sponsor Vim development Vim logo Vim Book Ad

vim-CtrlXA : make Ctrl-X and Ctrl-A run through keyword cycles

 script karma  Rating 29/14, Downloaded by 1879  Comments, bugs, improvements  Vim wiki

created by
Enno Nagel
script type
This Vim plug-in makes the key bindings `<Ctrl-X/A>` (and g<Ctrl-X/A>` in visual mode)
additionally cycle through keywords in lists such as 'true/false', 'yes/no', 'set/unset' or
'yesterday/today/tomorrow' or roman numerals  'I', 'II', 'III'...

Useful, for example,

- for toggling settings in a configuration file, or
- for switching between `pick`, `squash`, `reword`, ... a `git` commit when rebasing.

These keywords are configurable by the variable g:CtrlXA_Toggles which defaults to

  let g:CtrlXA_Toggles = [
      \ ['true', 'false'], ['True', 'False'], ['TRUE', 'FALSE'],
      \ ['yes', 'no'], ['Yes', 'No'], ['YES', 'NO'],
      \ ['on', 'off'], ['On', 'Off'], ['ON', 'OFF'],
      \ ['up', 'down'], ['Up', 'Down'] ,['UP', 'DOWN'],
      \ ['set', 'unset'],
      \ ['is', 'isnot'] ,
      \ ['==', '!='] , ['<', '>'], ['<=', '>='], ['=~', '!~'],
      \ ['enable', 'disable'], ['Enable', 'Disable'],
      \ ['enabled', 'disabled'], ['Enabled', 'Disabled'],
      \ ['maximum', 'minimum'], ['Maximum', 'Minimum'],
      \ ['maximal', 'minimal'], ['Maximal', 'Minimal'],
      \ ['upper', 'lower'], ['Upper', 'Lower'],
      \ ['top', 'bottom'], ['Top', 'Bottom'],
      \ ['above', 'below'], ['Above', 'Below'],
      \ ['forward', 'backward'], ['Forward', 'Backward'],
      \ ['right', 'middle', 'left'], ['Right', 'Middle', 'Left'],
      \ ['next', 'previous'], ['Next', 'Previous'],
      \ ['first', 'last'], ['First', 'Last'],
      \ ['before', 'after'], ['Before', 'After'],
      \ ['more', 'less'], ['More', 'Less'],
      \ ['fast', 'slow'], ['Fast', 'Slow'],
      \ ]

There is also its buffer-local analogue, which allows for file-type specific
keyword cycles by, for example

  autocmd FileType gitrebase
              \ let b:CtrlXA_Toggles = [
              \ ['pick', 'fixup', 'squash', 'break', 'reword', 'edit', 'drop'],
              \ ] + g:CtrlXA_Toggles
  autocmd FileType vim
              \ let b:CtrlXA_Toggles = [
              \ ['if', 'else', 'elseif', 'endif'],
              \ ] + g:CtrlXA_Toggles
  autocmd FileType sh
              \ let b:CtrlXA_Toggles = [
              \ ['if', 'elif', 'else', 'fi'],
              \ ] + g:CtrlXA_Toggles
  autocmd FileType tex
              \ let b:CtrlXA_Toggles = [
              \ ['final', 'draft'],
              \ ['|', '\nmid'], ['=', '\neq'], \
              \ ['\leq', '\geq],
              \ ] + 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.

There are many more toggles that could be useful, for example, to switch between the draft and final version of a `TeX` document, add:

  autocmd FileType tex
              \ let b:CtrlXA_Toggles = [
              \ ['final', 'draft'],
              \ ] + g:CtrlXA_Toggles

vim-CtrlXA is developed at https://github.com/Konfekt/vim-CtrlXA where issues can be filed.
install details
unzip vim-CtrlXA.zip into ~/.vim (respectivley %USERPROFILE/_vim in Microsoft Windows).

rate this script Life Changing Helpful Unfulfilling 
script versions (upload new version)

Click on the package to download.

package script version date Vim version user release notes
vim-CtrlXA.zip 1.8 2020-08-17 7.0 Enno Nagel toggle keywords behind cursor word
vim-CtrlXA.zip 1.7 2020-03-23 7.0 Enno Nagel fix corner cases of g<C-X/A>
vim-CtrlXA.zip 1.6 2020-02-07 7.0 Enno Nagel add visual mappings
vim-CtrlXA.zip 1.5 2020-01-08 7.0 Enno Nagel various additions and corrections; see the commits in the GitHub repo
vim-CtrlXA.zip 1.4 2019-04-02 7.0 Enno Nagel make ctrl-x/a act oppositely; add enumeration markers
vim-CtrlXA.zip 1.3 2018-12-06 6.0 Enno Nagel more default lists
vim-CtrlXA.zip 1.2 2017-08-31 5.7 Enno Nagel allow for non-keyword characters
vim-CtrlXA.zip 1.1 2017-08-29 5.7 Enno Nagel Support file-type specific keyword cycles.
vim-CtrlXA.zip 1.0 2017-08-26 5.7 Enno Nagel Initial upload
ip used for rating:

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.