How to insert text &nbsp; on current text position when I press <F1> key in vim in insert and normal mode?

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

How to insert text &nbsp; on current text position when I press <F1> key in vim in insert and normal mode?

Gena Makhomed
Hello, All!

How to insert text &nbsp; 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.

I use vim version 7.4 from CentOS 7.5

--
Best regards,
  Gena

--
--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How to insert text &nbsp; on current text position when I press <F1> key in vim in insert and normal mode?

Christian Brabandt

On Sa, 09 Jun 2018, Gena Makhomed wrote:

> Hello, All!
>
> How to insert text &nbsp; 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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How to insert text &nbsp; on current text position when I press <F1> key in vim in insert and normal mode?

Tony Mechelynck
On Mon, Jun 11, 2018 at 9:57 PM, Christian Brabandt <[hidden email]> wrote:

>
> On Sa, 09 Jun 2018, Gena Makhomed wrote:
>
>> Hello, All!
>>
>> How to insert text &nbsp; 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

Neither would I, because in Vim like in most other programs, F1 brings
you to the first page of help.

Gena: What's wrong with Ctrl-R n (in Insert mode) or "np (in Normal
mode)? Or if you're dead set on using only one keystroke, any F key
other than F1 (Help) and F10 (Menu) or any Shift-F key, would IMHO be
better than F1.


Best regards,
Tony.

--
--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How to insert text &nbsp; on current text position when I press <F1> key in vim in insert and normal mode?

Gena Makhomed
On 12.06.2018 2:22, Tony Mechelynck wrote:

> On Mon, Jun 11, 2018 at 9:57 PM, Christian Brabandt wrote:

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

Christian, thank you! All works fine now!

>> Note that I would not recommend mapping <f1>

Why not? <F1>, as I understand, is always mapped to vim :help command.
<F1> on keyboard located near <ESC> key, it is very useful to press <F1>

> Neither would I, because in Vim like in most other programs, F1 brings
> you to the first page of help.

And this is completely useless for me, I always can enter :help command
from keyboard. Even more, typing just three keys :h<CR> is enough.

It is more useful for me to read vim documentation via web-site,
for example, site http://vimdoc.sourceforge.net/htmldoc/help.html
contains documentation for vim 7.3, and I am use vim 7.4, it is Ok.

Web site http://vimdoc.sourceforge.net/htmldoc/help.html
was not updated from 2010 year - this is bug or feature?

> Gena: What's wrong with Ctrl-R n (in Insert mode) or "np (in Normal
> mode)?

wrong #1: it is different keys in different modes,
this is uncomfortable.

wrong #2: I need to press more when one key on the keyboard,
this is uncomfortable too.

wrong #3: I use vim to edit text written on Russian language,
and my keyboard frequently switched to Russian language layout.
If keyboard in Russian language mode - vim just beep and do nothing.

So, I need first switch keyboard from Russian to English,
when find in which mode vim is currently, and select appropriate
keyboard sequence, when enter this sequence on keyboard,
when switch keyboard back from English to Russian mode.

This is very uncomfortable for editing text.
Just pressing <F1> is very fast and very useful.

> Or if you're dead set on using only one keystroke, any F key
> other than F1 (Help) and F10 (Menu) or any Shift-F key, would IMHO be
> better than F1.

I just don't want continually switch keyboard
from Russian to English and from English to Russian.

So, I can use only functional keys on keyboard or other
key combinations which are available in VT100 terminal mode.
(I use PuTTY, ssh and screen, so terminal is limited to VT100)

P.S.

One more question.

Is it possible with vim:

If I press <F1> and text under cursor is space - replace it with &nbsp;
If I press <F1> and text under cursor is not space - generate beep

I try to write this via function:

===========================================================

function SpaceReplace()
     if getline(".")[col(".")-1] == ' '
         echo "replace <space> under cursor with &nbsp;"
     else
         echo "beep"
     endif
endfunction

inoremap <F1> <esc>:call SpaceReplace()<CR>a
nnoremap <F1> :call SpaceReplace()<CR>

===========================================================

But I can't understand what I need to write instead "echo".

--
Best regards,
  Gena

--
--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How to insert text &nbsp; on current text position when I press <F1> key in vim in insert and normal mode?

arocker
In reply to this post by Tony Mechelynck
> On Mon, Jun 11, 2018 at 9:57 PM, Christian Brabandt <[hidden email]>

> mode)? Or if you're dead set on using only one keystroke, any F key
> other than F1 (Help) and F10 (Menu) or any Shift-F key, would IMHO be
> better than F1.
>

This reminds me of the story about a nerd who fell into a river and
drowned, despite his cries of "F1, F1".

--
--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How to insert text &nbsp; on current text position when I press <F1> key in vim in insert and normal mode?

David Woodfall
In reply to this post by Gena Makhomed
On Tuesday 12 June 2018 10:36,
Gena Makhomed <[hidden email]> put forth the proposition:

> On 12.06.2018 2:22, Tony Mechelynck wrote:
>
> > On Mon, Jun 11, 2018 at 9:57 PM, Christian Brabandt wrote:
>
> > > :let @n='&nbsp;'
> > > :inoremap <F1> <c-r>n
> > > :nmap <f1> a<f1><esc>
>
> Christian, thank you! All works fine now!
>
> > > Note that I would not recommend mapping <f1>
>
> Why not? <F1>, as I understand, is always mapped to vim :help command.
> <F1> on keyboard located near <ESC> key, it is very useful to press <F1>
>
> > Neither would I, because in Vim like in most other programs, F1 brings
> > you to the first page of help.
>
> And this is completely useless for me, I always can enter :help command
> from keyboard. Even more, typing just three keys :h<CR> is enough.
>
> It is more useful for me to read vim documentation via web-site,
> for example, site http://vimdoc.sourceforge.net/htmldoc/help.html
> contains documentation for vim 7.3, and I am use vim 7.4, it is Ok.
>
> Web site http://vimdoc.sourceforge.net/htmldoc/help.html
> was not updated from 2010 year - this is bug or feature?
>
> > Gena: What's wrong with Ctrl-R n (in Insert mode) or "np (in Normal
> > mode)?
>
> wrong #1: it is different keys in different modes,
> this is uncomfortable.
>
> wrong #2: I need to press more when one key on the keyboard,
> this is uncomfortable too.
>
> wrong #3: I use vim to edit text written on Russian language,
> and my keyboard frequently switched to Russian language layout.
> If keyboard in Russian language mode - vim just beep and do nothing.
>
> So, I need first switch keyboard from Russian to English,
> when find in which mode vim is currently, and select appropriate
> keyboard sequence, when enter this sequence on keyboard,
> when switch keyboard back from English to Russian mode.
>
> This is very uncomfortable for editing text.
> Just pressing <F1> is very fast and very useful.
>
> > Or if you're dead set on using only one keystroke, any F key
> > other than F1 (Help) and F10 (Menu) or any Shift-F key, would IMHO be
> > better than F1.
>
> I just don't want continually switch keyboard
> from Russian to English and from English to Russian.
>
> So, I can use only functional keys on keyboard or other
> key combinations which are available in VT100 terminal mode.
> (I use PuTTY, ssh and screen, so terminal is limited to VT100)
>
> P.S.
>
> One more question.
>
> Is it possible with vim:
>
> If I press <F1> and text under cursor is space - replace it with &nbsp;
> If I press <F1> and text under cursor is not space - generate beep
>
> I try to write this via function:
>
> ===========================================================
>
> function SpaceReplace()
>     if getline(".")[col(".")-1] == ' '
>         echo "replace <space> under cursor with &nbsp;"
>     else
>         echo "beep"
>     endif
> endfunction
>
> inoremap <F1> <esc>:call SpaceReplace()<CR>a
> nnoremap <F1> :call SpaceReplace()<CR>
>
> ===========================================================
>
> But I can't understand what I need to write instead "echo".

For the replacement you could try:

normal xi&nbsp;

For the 'beep' I guess echomsg "ERROR" for a visual message, or
something like:

silent ! printf "\a"

to make an ascii bell. Substitute the command after the ! to play a
sound if you want that. You will probably need to do a :redraw or a
:redrawstatus afterwards.

-Dave

> --
> Best regards,
>  Gena

--

There are no threads in a.b.p.erotica,  so there's no  gain in using a
threaded news reader.
  -- unknown source

                                                            .--.  oo
                                                           (____)//
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'

--
--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How to insert text &nbsp; on current text position when I press <F1> key in vim in insert and normal mode?

Ken Takata-2
In reply to this post by Gena Makhomed
Hi,

2018/6/15 Fri 9:26:22 UTC+9 Gena Makhomed wrote:
> Web site http://vimdoc.sourceforge.net/htmldoc/help.html
> was not updated from 2010 year - this is bug or feature?

There are at least two Web help sites which are up to date:
http://vimhelp.appspot.com/
https://vim-jp.org/vimdoc-en/

Regards,
Ken Takata

--
--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How to insert text &nbsp; on current text position when I press <F1> key in vim in insert and normal mode?

Christian Brabandt
In reply to this post by Gena Makhomed

On Di, 12 Jun 2018, Gena Makhomed wrote:
> But I can't understand what I need to write instead "echo".

ESC in normal mode beeps (depending on your configuration it might also
generate a visual bell or do nothing depending on various settings
'visualbell' 't_vb', 'belloff')

Best,
Christian
--
Ausschüsse:
  Gremien, die Probleme lösen, die es ohne die Ausschüsse nicht gäbe.

--
--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.