Monday, June 11, 2018

Re: How to insert text   on current text position when I press key in vim in insert and normal mode?

On Sa, 09 Jun 2018, Gena Makhomed wrote:

> Hello, All!
>
> How to insert text   on current text position
> when I press <F1> key in vim in insert and normal mode?
>
> I try to use macros, and put in .vimrc:
>
> let @n = "i&nbsp;\<esc>"
>
> then I switch no normal mode - I can run this macro by pressing @n
> but how to bind this macro to <F1> key in normal and insert mode?
>
> I try to use in .vimrc:
>
> imap <F1> <esc>@n<cr>a
> nmap <F1> @n<cr>
>
> and
>
> inoremap <F1> <esc>@n<cr>a
> nnoremap <F1> @n<cr>
>
> but this is not work.
>
> When I write function:
>
> function InsertNbsp()
> normal @n
> endfunction
>
> and when I call this function
>
> :call InsertNbsp()
>
> this work,
> but when I try to bind this function to <F1> key:
>
> inoremap <F1> <esc>:call InsertNbsp()<cr>a
> nnoremap <F1> :call InsertNbsp()<cr>
>
> - it not work.


something like this, if your register contains '&nbsp;':

:let @n='&nbsp;'
:inoremap <F1> <c-r>n
:nmap <f1> a<f1><esc>


Note that I would not recommend mapping <f1>

Best,
Christian
--
Das X ist der Klappstuhl des Alphabets.
-- Ramòn Gómez de la Serna

--
--
You received this message from the "vim_use" 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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment