Sometimes you need to toggle a specific pattern on the line under cursor: add/remove a semicolon at the end of line, add/remove a comma at the beggining of line,... Toggline Vim Plugin provides a set of functions to help you in these cases.
This plugin follows the standard runtime path structure, and as such it can be installed with a variety of plugin managers:
- Pathogen
git clone https://github.com/TiuSh/vim-toggline ~/.vim/bundle/vim-toggline
- Vundle:
Plugin 'TiuSh/vim-toggline'
Use this plugin by setting your own mappings in your .vimrc
:
nmap <silent> <leader>; :call toggline#End(';')<CR>
inoremap <silent> <leader>; <C-\><C-O>:call toggline#End(';')<CR>
Consider this line of code (where [*] represent the position of the cursor):
var foo = { ba[r]: 1 }
Pressing <leader>;
will result to:
var foo = { ba[r]: 1 };
Pressing <leader>;
again:
var foo = { ba[r]: 1 }
Note that you can add spaces around the toggled string:
nmap <silent> <leader>, :call toggline#Start(', ')<CR>
Now consider this code:
var foo = 1
,ba[r] = 0;
Pressing <leader>,
will result to:
var foo = 1
ba[r] = 0;
Pressing <leader>,
again:
var foo = 1
, ba[r] = 0;
Available helper functions:
Toggle the given string at the end of the line.
Toggle the given string at the beginning of the line.
Toggle the current line using the given expresions and substitutions:
- enabledPat: Pattern on which the line will be tested. If it matches, the line will be considered as "enabled" and this pattern will be replaced by the "disableSub" argument.
- disableSub: Substition string applied on "enablePat" if the line is considered "enabled"
- disabledPat: If the line is considered as "disabled", this pattern will be replaced by the "enableSub" argument.
- enableSub: Substition string applied with the "enablePat" if the line is considered "disabled"
MIT