JonnyRobbie
JonnyRobbie

Reputation: 614

Custom search pattern in VIM

In what way I can make sort of a shortcut to parametrized search in vim? So when I invoke (for example) :customsearch foo, I get a search for /bar foo baz$. Or more generally /bar %s baz.

Upvotes: 2

Views: 286

Answers (2)

Ingo Karkat
Ingo Karkat

Reputation: 172520

@TonyMyddeltyn's answer shows a custom command, which is a valid approach. As you're asking for a shortcut mapping and real-time display, you can have that by defining an incomplete search mapping.

Think of first preparing the search (with parameters already inserted and the cursor placed in the middle), and then completing it by filling in the blanks and triggering searching via Enter. That first part can be supplied by a mapping, like this:

:nnoremap sf /bar  baz$<Left><Left><Left><Left><Left>

Upvotes: 4

Tom Myddeltyn
Tom Myddeltyn

Reputation: 1375

Add a command to the vimrc file such as this:

Note that the command must start with a capital letter.

command -nargs=1 Customsearch :
    \ /foo <args> baz

Upvotes: 4

Related Questions