6

When I hit <C-]> or type :tag {indent}, vim does not jump to the first tag that matches the keyword under the cursor. Instead, it prompts me to select from multiple matches for the word.

Vim mistakes <C-]> for g<C-]> and :tag {indent} for tjump {indent}.


Update:

  1. When I launch vim without sourcing my .vimrc file, <C-]> or :tag {indent} is ok, whether all initializations are skipped with the argument -u NONE, or just the plugins are sourced with the argument -u NORC.

  2. When I launch vim sourcing my .vimrc file, <C-]> or :tag {indent} goes wrong, whether I skip loading plugins with the argument --noplugin or not.

  • 2
    Maybe a file has remapped your <C-]> key. To find out which one, type: :verbose nmap <C-]> – saginaw Dec 16 '15 at 13:16
  • @saginaw vim echo No mapping found – Feng Yu Dec 16 '15 at 13:33
  • @saginaw Note that :tag {keyword} went wrong too. If I have remapped my <C-]> key, :tag {keyword} should work right at least. – Feng Yu Dec 16 '15 at 13:55
  • 2
    @FengYu Yes you're right. Maybe there's a problem with the tags file and how it was created. You say it works when you start vim like this vim -u NONE but not when you start vim with an empty vimrc file and .vim/ folder. I may be wrong, but it seems to suggest a file is messing with the behavior of your mappings / commands. If you start vim like this : vim -u NORC, all initializations from files and environment variables are skipped except plugins. Is the issue still there when you start vim like this ? – saginaw Dec 16 '15 at 14:06
  • @FengYu Just a suggestion, type vim --startuptime log1, quit then type vim -u NORC --startuptime log2, quit then type vim -u NONE --startuptime log3, quit then type vim -d log1 log2 log3. Maybe it will help you find a file which is messing with your commands. – saginaw Dec 16 '15 at 14:16
4

To see all the files that Vim sourced during launch, I typed :scriptnames.

I found that:

  1. When launching vim with the command $vim --noplugin or $vim, there is a /etc/vimrc file which is sourced;
  2. When launching vim with $vim -u NONE or $vim -u NORC, this /etc/vimrc file is gone.

There are other differences in the list of sourced files, but only /etc/vimrc caught my eye because vimrc is included in this path.

Then I experimented with /etc/vimrc and I found that one statement in it was modifying the behavior <C-]> and :tag {indent}:

set cscopetag

When I comment out this line, the problem no longer exists.

From the vim help (:help cscopetag):

If 'cscopetag' is set, the commands ":tag" and CTRL-] as well as "vim -t" will always use :cstag instead of the default :tag behavior.

:help :cstag:

If you use cscope as well as ctags, |:cstag| allows you to search one or the other before making a jump. For example, you can choose to first search your cscope database(s) for a match, and if one is not found, then your tags file(s) will be searched. The order in which this happens is determined by the value of |csto|. See |cscope-options| for more details.

|:cstag| performs the equivalent of ":cs find g" on the identifier when searching through the cscope database(s).

|:cstag| performs the equivalent of |:tjump| on the identifier when searching through your tags file(s).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.