Search code examples
vimsnipmate

Is there a way to tab to locations in a file to change text?


Using snipmate I can create tab stops using ${1}, ${2}, and so on. But let us say I have a file that has several lines of text I frequently use. When I yank and put these into my active file there are certain parts of the line that need to be altered. Is there a way to replicate snipmate's tab stop functionality? If there isn't is there a way to highlight the locations that need altering?

So let us say I have the following lines:

The results show: [] 
Item [] returned true.

I would like the brackets to be replaced with text. I know I can search for the brackets and next my way through them, but I was hoping for something a bit more convenient.


Solution

  • I would second Zach's suggestion to use Snipmate itself to deal with that problem.

    Search and replace is the most convenient approach if you want your placeholders to be replaced with the same text:

    :'{,'}s/\[\]/foo/g
    

    If you want to replace each placeholder with different text you can replicate Snipmate's behavior with:

    :nnoremap <key> *``gn<C-g>
    :inoremap <key> <Esc>gn<C-g>
    
    • Pressing <key> in normal mode highlights the current word in select mode, ready to type over.
    • Pressing <key> in insert mode — in this context, when you are done with that placeholder — jumps to the next placeholder and highlights it in select mode, ready to type over.