3

I would like to remap ctrl + j to ctrl + d, and ctrl + k to ctrl + u for moving half a page down and up in normal mode. I have tried with

noremap <c-j> <c-d>
noremap <c-k> <c-u>

in my .vimrc, but the key function does not change.

I read on the vim wiki that

The Ctrl-J character represents the linefeed and is internally used by Vim to represent the Nul character. You cannot create a map for Ctrl-J by using the following command:

"The following command doesn't work

:imap Newlinecharacter

Is there any way to remap ctrl + j and ctrl + k in vim?

  • 1
    Is is possible to see why this question was downvoted, so I know if I should change the format of my questions in the future? – joelostblom Dec 11 '16 at 20:37
  • Yes, this should be possible, and your commands are right. Are you sure your .vimrc is loaded? Check output of :map and :scriptnames. – Ingo Karkat Dec 12 '16 at 15:43
  • I discovered that I had an interfering addon, this works after disabling that addon. Weirdly, I previously tested this with an empty .vimrc (apart from these lines), but that was not working, just disabling the addon and keeping the rest of my current config... – joelostblom Dec 21 '16 at 15:36
5

With those, you first need to unmap them:

For example, for CTRL+J put the following line in the file '.vimrc':

let g:BASH_Ctrl_j = 'off'
  • Thanks! Through you answer I found this thread that talks about the same solution stackoverflow.com/questions/9092982/…, so this seems to be the way to go. For some reason, it is still not working for me, even after clearing everything else from my .vimrc. Instead, I just ended up using capital J and K in the end. – joelostblom Dec 11 '16 at 20:35
3

Almost there. You need to add these lines to your .vimrc:

nnoremap <C-j> <C-d>
nnoremap <C-k> <C-u>

When I want to know how vim works I find useful :help <command>.

  • This is what I tried. Sorry if it wasn't clear, I edited the question. – joelostblom Dec 11 '16 at 20:36
  • I'm sorry, but I did some tests and this is working for me. Note that noremap and nnoremap are not the same thing. If you want a non-recursive normal mode mapping nnoremap is what you are looking for. – andreatsh Dec 11 '16 at 20:41
  • My apologies, I did not notice the extra "n" at the start of each line. I also discovered that I had an interfering addon, this works after disabling that addon and so does mu original solution. Weirdly, I previously tested this with an empty .vimrc (apart from these lines), but that was not working, just disabling the addon and keeping the rest of my current config... – joelostblom Dec 21 '16 at 15:35

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.