vim - gvim custom command arguments -
I'm trying to create a custom command to use vimgrep to search patterns like a given file pattern I
: Command- nargs = * Find: Tabune & lt; Bar & gt; Vimgrep / & lt; Arg1 & gt; / Gj & lt; Arg2 & gt; & Lt; Bar & gt; CW & LT; CR & gt;
How can I use arg1 and arg2 arguments?
Edit 1 : I've come with the following solution
order! -nargs = * Find the call VimFind (& lt; f-args & gt;) function! VimFind (searchPattern, filePattern, ...) searchCommand = 'vimgrep /'.a:searchPattern.'/gj' .a: filePattern. '| Cw 'if one: 0 & gt; 0 and amp; Amp; A: 1 == 'n' search compand = 'tannu |' L: Perform search Commands AndIIF: searchCommand endfunction
Is there a cleaner way to do this?
<Edit : Eh well, the above function errors arise and then nothing is found then a new tab opens
& lt; F-args & gt;
And by using a function, Vim parses personal command arguments for you; There is a right way to do this. To deal with errors from
: vimgrep
, you will have to execute : searchCommand
with try ... hold
, example:
Try to execute: searchCommand hold / ^ wim \% ((\ a \ +) \) \ =: e / tab close echo error message 'Echomsg' search I'm not sure why you need to search : tabnew
before failed; If you do this later (but before : cw
), you do not have to clean in case of failed searches.
Comments
Post a Comment