Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trouble mapping <C-j> in Vim with latex-suite

Tags:

vim

mapping

latex

I wanted to map <C-j> to switch to the next window below the current one

map <C-j> <C-w>j

However, it goes into Insert mode instead of moving the window below. Why?

Solution attempted:

I have latex-suite installed. So I tried to query what <C-j> is mapped to

:map <C-j>

And I get the following output:

v  <NL>          <Plug>IMAP_JumpForward
n  <NL>          <Plug>IMAP_JumpForward
o  <NL>          <C-W>j

This means that I should change the mapping of <Plug>IMAP_JumpForward. I read around a bit and I found out it's related to the <++> placeholders that you can jump to using <C-j> during Insert mode. So, based on my reading, I learned I could change the mapping using the following line in .vimrc:

imap <C-space> <Plug>IMAP_JumpForward

But no, it doesn't work as <C-j> used to. I'll try to illustrate. I type the following (the _ represents the cursor):

\documentclass{}_

Then I get

\documentclass{_}<++>

Then I try to type in some text

\documentclass{article_}<++>

So now I press <C-space>. This is what happens: it goes out of Insert mode and I'll be in the following situation:

\documentclass{articl_e}<++>

Problem summary:

  1. After map <C-j> <C-w>j, <C-j> goes into Insert mode.
  2. After imap <C-space> <Plug>IMAP_JumpForward, <C-space> doesn't jump to the next <++> placeholder. It goes out of Insert mode and cursor backs up one character.

What's the matter? Anything I missed?

like image 880
Kit Avatar asked Nov 29 '11 00:11

Kit


2 Answers

I suggest two things:

  1. firstly, target the mappings:

    nnoremap <C-j> <C-w>j
    
  2. secondly, find out what mappings interfere (and where they come from) by doing

    verbose nmap <C-j>     
    verbose nmap <C-w>
    verbose nmap j
    

see also :map, :imap, :vmap, :noremap etc.

like image 66
sehe Avatar answered Oct 09 '22 12:10

sehe


I have had the same problem; for me, it was behaving weirdly since the <C-j> from vim-latex is mapped for the normal visual and insert modes. I kind of felt that after seeing this answer and checking the 'imaps.vim' file in the '\bundle\vim-latex\plugin' directory. I put the following code in my vimrc and it seems to work.

imap <C-space> <Plug>IMAP_JumpForward
nmap <C-space> <Plug>IMAP_JumpForward
vmap <C-space> <Plug>IMAP_JumpForward
like image 3
Whynot Ogle Avatar answered Oct 09 '22 14:10

Whynot Ogle