Vim 101: Working with Brackets
I don’t know how much nontechnical writers care about brackets — there probably aren’t that many brackets in the average novel, fiction or non. Programming is another matter. Every language seems to make use of all brackets, including curly and square.
Vim has a few standard ways to deal with brackets, and standard Vim distributions also come bundled with bracket-related plugins.
Movement and Selection
Moving the cursor over a bracket and pressing %
will cause the cursor to jump to the corresponding bracket. This is useful for unravelling nested and mixed brackets -- repeatedly pressing %
provides a clear visual indication.
I also use v
to visual select the contents of brackets. This can be combined with the pull and yank commands. For example, f(v%y
would do this:
f(
: Move to the next(
on the current linev
: Start a visual selection%
: Select the text up to and including the next brackety
: Yank the text
Highlights
If you’re using a standard installation of Vim then you should have matchparen.vim
installed. This causes pairs of brackets to be highlighted when the cursor is over one of them. If you don't want to use it, then typing :NoMatchParen
will disable it. Some people set :let loaded_matchparen = 1
in their ~/.vimrc
to prevent it from loading.
I like to use :set showmatch
. This causes Vim to move the cursor to the previous matching bracket for half a second, and quickly pressing a key will effectively cancel this animation so it doesn't get in the way of rapid typing. The duration for this animation is set with :set matchtime=10
, where 10
is in tenths of a second.