Meino Christian Cramer wrote:
From: "A.J.Mechelynck" <[EMAIL PROTECTED]>
Subject: Re: Mapping of keysequences...
Date: Sun, 01 Oct 2006 19:44:39 +0200

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.


Hi Tony,

 as I said...I am currently not thinking vim-y enough ... :)))))))

 With "<Left>" it is so much easier to achieve the wanted effect than
 jumping betwen the modes and inserting things only for the purpose of
 replaceing them with something different...

 And the register-trick with @b,@f,@s is even more simpler!

 One last question:
 Will it hurt or eat up my system resources :) when I insert the 'let'
commands into my .vimrc?

well, it will just (after the first time) place into your registers what is already there because your viminfo automatically saves it from session to session. The "resources" it "eats up" are, I suppose, a few bytes of vimrc disk space and a few milliseconds of startup time ;-). Nothing much to worry about.

 This is to avoid haveing "one part" of a macro in .vimrc and the
 other one in .viminfo....not to confuse myself right in the beginning
 of learning of vim if not needed.

Thank you very much, Tony !
 Keep hacking!
 mcc



And if you put these three values in the registers, you don't need anything for this in the vimrc -- there is no "other part". Ctrl-R letter (in Insert mode) directly invokes the corresponding register. Similarly Ctrl-R + (the system clipboard), Ctrl-R / (the latest search pattern), etc.

There are several ways to invoke each register:

        "x in Normal mode commands (y, d, p etc.)
        @x      in expressions and in :let, :redir, etc.
        x       in the argument to :yank, :put etc.
        "x"   in the first argument to setreg() etc.
        <C-R>x    in Insert/Replace and Command-line modes

In all these cases, the register is the same if the letter is the same. And if you ever forget what is in your registers, there is always the ":reg[isters]" command.


Best regards,
Tony.

Reply via email to