Skip to content

Instantly share code, notes, and snippets.

@haya14busa
Created January 13, 2014 13:24
Show Gist options
  • Select an option

  • Save haya14busa/8400189 to your computer and use it in GitHub Desktop.

Select an option

Save haya14busa/8400189 to your computer and use it in GitHub Desktop.
function! s:before_get_visual()
exec "normal! \<Esc>"
normal! gv
endfunction
function! s:after_get_visual()
normal! gv
endfunction
function! s:test_visual_scroll(mode)
call g:plog('=====')
if a:mode == 'v' | call s:before_get_visual() | endif
let first_line = line('w0')
let current_line = line('.')
let end_line = line('w$')
" if a:mode == 'v' | call s:after_get_visual() | endif
call g:plog('mode : ' . a:mode)
call g:plog('first : ' . first_line)
call g:plog('cursor : ' . current_line)
call g:plog('end : ' . end_line)
endfunction
" Normal
nnoremap <buffer><silent> ,, :<C-u>call <SID>test_visual_scroll('n')<CR>
" Dame!
xnoremap <buffer><silent> ,1 :<C-u>call <SID>test_visual_scroll('v')<CR>
" OK!
xnoremap <buffer><silent> ,2 <Esc>:<C-u>call <SID>test_visual_scroll('v')<CR>
" How to Reproduce
" 1. :so %
" 1. gg
" 2. <C-f><C-f> (scroll ...)
" 3. ,1 ( -> dame)
" 4. ,2 ( -> ok)
"
" 1の従来の方式だとスクリーンの中心"以外"で呼ぶとずれる
" line('w$')が正しく取れないと思いきや意外と1でもとれてるので要検証...?
noremap <buffer> ,st :so %<CR>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment