10

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?

3
  • 2
    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? Dec 11, 2016 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. Dec 12, 2016 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... Dec 21, 2016 at 15:36

2 Answers 2

7

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'
3
  • 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. Dec 11, 2016 at 20:35
  • This does not work for me. Pressing <C-j> in insert mode still produces a new line.
    – pfincent
    Dec 10, 2022 at 19:33
  • Maybe You're doing it on wrong account? Dec 11, 2022 at 13:41
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>.

3
  • This is what I tried. Sorry if it wasn't clear, I edited the question. Dec 11, 2016 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, 2016 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... Dec 21, 2016 at 15:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .