English 中文(简体)
vi command line equivalent to CTRL-]?
原标题:
  • 时间:2010-01-03 11:36:40
  •  标签:
  • vi
  • vim
  • ctags

I m trying to map my own shortcuts in vi. I want to be able to open a splitted window containing the declaration of the function I m calling the shortcut on. something like this in my vimrc:

nmap <unique> <silent> <Leader>tg :exe vsplit | equivalent of <C-]>

but what s the equivalent of C-] in command mode ?

最佳回答

To open vim at the line containing the tag foobar type this at the shell commandline:

vim -t foobar

To jump to the same tag on the vim commandline type:

:tag foobar

If you want to split the window and jump to the tag in the new window type this in vim s commandline:

:stag foobar

If you want a keystroke that specifies "the word under the cursor", then according to this question, you can use the CTRL+R CTRL+W to get that:

:tag CTRL+R CTRL+W

You can also use :

:nmap <leader>w :tag <c-r>=expand("<cword>")<c-r>

Now typing <leader>+w (which is in my setup, so I d press w) will be the same as typing :tag <word under the cursor>

问题回答

See :help CTRL-]:

CTRL-] Jump to the definition of the keyword under the cursor. Same as ":tag {ident}", where {ident} is the keyword under or after cursor.

Edit

Not sure if there is a built-in for this, but the following seems to match the keyword "under or after" the cursor:

matchstr(getline( . ),  \% .col( . ). cs*zsk+ )

you could also write (to map it for example to Ctrl-Q):

:nmap <C-Q> <C-]>

you could also consider :nn[oremap] in such cases to avoid nested/recursive mappings.

You can jump to the definition of the word under the cursor with exe "tag " . expand("<cword>"). The expand function replaces special tokens with their meaning - this includes a filename under the cursor, the current file name, etc. See Vim s help for the expand() function for the full set.

Alternatively you could use the :normal command, which lets you execute normal-mode key sequences from an :ex command.





相关问题
Autoupdate VIM Plugins?

Is it possible to update vim plugins automatically?

how to unindent in vim without leaving edit mode?

I m writing a lot of python code recently, and i used the tab-to-space mode in vim. I was just wondering how would i unindent in vim without leaving edit mode for example after i finished if...: block....

Scrolling inside Vim in Mac s Terminal

I ve been googling around trying to figure out if it s possible to use my mouse wheel to scroll while inside Vim in Mac s Terminal, with no luck. It seems as if only X11 or iTerm support this. Before ...

Vim - Deleting XML Comments

How do I delete comments in XML? If the opening and the closing comment tags are on the same line, I use :g/^<!--.*-->$/d to delete the comment. How to delete the comments that are spread ...

Limiting a match in vim to certain filetypes?

I have the following in my .vimrc to highlight lines longer than 80 chars: highlight OverLength ctermbg=red ctermfg=white guibg=#592929 match OverLength /\%81v.*/ This works quite well. However, the ...

Profiling Vim startup time

I’ve got a lot of plugins enabled when using Vim – I have collected plugins over the years. I’m a bit fed up with how long Vim takes to start now, so I’d like to profile its startup and see which of ...

热门标签