Tuesday, October 11, 2016

Re: How to prevent Vim scrolling when splitting a window ?

Alessandro Antonello wrote:
> Could you please post your solution in this thread? I may be useful to someone else. It may be useful to myself on some circumstances.
>

1. save the cursor and window position by winsaveview()
2. split a new window
3. restore the previous cursor and window position by winrestview()

https://github.com/skywind3000/asyncrun.vim/blob/master/plugin/asyncrun.vim#L653

function! asyncrun#quickfix_toggle(size)
function! s:WindowCheck(mode)
if getbufvar('%', '&buftype') == 'quickfix'
let s:quickfix_open = 1
return
endif
if a:mode == 0
let w:quickfix_save = winsaveview()
else
call winrestview(w:quickfix_save)
endif
endfunc
let s:quickfix_open = 0
let l:winnr = winnr()
windo call s:WindowCheck(0)
if s:quickfix_open == 0
exec 'botright copen '.a:size
wincmd k
else
cclose
endif
windo call s:WindowCheck(1)
try
silent exec ''.l:winnr.'wincmd w'
catch /.*/
endtry
endfunc

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments: