I have the following in my vimrc:

nnoremap <C-J> o<Esc>k$
nnoremap <C-K> O<Esc>j$

The bottom mapping works as expected, but c-j now produces the same effect as i (which is really dumb). To troubleshoot, I tried:

verbose map c-j 
" UPDATE: the above is wrong. Instead use:
verbose map <c-j> 
verbose map <buffer>

The top command returns nothing (see last update), and the bottom nothing relevant. How can I find out what's wrong?

Update. Someone said this is a duplicate of this post, but I don't understand how. For what it's worth, I got the idea for the mapping from the vim wiki, so it must've worked for some people. In fact, it was working for me, too, before it stopped. Also, according to the help, c-j is supposed to be the same as c-n and <nl>, but that's not the case here as I said earlier. It behaves like i, and I would like to know how to figure out why.

Update II. The mapping now works fortuitously after the following change. If there's a decent explanation, I'll accept it as answer. Otherwise, I'm happy enough to get this to work.

" old
" nnoremap <CR> :noh<CR><CR>
" new
nnoremap <CR> :noh<return>

Update III. It's not working again, but I now realize that my verbose map syntax above is incorrect. The correct syntax gives me something to work with. Thanks all.

  • 2
    <C-J> is newline. Use another key for this mapping.
    – muru
    Jun 5, 2016 at 23:13
  • @muru See my edit. I don't see why it's a duplicate. For what it's worth, I even managed to map <cr>, with great results. This should work and has worked. Now that it doesn't, I want to find out why.
    – bongbang
    Jun 6, 2016 at 2:15
  • 1
    I didn't say you can't map <c-j>, I suggested using another key. In any case, if I add nnoremap <C-J> o<Esc>k$ and nnoremap <CR> :noh<CR><CR> to my vimrc, <c-j> works as expected. As you say: "fortuitously". Further, if you use nnoremap <CR> :noh<return>, and the cursor still moves down a line, I'd be very surprised. Since verbose map was silent, <c-j> was unmapped later on somewhere in your config. Have a look at any plugins you use. In any case, see: How do I debug my vimrc file?
    – muru
    Jun 6, 2016 at 3:34
  • 3
    also worth looking: vi.stackexchange.com/questions/7722/how-to-debug-a-mapping
    – nobe4
    Jun 6, 2016 at 10:30
  • 1
    I have just tried your mapping of <c-j> with both forms of the <CR> mapping and it seem to work in both cases so I'm not sure that was the real cause of your problem.
    – statox
    Jun 6, 2016 at 11:21


Your Answer

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

Browse other questions tagged or ask your own question.