Vim Tips Wiki

Simple placeholders

1,612pages on
this wiki
Revision as of 15:07, March 3, 2009 by Luc Hermitte (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Tip 1071 Printable Monobook Previous Next

created December 9, 2005 · complexity basic · author gabriel · version 5.7

I was very impressed with the functionality of placeholders in the Latex-Suite script#475, so I decided to add a similiar functionality to my vimrc.

" A syntax for placeholders
" Pressing Control-j jumps to the next match.
inoremap <c-j> <Esc>/<++><CR><Esc>cf>

You could of course use any key-sequence for this. I use it with my code for () completion. It can be equally well used with templates and other abbreviations.

" Completions using placeholders
inoremap ( ()<++><Esc>F)i
inoremap [ []<++><Esc>F]i
inoremap { {}<++><Esc>F}i

This doesn't care if the code is entered free or if it's inside a block of text. In which case I think it should not expand. But I find it helpful none the less. Unlike the scripts pointed to by the comments this tip is just what it advertises. Simple.


Similar to this is markjump.vim script#485, in addition to others (the names of which escape me for now). Markjump adds a few advantages to this method such as not mangling the search pattern and providing previous and next jumps.

You may have a look at what I produced in the API plugin script#50. It already takes cares of what you are rewriting and much more. See also script#336 and mu-template (the fork I'm maintening provides a better integration of markers/placeholders) that fully integrate the bracketing system.

Around Wikia's network

Random Wiki