sponsor Vim development Vim logo Vim Book Ad

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

 script karma  Rating 37/16, Downloaded by 2446  Comments, bugs, improvements  Vim wiki

created by
Enno Nagel
 
script type
utility
 
description
With this Vim plug-in, the key bindings |<Ctrl-X>|/|<Ctrl-A>| (and |g<Ctrl-X>|/|g<Ctrl-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|, ... a |git| commit when rebasing, ...

Repetition of the last command by hitting |.| (see |:help .|) is achieved

- in normal mode by vim-repeat[1], and
- in visual mode by vim-visualrepeat[2].

GLOBAL SETUP ~

These keyword cycles are configurable by the variable |g:CtrlXA_Toggles| whose default value can be seen in https://github.com/Konfekt/vim-CtrlXA/blob/master/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_Toggles

into a file |~/.vim/after/plugin/CtrlXA.vim| on Linux (respectively |%USERPROFILE%\vimfiles\after\plugin\CtrlXA.vim| on Microsoft Windows), or
- put into your |vimrc| the lines

    augroup 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.

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 |~/.vimrc| on Linux or MacOS (respectively |%USERPROFILE%\_vimrc| on Microsoft Windows), or
- the last three lines above to |~/.vim/after/ftplugin/gitrebase.vim| on Linux (respectively |%USERPROFILE%\vimfiles\after/ftplugin\gitrebase.vim| on Microsoft Windows).
 
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.12 2024-03-27 7.0 Enno Nagel reorganize localized lists for easier customization
vim-CtrlXA.zip 1.11 2024-03-02 7.0 Enno Nagel add many general, localized and file type specific keyword cycles
vim-CtrlXA.zip 1.10 2021-12-19 7.0 Enno Nagel support nested keywords
vim-CtrlXA.zip 1.9 2021-03-04 7.0 Enno Nagel simplify and speed up numeral increment
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: 207.241.235.164

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.
   
Vim at Github