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?

joelostblom
  • 1,889
  • 2
  • 19
  • 32
  • 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? – 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

2 Answers2

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'
Fabich
  • 151
  • 1
  • 9
Flash Thunder
  • 261
  • 1
  • 9
  • Thanks! Through you answer I found this thread that talks about the same solution http://stackoverflow.com/questions/9092982/mapping-c-j-to-something-in-vim, 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
  • This does not work for me. Pressing `` in insert mode still produces a new line. – pfincent Dec 10 '22 at 19:33
  • Maybe You're doing it on wrong account? – Flash Thunder Dec 11 '22 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>.

andreatsh
  • 1,985
  • 1
  • 14
  • 15
  • 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