Reputation: 4580
I have a few Regex expressions that I use with xVim for Xcode. Rather than repeatedly typing them out in the command bar with \<Regex>
, I'd like to be able to invoke them with a custom command, like :Regex1
. So I've added command Regex1 “/-\s*\(“
to my xvimrc
file and restarted Xcode. When I run :Regex1
however nothing happens.
Upvotes: 0
Views: 532
Reputation: 4041
Abbreviations ...
I understand you often use the same regex. You can use abreviations instead of a command to do a search.
ab re -\s*(
then type / + re + space and your long regex (here just "-\s*(" should expand).
... Not user defined command
User defined commands are not available in ed nor in vi nor in vim without the +eval compilation flag (:h user-commands
and scroll one line up).
For a list of ex commands: http://www.csb.yale.edu/userguides/wordprocess/vi-summary.html
For a list of ed commands: http://pubs.opengroup.org/onlinepubs/7908799/xcu/ed.html
Upvotes: 1
Reputation: 1289
I would suggest using this PERL Regex plugin since it already does what you want.
https://github.com/othree/eregex.vim
Upvotes: 1
Reputation: 172648
Your command wouldn't even work in original Vim. I don't know xVim, but try something along these lines:
" With cursor moving to match.
command Foo /foo/
" Just updating the search pattern (but less likely to be portable to xVim).
command Foo let @/ = 'foo'
If none of that works; try defining a mapping instead. As this is just translating keys, it has the highest chance of being supported.
Upvotes: 1