When using vimgrep with lv expr path/**, I like to have a shortcut for navigating the results. So I mapped the F3 key like the following:

nnoremap <F3> :lnext<CR>

Now I would like to do something like the following

nnoremap <SHIFT-F3> :lprevious<CR>

But this does not have the desired effect. How do I map a F-key with SHIFT?


The solution is a bit difficult. In terminals you cannot just map Shift+F3. In fact an additional line like the following is necessary:

set <S-F3>=^[O1;2R
nnoremap <S-F3> :lprevious<CR>

But you cannot copy&paste this, see the link below in the right answer.


You're using Vim in the console, not GVIM, right? Anything other than the plain function keys is problematic, and best avoided; try using a prefix like <Leader> instead. If you really want this, you can try the instructions at http://vim.wikia.com/wiki/Mapping_fast_keycodes_in_terminal_Vim for getting function keys with modifiers to work.

  • That link was very helpful, I did not even expected a problem like this. Although it is not the answer I wished to read, it is the right answer in my opinion. And following the advise with fast key codes, I could map the key combination as desired. – Trendfischer Nov 22 '12 at 8:21

It should be <S-F3> not <SHIFT-F3>, see :help key-notation in Vim.

  • Yes, this is the answer I wanted to have, but it did not work this way. You need :set for making it in a terminal to work. – Trendfischer Nov 22 '12 at 8:22

Nowadays setting extra keycodes for functional keys isn't necessary, all you need is:

nnoremap <s-f3> :lprevious<cr>

Tested on NeoVim.

Somebody please try it on clean VIM so I could update this answer.

  • Doesn't work with neovim on the terminal – shaahiin Dec 24 '20 at 3:53
  • Maybe it's terminal dependent. Works out of the box on up to date Gnome terminal and Neovim. – cprn Dec 28 '20 at 14:47

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.