4

Description:

In my Konsole the key mappings for changing tabs to left and right are Shift-left and Shift-right (where left/right are the arrow keys).

What I'm trying to do is to map F2 in vim to issue Shift-right, and thus change to the next tab in Konsole (in case of Clojure files, but probably this is not relevant). So, it would send keys "outside" of vim.

I've tried with the following mapping:

autocmd FileType clojure map <F2> <S-Right>

However, when I press F2, nothing happens. I'm fairly sure that the mapping syntax in general is right, since the following works as expected (inserts "Hello" at the current position):

autocmd FileType clojure map <F2> iHello

Questions:

  • Is <S-Right> really the correct combination for shift-right? (Based on the documentation, I suspect yes, but a confirmation would be nice.)
  • Is it possible at all to achieve what I want? (I.e. send keys "outside" vim.) I'm beginning to suspect that this is not possible...
  • If this can be done, then why does my command not work, and what is the way?
  • Is there a way to "debug" in vim, what is going on when I press a certain key? (I.e. lookup of mappings, and then the keys that are sent as a result.)

Background:

I'm developing Clojure and doing TDD. F2 was previously mapped to execute lein test and show the results:

autocmd FileType clojure map <F2> :wa<LF>:! clear && echo -en "\e[3J" && lein test<LF>

I got very used to just press F2 to show the test results, but today I found a plugin that can do continuous testing in the background, so I would like to keep my workflow with the new "implementation".

Remark:

I know that I could just remap F2 in Konsole, but I was curious if there is a way to achieve what I want in vim. This would have the additional advantage of not affecting all the other usages of console.

EDIT: (work-around)

Well, I found a way by running xdotool as an external command, which does what I want. Still I would be interested to the answers of the above questions, to deepen my knowledge about vim ;)

autocmd FileType clojure map <F2> :silent exec "!xdotool key shift+Right"<LF>:redraw!<LF>
4

To answer your several important points here:

Is <S-Right> really the correct combination for shift-right?

Yes <S-Right> indeed is the correct way to represent shiftright arrow in vimscript.

Is it possible at all to achieve what I want? (I.e. send keys "outside" vim.)

As you figured it out in your edit, yes it is possible.

If this can be done, then why does my command not work, and what is the way?

Here is the interesting part! When you do nnoremap <F2> <S-Right> you tell to Vim "When you see F2 behave as if you had seen shiftright arrow". You are not telling to your terminal emulator (i.e. Konsole) to do anything, the instructions are only internal to Vim.

That is why you had to use xdotool. With your current mapping you are telling to Vim "When you see F2, call an external command (xdotool) which will tell to Konsole that I pressed shiftright arrow.

Is there a way to "debug" in vim, what is going on when I press a certain key? (I.e. lookup of mappings, and then the keys that are sent as a result.)

To avoid repetition I create a pretty complete answer here : How to debug a mapping I think that might be worth reading it.

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.