Hi, this code is heavily influenced by vim.org tip #1363 "getchar trick using recursive <expr> map" by Hari Krishna Dara. Clever code. The code has also been posted on vim-dev recently. I just reworked it a bit to understand it better.
----- imap <buffer> <silent> <expr> <F12> Double("\<F12>") function! Double(mymap) let char = GetChar() if char =="\<Esc>" " return "\<Esc>"."\<C-R>=Redraw()\<CR>" return "\<Esc>" else return char."\<C-R>=Redraw()\<CR>".a:mymap endif endfunction function! Redraw() redraw return '' endfunction function! GetChar() try let char = getchar() " catch Interrupt <C-C> and convert it into <Esc> catch /^Vim:Interrupt$/ let char = "\<Esc>" finally try throw char " If the character typed is a number, convert it to character catch '^\d\+$' let char = nr2char(char) finally " Return whatever was typed, or converted return char endtry endtry return char endfunction ---- To execute: - source it in - go to Insert mode (a, i, o, ...) and start typing, observe that the cursor is inside the window at the place where the next typed-in char will be put (important). - now hit <F12>, the cursor will move to the bottom of the window and stay there but continue typing and characters will be placed correctly in the window. (Hit <Esc> to get out of INSERT.) Hence my question: how to move the cursor to the position as if one was in the "normal" INSERT mode? Thanks and regards, ---Zdenek
smime.p7s
Description: S/MIME Cryptographic Signature