Reputation: 8132
Most of the time I do some regular search like anything that starting with def
,it should take my cursor to that place, so /def <search character>
. I am thinking to create some shortcut.
I tried doing this
command # /def
with a hope that if I do ESC# it will type /def<space>
, but it doesn't.
It is throwing error
E182: Invalid command name
How can i do that ?
Upvotes: 0
Views: 509
Reputation: 45157
An alternative to using /
to search is to use ctags. Using tags lets you do the following:
<c-]>
<c-w><c-]>
is the same as <c-]>
, but open definition in new split window:tag {tag_name}
will jump to the definition of {tag_name}
:tag
uses completion so <tab>
and <c-d>
can help you type less:tag
can use a regex to match part of a tag. e.g. :tag /foo
(use completion with this also)<c-t>
to jump back after you visit a definition (It pops the tag stack)For a quick mapping use the following:
nnoremap <leader>t :ta<space>
More alternatives:
:h cscope
:vimgrep
/:grep
/ack/ag/git-grep to search across several files when tags are not availablegd
(go to definition) for simple cases. See :h gd
For more help please see the following:
:h tags
:h ctrl-]
:h ctrl-w_ctrl-]
:h :tag
:h ctrl-t
:h :vimg
:h :grep
:h gd
:h cscope
Upvotes: 1
Reputation: 195229
you are looking for map
not command
. try this:
nnoremap <F3> /def<space>
I didn't map #
, instead I used <F3>
, since #
is very useful in normal mode. you can use #
if you like.
Upvotes: 2