4

When I type [[ or ]] in normal mode, cursor is jumping previous / next "class definition" during editing python (.py) file.

I want to map these shortcuts to SHIFT + UP and SHIFT + DOWN. And I added this to my vimrc:

nnoremap <S-Up> [[
nnoremap <S-Down> ]]

But when I press SHIFT + UP, cursor going beginning of the file, or if I press SHIFT + DOWN, cursor going end of the file.

How can I map these keys?

  • Just tried it in Gvim and Neovim in Windows, works fine. Tried it on my linux box in a terminal and doesn't work. I think the issue is what key is being sent when you press shift+up. What type of system are you running? – jecxjo Nov 2 '16 at 20:06
  • @jecxjo Ubuntu 14.04 with Unity. I'm working on default terminal and vim8. – Umut Çağdaş Coşkun Nov 2 '16 at 20:09
5
nnoremap <S-Up> [[
nnoremap <S-Down> ]]

With the non-recursive mappings above in your vimrc, pressing <S-Up> will be exactly like pressing [[ in its original meaning.

The original meaning of [[ is (quoting :help [[):

[[    [count] sections backward or to the previous '{' in
      the first column.

which, usually, means "jump to the first column of the first line". Same logic for ]].

Since you are using non-recursive mappings, the original meaning of [[ and ]] is used, not the remapped versions from the Python filetype plugin.

You need recursive mappings:

nmap <S-Up> [[
nmap <S-Down> ]]

The rule is:

Use a recursive mapping only if you intend to use any other mapping in your mapping. Use non-recursive mappings if you don't.

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.