0

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.

George Karpenkov
  • 2,094
  • 1
  • 16
  • 36
thequerist
  • 1,774
  • 3
  • 19
  • 27
  • 1
    Is there a reason why you are not just using snipmate to make snippets for these lines so you don't have to yank or paste them at all and you can still use tabstop? – Zach Jul 24 '14 at 23:59
  • Because I have thousands of these, and it would be difficult to remember the snippets for all of them. – thequerist Jul 27 '14 at 19:55

2 Answers2

1

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.
romainl
  • 186,200
  • 21
  • 280
  • 313
1

What you describe is very similar to the snippets use case; it would probably be best if you just defined those text fragments as snippets and use snipMate to insert them; you'll get all the functionality for free then!

Of course, you can recreate parts of snipMate, e.g.:

:nnoremap <silent> <F3> :call search('\[\]')<CR>

With this, you can jump to the next placeholder via F3, and you can replace the current placeholder with e.g. 2s.

Ingo Karkat
  • 167,457
  • 16
  • 250
  • 324