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). |
|
script versions (upload new version)
Click on the package to download.
ip used for rating: 207.241.235.164
|