Mercurial > vim-lawrencium
diff plugin/lawrencium.vim @ 24:21a879a09f20
Trying to keep the cursor line when open an already opened file in `Hgstatus`.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Tue, 20 Dec 2011 15:25:51 -0800 |
parents | 84bceffbb19c |
children | 0e952b7c79d7 |
line wrap: on
line diff
--- a/plugin/lawrencium.vim Tue Dec 20 14:33:05 2011 -0800 +++ b/plugin/lawrencium.vim Tue Dec 20 15:25:51 2011 -0800 @@ -390,15 +390,19 @@ function! s:HgStatus_FileEdit() abort " Get the path of the file the cursor is on. let l:filename = s:HgStatus_GetSelectedPath() - - " Go back to the previous window and open the file there, or open an - " existing buffer. + + " If the file is already open in a window, jump to that window. + " Otherwise, jump to the previous window and open it there. + for nr in range(1, winnr('$')) + let l:br = winbufnr(nr) + let l:bpath = fnamemodify(bufname(l:br), ':p') + if l:bpath ==# l:filename + execute nr . 'wincmd w' + return + endif + endfor wincmd p - if bufexists(l:filename) - execute 'buffer ' . l:filename - else - execute 'edit ' . l:filename - endif + execute 'edit ' . l:filename endfunction function! s:HgStatus_FileAdd() abort