Hi Ingo!

On Sa, 05 Feb 2011, Ingo Karkat wrote:

> Not every normal mode-mapping is automatically suitable for execution via
> i_CTRL-O; you need to explicitly design your mappings for that purpose. I
> wouldn't call it a bug, rather a weakness in Vi(m)'s model of mode-based 
> operation.
> 
> 
> Here are some rules and guidelines from my personal "Vim scripting guide":
> 
> The |i_CTRL-O| command allows execution of one normal mode command, then
> returns to insert mode. If a normal mode mapping concatenates multiple normal
> mode commands, this breaks down in temporary normal mode and literally inserts
> the second part of the command into the buffer instead.
> To support execution of normal mode mappings from within insert mode (via
> |i_CTRL-O|), these strategies can be used:
> a) Instead of concatenating multiple normal mode commands, use one :normal
>    mapping: >
>    "nnoremap zC zCVzC
>    nnoremap <silent> zC :<C-U>normal! zCVzC<CR>
> b) Concatenate multiple Ex commands via <Bar>, not >
>     :<C-U>call FirstCommand()<CR>:<C-U>call SecondCommand()<CR>
> c) Shadow normal mode mappings are by insert mode mappings that re-enter
>    normal mode, then invoke the normal mode mapping. >
>     inoremap <silent> <script> <SID>MyMapping <C-\><C-O><SID>MyMapping
> d) Normal mode mappings that consist of multiple Ex command lines (and where
>    Ex commands cannot be concatenated via <Bar>) use <SID>NM instead of
>    ':<C-U>'; the insert mode variant of <SID>NM re-enter command mode for one
>    ex command line. >
>     " Handle execution from insert mode via |i_CTRL-O|.
>     nnoremap <silent> <SID>NM :<C-U>
>     inoremap <silent> <SID>NM <C-\><C-O>:
>     "nnoremap <silent> <script> <SID>MyMap1:<C-U>call MySecondCommand()<CR>
>     nnoremap <silent> <script> <SID>MyMap1<SID>NMcall MySecondCommand()<CR>
> e)  If none of the above is possible, at least force normal mode for
>     subsequent commands via |CTRL-\_CTRL-N| to avoid accidental insertion of
>     the remainder of the mapping. >
>     nnoremap zC zC<C-\><C-N>VzCzz
> 
> If you rewrite your mapping as follows, it'll also work in temporary insert 
> mode:
>     :nnoremap <F9> :execute 'normal! 0'<Bar>echo getfontname()<CR>
> 
> -- regards, ingo
> 

Good information. I took your text, reworked it a little bit and put it 
into the faqı It's question 20.20 and it should be in the web tomorrow 
or the day after tomorrow. Please check.

ı) http://www.github.com/chrisbra/vim_faq
and on the web at:
http://vimhelp.appspot.com/vim_faq.txt.html

Mit freundlichen Grüßen
Christian
-- 

-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

Raspunde prin e-mail lui