I have the following in my init.vim:

nnoremap K \%              " Swap K with % in [n]ormal mode
vnoremap K \%              " Swap K with % in [v]isual mode
xnoremap K \%              " Swap K with % in [V]isual mode
nnoremap \% K              " Swap % with K in [n]ormal mode
vnoremap \% K              " Swap % with K in [v]isual mode
xnoremap \% K              " Swap % with K in [V]isual mode

All I want is to change the default code block selection which is % by default to K (Shift k), but it's not working.

I have escaped the % with \% and it's not working. I also tried normal % and it didn't work either. But whenever I move my cursor on a { and then press K (Shift k) then Neovim freezes.

How can I remap this key?

I'm using Neovim.

  • I have tested the standard solution and it is working fine. Maybe could you verify launching vim with vim -i NONE -u NONE and executing your mapping in the command line (or using the %so command) or with vim --clean Apr 20, 2023 at 11:01

2 Answers 2


I would do:

nnoremap K %
nnoremap % K
vnoremap K %
vnoremap % K

The solution provided by Vivian works as expected, but I had a very strange issue and it was due to extra space I had after the remapped key and the comment, which wasn't obvious at all.

Meaning that:

nnoremap K %              " comment

Would have remapped K to % , but that's not what we want.

That extra whitespace space ( ) caused a whole problem for me since I had mapped my leader key to space. It was hard to debug what I was doing wrong, but it's worth sharing anyway.

I simply moved the comment to live above, and removed the extra whitespace and it got fixed:

" comment
nnoremap K %
  • 1
    See :help map-comments
    – D. Ben Knoble
    Apr 20, 2023 at 19:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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