Meino Christian Cramer wrote:
[...]
Hi Tony !

 nice to read you again! And thank you very much for your
 help,help,help... :)  <- BIG smiley!

 Slowly and surely I get my TeX macro working...

 What I have now is the following:

   inoremap <C-C><C-F>b {\bf #}<ESC>?#<CR>c/}<CR>
   inoremap <C-C><C-F>i {\it #}<ESC>?#<CR>c/}<CR>
inoremap <C-C><C-F>s {\sl #}<ESC>?#<CR>c/}<CR>
 which "works". A last wish I would have is: After 'c'hanging the '#'
 to what I really want to typeset I will press <ESC> to leave
 'c'hanging and insert mode. But my cursor still is inside of the {}....

 Is it possible to let the macros recognize the pressing of '<ESC>'
 and then jump behind the '}' and may be entering 'i'nsert mode again?

 Or may be I need a completly different implementation of those macros
 for that?

 I often feel, that I am not thinking vim-y enough. ;o)

 Thanks a lot for all your help!

 Keep hacking!
 mcc



The {rhs} (right-hand side) of a mapping is exactly the sequence of keys as you would hit them to accomplish the desired action. In Insert mode you can move the cursor using <Left> <Right> etc., so instead of <Esc>?#<CR> you can use <Left><Left>. This means that you can leave out the # in the first place, and just use one <Left> to place the cursor before the }. You then remain in Insert mode to insert whatever you want through the keyboard after the mapping has finished:

        :imap <C-C><C-F>b   {\bf }<Left>

etc.

If you want the _next_ use of <Esc> to move the cursor after the } then it becomes more intricate: you will need to use a function as {rhs} to return the required string and remap <Esc> as a side-effect; but "what you remap <Esc> to" must not only do the required cursor move but also unmap itself. In this case I don't think the game is worth the candle, especially if {\bf } {\it } {\sl } etc. can be nested. It may be simpler to just hit <Right> to go past the right-bracket when you want to close the "{\bf " or similar.

Another possibility is to simply yank these strings (without the closing brace) into some registers (which will be saved in your viminfo so you do this only once, at the command-line):

        :let @b = '{\bf '
        :let @i = '{\it '
        :let @s = '{\sl '

(Note the _single_ quotes.) Then, in Insert mode, <C-R>b will insert {\bf<Space> and similarly for the other two (even after you close and reopen Vim, without the need to reenter them). Hit } to close the (bold?) text area.


Best regards,
Tony.

Reply via email to