1

I am using the plugin vim-latex/vim-latex. It's a fantastic plugin for sure. But I want some of my own mapping to be there. Say whenever I press 4 I want $$ in return with the cursor on the second $, or whenever I press { I want {} in return with the cursor on }.

Earlier I added the following to my .vimrc:

inoremap 4 $$ < esc>i

inoremap { {} < esc>i

inoremap 0 <Esc>lla

The last one takes the cursor 2 steps to the right while in insert mode.

But these are not working now. What can I do to achieve similar functionality now? Thanks in advance.

1

The suggestion from Vim-LaTeX is to use IMAP() which takes IMAP('lhs','rhs','ft') which looks for lhs, replaces it with rhs when the filetype is ft.

For your two cases the following work

call IMAP('4','$<++>$','tex')
call IMAP('{','{<++>}','tex')

where <++> is a placeholder to indicate where the cursor should go (see the vim-LaTeX documentation or What does <++> signify when using Vim LatexSuite?).

Personally I prefer to define an vim-latex environment as

let g:Tex_Env_m = "$ <++> $<++>"

which can then be called with mF5 to produce inline maths.


Responding to the comment, non-insert mode stuff can be called using Ctrl+O e.g.

call IMAP('3',"\<C-O>f{",'tex')

will temporarily use normal mode to execute f{ which will find the next { and then leaving you with insert mode.

  • Thanks Dai. I had some other mapping too, like: inoremap 3 llf}i which finds the next } whenever I press 3 in insert mode, or inoremap 1 A which take the cursor to the end of the line in insert mode, or inoremap 0 <Esc>lla which take the cursor 2 steps right of current position. I'm new to vim-latex, I'm not sure how to achieve these. Sorry if the questions are too boring. – Mahbub Alam Mar 8 '18 at 21:40
  • @MahbubAlam I've added your first example which involves doing stuff beyond insert mode. If that's not enough for you to define all the others you want yourself, please help me understand what aspect of the syntax isn't making sense to you. – Dai Bowen Mar 8 '18 at 21:58
  • Let me check my other remaps, I guess now I can manage. Thank btw. If I have some other troubles I'll let you know. – Mahbub Alam Mar 8 '18 at 22:10
  • My remapping problems are solved. I was trying to use my earlier abbreviations. IMAP is interfering with abbreviations. I couldn't find a way online to resolve this. Can you help me on this issue? – Mahbub Alam Mar 9 '18 at 3:06
  • 1
    Let us continue this discussion in chat. – Mahbub Alam Mar 9 '18 at 15:24

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.