Skip to content

Instantly share code, notes, and snippets.

@tyru
Forked from mattn/setbufline.vim
Created September 9, 2010 11:27
Show Gist options
  • Save tyru/571746 to your computer and use it in GitHub Desktop.
Save tyru/571746 to your computer and use it in GitHub Desktop.
function! SetBufLine(expr, lnum, text)
let oldnr = winnr()
let winnr = bufwinnr(a:expr)
try
if oldnr == winnr
silent! call setline(a:lnum, a:text)
elseif winnr ==# -1
silent split
silent execute bufnr(a:expr) 'buffer'
silent call setline(a:lnum, a:text)
silent hide
else
execute winnr 'wincmd w'
silent call setline(a:lnum, a:text)
endif
finally
execute oldnr 'wincmd w'
endtry
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment