Skip to content

Vim Plugin that toggles patterns on current line

License

Notifications You must be signed in to change notification settings

TiuSh/vim-toggline

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Toggline.vim

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.

Preview

toggline1 toggline2

Installation

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'

Usage

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:

toggline#End( str )

Toggle the given string at the end of the line.

toggline#Start( str )

Toggle the given string at the beginning of the line.

toggline#With( enabledPat, disableSub, disabledPat, enableSub )

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"

License

MIT

About

Vim Plugin that toggles patterns on current line

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published