sponsor Vim development Vim logo Vim Book Ad

smartpairs : Fantastic selections for Vim

 script karma  Rating -2/2, Downloaded by 274    Comments, bugs, improvements  Vim wiki

created by
Alexander Gorkunov
script type

Smartpairs allows you forget about difficult keys combination like vi{ or va".

Now you can use only one shortcut for all typical combinations. Even if you've already
selected something you can easily fix selection by using smartpairs.

Plugin searches first unpair symbol from the left of the current cursor
position and then runs target command with this symbol. When you press
'v' again plugin extend current selection by next pairs.


Use https://github.com/tpope/vim-pathogen for quick plugin installation.

If you already have pathogen then put smartpairs into ~/.vim/bundle like this:

    cd ~/.vim/bundle
    git clone https://github.com/gorkunov/smartpairs.vim.git


By default smartpairs focuses on selection command but it also supports delete/change/yank.

Commands list:

    vi* -> viv
    va* -> vav
    ci* -> civ
    ca* -> cav
    di* -> div
    da* -> dav
    ya* -> yiv
    ya* -> yav
    Where * is in <, >, ", ', `, (, ), [, ], {, } or t as tag
After v* commands you can press v again and selection will be extended to
the next pairs.

Advanced configuration

For changing smartpairs keys binding add those lines to your .vimrc file:

"Key for running smartpairs in all modes (select/delete/change/yank)
"default is 'v'
let g:smartpairs_key = 'v'

"Key for running smartpairs in the selection mode
"(extend current selection to the next pair)
"default is 'v'
let g:smartpairs_nextpairs_key = 'v'

"Key for running smartpairs in the selection mode
"for extending selection with IN-mod (like vi")
"default is 'z'
let g:smartpairs_nextpairs_key_i = 'z'

"Key for running smartpairs in the selection mode
"for extending selection with ABOVE-mod (like va")
"default is 'Z'
let g:smartpairs_nextpairs_key_a = 'Z'

"Smartpairs looks only 20 lines before cursor position
"but you can changes this limit:
let g:smartpairs_maxdepth = 20


Smartpairs is released under the wtfpl (http://sam.zoy.org/wtfpl/COPYING)
install details

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
smartpairs.zip 1.0 2012-12-31 7.3 Alexander Gorkunov 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.
SourceForge.net Logo