Skip to content

Instantly share code, notes, and snippets.

@tyru
Last active November 11, 2018 09:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tyru/7f252720c80574152d0103a9598cf62b to your computer and use it in GitHub Desktop.
Save tyru/7f252720c80574152d0103a9598cf62b to your computer and use it in GitHub Desktop.
Bizarre <SID> and <SNR> conversion (https://github.com/vim-jp/issues/issues/1201)
function! s:get_next_tab(n) abort
let last = tabpagenr('$')
let i = (tabpagenr() - 1 + a:n) % last
let i = i < 0 ? last + i : i
return i ==# 0 || i + 2 ==# tabpagenr() ? i : i + 1
endfunction
" =============== Error ===============
" E121: Undefined variable: SNR
" E15: Invalid expression: 'tabmove' <SNR>279_get_next_tab(+v:count1)
"
" But ':echo <SNR>276_get_next_tab(-v:count1)' can successfully call it with no errors...
nnoremap <silent> <Left> :<C-u>execute 'tabmove' <SID>get_next_tab(-v:count1)<CR>
nnoremap <silent> <Right> :<C-u>execute 'tabmove' <SID>get_next_tab(+v:count1)<CR>
" =============== Success ===============
nnoremap <silent> <Left> :<C-u>call <SID>f(-v:count1)<CR>
nnoremap <silent> <Right> :<C-u>call <SID>f(+v:count1)<CR>
function! s:f(n) abort
execute 'tabmove' s:get_next_tab(a:n)
endfunction
@tyru
Copy link
Author

tyru commented Nov 11, 2018

Vim version: 8.1.513

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment