7

When using gVim on Windows 7 I cannot use ^] (CTRL+]) to jump to tags as described in the Vim documentation:

<C-LeftMouse>                   *<C-LeftMouse>* *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.
            When there are several matching tags for {ident}, jump
            to the [count] one.  When no [count] is given the
            first one is jumped to. See |tag-matchlist| for
            jumping to other matching tags.
            {Vi: identifier after the cursor}

This used to bother me a lot when learning Vim. In the end I managed to solve it by using this hacky mapping

nnoremap <leader>t :tag <c-r><c-w><cr>

which allowed me to jump to tags using \t (I used the default setting of \ as<leader>).

This is not a problem for me anymore as I now only use gnu/linux for programming and I have already read pretty much all help there is to read. But considering that this contributed to making my experience learning Vim so much worse I ask here to get this solved for people who are in the same situation I was in.

Why doesn't CTRL+] work for me on Windows 7 and how can it be fixed?

Edit: The title has been edited with the information that this problem is caused by the keyboard layout I used.

  • Can you provide more information? Why doesn't it work? Do you have ctags installed? What error message do you get, if any, when you try using Ctrl-] on a word? – akshay Dec 5 '15 at 22:23
  • 1
    I just managed to figure it out! The problem was because I used an keyboard layout that requires ^] to be entered using Ctrl-AltGr-9 which does not work within Vim. I answered my own question with this information. – wefwefa3 Dec 5 '15 at 22:59
  • 1
    FWIW, <C-]> on an AZERTY Mac keyboard is obtained by pressing <C-$>, $ being in the same physical location as ] on QWERTY keyboards. – romainl Dec 6 '15 at 9:20
  • I remember a solution which involved using MS Keyboard Layout Creator to "inject" the key combination (i.e. the OS didn't generate a key code at all when Ctrl-] was pressed. Or was it for Ctrl-[ ?) – VanLaser Dec 6 '15 at 12:37
  • 1
    @romainl: thanks for mentioning this. Reminded me of my own question I asked on SO on this topic. Answered by... you :-) – eckes Dec 6 '15 at 12:48
12

Say hello to knowledge fragmentation: https://stackoverflow.com/q/6932702/520162 This question was already asked and answered on StackOverflow.

The key is to press CTRL and the key that is located where the ] lives on the US keyboard. I had the issue with a QUERTZ German keyboard and have to press CTRL-+

Compare: US keyboard: US keyboard

German keyboard: German keyboard

Another obvious way would be to simply remap the functionality to a different keystroke. Since you want to go to the tag under the cursor, you could use oo for this:

:map oo <C-]>
2

I just found out why I had this problem.

The cause of the problem

The problem is that I used a Non-English keyboard layout on my Windows 7 computer.

The backslash character is entered using Alt Gr+9 on my Non-English keyboard layout. This leads to that ^] would be entered using Ctrl+Alt Gr+9. This simply does not work within Vim.

I do not know why that is:

  • The problem could be in hardware. Maybe the problem is caused by limited keyboard ghosting (but I have the same problem with a keyboard that is supposed to be able to register 6 keys at once).

  • The problem could be in software. Vim maybe was not programmed with this in mind.

I would appreciate if someone else who uses a Non-English keyboard could comment on if ^] works as it should on their machine.

The solution

The problem is fixed by simply changing to an English keyboard layout. Unfortunately I have found no other solution.

So you have to use an English layout instead. Vim's user interface is also designed with an English keyboard layout in mind. Using an English keyboard layout is also advantageous in programming because characters like [, { and ; that are frequently used in programming become easier to reach (no Alt Gr stretch). So switching can even make your life more comfortable!

The problem will be about entering characters in your main language. Then you have to resort to using digraphs (see :help digraphs).

Another way to solve it this problem would be to use this hacky mapping that was mentioned in the question:

nnoremap <leader>t :tag <c-r><c-w><cr>

Which allows the user to jump to a tag with \t (if <leader> is set to \ as it is by default).

  • 1
    This is no solution, this is surrender. – eckes Dec 6 '15 at 12:32

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.