-
-
Save tyru/391891 to your computer and use it in GitHub Desktop.
"toggle bang" in vim script.
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
function! s:toggle_bang(cmdline) | |
" :substituteみたいに引数とコマンドの間に | |
" 空白がなくても呼ばれたりするものもあるので完璧ではない。 | |
" そもそも:substituteはbangとらないけど。 | |
let m = matchlist(a:cmdline, '^\(\s*\)\(\S\+\)\(.*\)') | |
if empty(m) | return a:cmdline | endif | |
let [ws, cmd, rest] = m[1:3] | |
return ws . (cmd[strlen(cmd) - 1] == '!' ? cmd[:-2] : cmd . '!') . rest | |
endfunction | |
cnoremap <Plug>(cmdline-toggle-bang) <C-\>e <SID>toggle_bang(getcmdline())<CR> | |
cmap <C-x> <Plug>(cmdline-toggle-bang) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment