vim-CtrlXA
vim-CtrlXA copied to clipboard
make Ctrl-X and Ctrl-A run through keyword cycles
With this Vim plug-in, the key bindings <Ctrl-X/A> (and g<Ctrl-X/A>) additionally cycle through lists of keywords such as true/false, yes/no, yesterday/today/tomorrow or roman numerals I, II, III...
Useful, for example,
- for toggling settings in a configuration file,
- for toggling language modifiers such as
public/private, - for switching between
pick,squash,reword, ... agitcommit when rebasing, ...
Keyword cycles are provided for common programming and natural languages
(inspectable in the ftplugin respectively autoload/CtrlXA/langs folders).
Repetition of the last command by hitting . (see :help .) is achieved
- in normal mode by vim-repeat, and
- in visual mode by vim-visualrepeat.
Global Setup
These keywords are configurable by the variable g:CtrlXA_Toggles which is a long list of keyword lists in plugin/CtrlXA/toggles.vim
If you want to add a cycle, say the pair ['sweet', 'bitter'], to the default list of cycles, then
-
either put
let g:CtrlXA_Toggles = [ \ ['sweet', 'bitter'], \ ] + g:CtrlXA_Togglesinto a file
~/.vim/after/plugin/CtrlXA.vimon Linux (respectively%USERPROFILE%\vimfiles\after\plugin\CtrlXA.vimon Microsoft Windows), or -
put into your
vimrcthe linesaugroup VimAfter autocmd! autocmd VimEnter * let g:CtrlXA_Toggles = [ \ ['sweet', 'bitter'], \ ] + g:CtrlXA_Toggles augroup END
Keywords consist of the keyword characters determined by the global variable g:CtrlXA_iskeyword.
By default, this variable takes the same value as &g:iskeyword (see :help iskeyword) with the exception of the underscore _ which is removed from g:CtrlXA_iskeyword.
If you want the cursor to move to the keyword (among g:CtrlXA_Toggles) that was changed after hitting a key (mapped to <Plug>(CtrlXA-CtrlA) or <Plug>(CtrlXA-CtrlX)), then set the global variable g:CtrlXA_move to 1.
By default, the cursor only moves to a changed number, as Vim does by default.
If you prefer i, v and I, V to run through the letters of the Latin
alphabet instead of the Roman numerals, move these letters from the pair of
arrays containing the roman numerals to that containing the Latin alphabet.
There are also localized keyword cycle lists for common (spell) languages.
Disable them by adding let g:CtrlXA_localization = 0 to your Vimrc.
To customize them, put a file named after the corresponding (spell) language code, for example, ro.vim for Romanian into $VIMFILES/autoload/CtrlXA/langs/
(where $VIMFILES is ~/.vim on Linux and Mac OS and %USERPROFILE%/vimfiles on Microsoft Windows, see :help vimfiles).
Buffer-Local Setup
There is also the buffer-local list of keyword cycles b:CtrlXA_iskeyword, which allows for file-type specific keyword cycles.
For example, as included by default:
autocmd FileType gitrebase
\ let b:CtrlXA_Toggles = [
\ ['pick', 'fixup', 'squash', 'break', 'reword', 'edit', 'drop'],
\ ] + get(b:, 'CtrlXA_Toggles', g:CtrlXA_Toggles)
This will
- include all keyword cycles of the global variable, and
- add (buffer-)local keyword cycles which have precedence over the global cycles.
To add keyword cycles for other file types, add
- either the four lines above to
~/.vimrcon Linux or MacOS (respectively%USERPROFILE%\_vimrcon Microsoft Windows), or - the last three lines above to
~/.vim/after/ftplugin/gitrebase.vimon Linux (respectively%USERPROFILE%\vimfiles\after\ftplugin\gitrebase.vimon Microsoft Windows).
Related Plug-ins
This plugin integrates with Tim Pope's vim-speeddating by adding to your .vimrc the lines
nmap <Plug>SpeedDatingFallbackUp <Plug>(CtrlXA-CtrlA)
nmap <Plug>SpeedDatingFallbackDown <Plug>(CtrlXA-CtrlX)
Alternative Plug-ins
Vim plug-ins that provide similar functionality and more are
-
Andrew Radev's switch.vim which can cycle between expressions containing spaces;
-
@bootleq's vim-cycle which
- supports pairs in
LaTeX, for example, cycles between\big( a + b \big)and\Big( a +b \Big), and - preserves upper and lower case by options such as
match_case,hard_caseandmatch_word;
- supports pairs in
-
M.J. Brownie's swapit
See @kiryph's compilation for further alternatives.