Forked from hail2u/cycle-metasyntactic-variables.vim
Created
August 24, 2018 11:16
-
-
Save markatom/1378d035926cd9baf44a64c162774b81 to your computer and use it in GitHub Desktop.
'foo', 'bar', 'baz', 'qux', 'quux', 'corge', 'grault', 'garply', 'waldo', 'fred', 'plugh', 'xyzzy', 'thud'の上で<C-a>/<C-x>すると順にサイクルしてくれるやつ。レジスター使ってる。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" Cycle metasyntactic variables | |
function! s:CycleMetasyntacticVariables(num) | |
if type(a:num) != type(0) | |
return | |
endif | |
let vars = ['foo', 'bar', 'baz', 'qux', 'quux', 'corge', 'grault', 'garply', 'waldo', 'fred', 'plugh', 'xyzzy', 'thud'] | |
let cvar = expand('<cword>') | |
let i = index(vars, cvar) | |
if (i == -1) | |
if (a:num > 0) | |
execute "normal! \<C-a>" | |
else | |
execute "normal! \<C-x>" | |
endif | |
return | |
endif | |
let i += a:num | |
if (i == -1) | |
let i = len(vars) - 1 | |
elseif (i == len(vars)) | |
let i = 0 | |
endif | |
call setreg('w', vars[i]) | |
normal! "_viw"wp | |
endfunction | |
nnoremap <C-a> :call <SID>CycleMetasyntacticVariables(1)<Enter> | |
nnoremap <C-x> :call <SID>CycleMetasyntacticVariables(-1)<Enter> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment