Simple Vim questions -- Backspace + Escape in maps

25 views
Skip to first unread message

bertran...@gmail.com

unread,
Dec 31, 2022, 3:47:47 PM12/31/22
to vim_use

I used Vi for many years (on Unix) then stopped, but need it again (on Windows 10). There are couple of things that I used to be able to do in my sleep but no longer master, and the online information is hard to use (it talks about very complicated things but I was not able to find simple answers to simple questions).

 

1. Backspace in insert mode, over some characters, gives a special character instead of erasing. I remember that this was a feature, not a bug – a way to type special characters when they were troublesome to produce otherwise. I don’t need that facility, which is very annoying; I just want backspace to erase. What should I do? My settings file (_vimrc) currently has

 

              set bs=2

 

2. How do I represent ESC in a macro (my name for the result of a “map”)? I want to define something like

 

              :map v iSOME TEXT<Esc>

 

so that when I type “v” it will insert SOME_TEXT at the current position and then escape (get out of insert mode). But I no longer know how to type what appears above as <Esc> when entering the macro. I remembered various incantations involving CTRL-V or CTRL-G but they do not seem to work.

 

Very basic stuff, I just forgot.

 

Help will be much appreciated.

 

With best regards,

 

-- Bertrand Meyer

New book just out: Handbook of Requirements and Business Analysis, Springer, 2022

A treatise and textbook on requirements, see https://se.ethz.ch/requirements

 

Enan Ajmain

unread,
Jan 1, 2023, 8:57:00 AM1/1/23
to bertran...@gmail.com, vim...@googlegroups.com
On Sat, 31 Dec 2022 09:11:04 -0800 (PST)
"bertran...@gmail.com" <bertran...@gmail.com> wrote:
> 1. Backspace in insert mode, over some characters, gives a special
> character instead of erasing. I remember that this was a feature, not a bug
> – a way to type special characters when they were troublesome to produce
> otherwise. I don’t need that facility, which is very annoying; I just want
> backspace to erase. What should I do? My settings file (_vimrc) currently
> has
>
> set bs=2

I have never heard of this feature. Maybe you can try reading ':h bs'
and ':h :fixdel'.

> 2. How do I represent ESC in a macro (my name for the result of a “map”)? I
> want to define something like
>
> :map v iSOME TEXT<Esc>
>
> so that when I type “v” it will insert SOME_TEXT at the current position
> and then escape (get out of insert mode). But I no longer know how to type
> what appears above as <Esc> when entering the macro. I remembered various
> incantations involving CTRL-V or CTRL-G but they do not seem to work.

Which version of Vim are you using? And it _is_ Vim, not Vi, right?
Because in Vim, your map should work. What I will recommend is using
'nnoremap' instead of 'map' because:

o You want "v" to be mapped only in normal mode. Otherwise you can't
enter "v" in insert mode without using ':h i_CTRL-V'.
See ':h nmap'.
o You don't want nested or recursive mapping. See ':h noremap'.

--
Enan
3nan....@gmail.com
https://git.sr.ht/~enan/
https://www.github.com/3N4N

Enan Ajmain

unread,
Jan 1, 2023, 11:21:57 AM1/1/23
to vim...@googlegroups.com
On Sun, 1 Jan 2023 19:56:48 +0600
Enan Ajmain <3nan....@gmail.com> wrote:
> On Sat, 31 Dec 2022 09:11:04 -0800 (PST)
> "bertran...@gmail.com" <bertran...@gmail.com> wrote:
> > 2. How do I represent ESC in a macro (my name for the result of a ___map___)? I
> > want to define something like
> >
> > :map v iSOME TEXT<Esc>
> >
> > so that when I type ___v___ it will insert SOME_TEXT at the current position
> > and then escape (get out of insert mode). But I no longer know how to type
> > what appears above as <Esc> when entering the macro. I remembered various
> > incantations involving CTRL-V or CTRL-G but they do not seem to work.
>
> Which version of Vim are you using? And it _is_ Vim, not Vi, right?
> Because in Vim, your map should work. What I will recommend is using
> 'nnoremap' instead of 'map' because:
>
> o You want "v" to be mapped only in normal mode. Otherwise you can't
> enter "v" in insert mode without using ':h i_CTRL-V'.
> See ':h nmap'.
> o You don't want nested or recursive mapping. See ':h noremap'.

Sorry, I misunderstood your message. You're trying to map so that it
inserts the text "<Esc>". For that you need to add a literal 'Ctrl-V'
character in the map. Type this exactly (here ^V is a Ctrl-V):

:nnoremap v iTEXT^V^V<Esc>

To clarify, you need to press Ctrl-V twice, but only one literal Ctrl-V
will be inserted. It's quite intuitive once you know it. I am sure you
can explain the machinery yourself. Read ':h using_CTRL-V'.

bertran...@gmail.com

unread,
Jan 2, 2023, 11:38:47 AM1/2/23
to vim_use
Thank you, this is the idiom I had wired in years ago and forgotten. I really appreciate your help.

-- Bertrand Meyer

Christian Brabandt

unread,
Jan 2, 2023, 12:00:33 PM1/2/23
to vim...@googlegroups.com
Am 2022-12-31 18:11, schrieb bertran...@gmail.com:
> I used Vi for many years (on Unix) then stopped, but need it again (on
> Windows 10). There are couple of things that I used to be able to do
> in my sleep but no longer master, and the online information is hard
> to use (it talks about very complicated things but I was not able to
> find simple answers to simple questions).
>
> 1. Backspace in insert mode, over some characters, gives a special
> character instead of erasing. I remember that this was a feature, not
> a bug – a way to type special characters when they were troublesome
> to produce otherwise. I don’t need that facility, which is very
> annoying; I just want backspace to erase. What should I do? My
> settings file (_vimrc) currently has
>
> set bs=2


Hm, I don't know about backspace, but perhaps you meant to not redraw
the line when doing a change command by e.g. `:set cpo+=$` (see :h
cpo-$)


Best,
Chris

Jürgen Krämer

unread,
Jan 3, 2023, 8:01:13 AM1/3/23
to vim...@googlegroups.com
Hi,

I don't see the original message so I will answer to Enan's message.

Enan Ajmain schrieb am 01.01.2023 um 14:56:
On Sat, 31 Dec 2022 09:11:04 -0800 (PST)
"bertran...@gmail.com" <bertran...@gmail.com> wrote:
1. Backspace in insert mode, over some characters, gives a special
character instead of erasing. I remember that this was a feature, not a bug
– a way to type special characters when they were troublesome to produce
otherwise. I don’t need that facility, which is very annoying; I just want
backspace to erase. What should I do? My settings file (_vimrc) currently
has

              set bs=2

You might want to have a look at the 'digraph' option.

Regards,
Jürgen


Steve Martin

unread,
Jan 4, 2023, 1:46:04 AM1/4/23
to vim_use
Another question, what happens when you use the Backspace key on a command line in a Terminal? Do you get something that looks like: ^?

If so, it may be your terminal emulator is at fault for mishandling the key.

Reply all
Reply to author
Forward
0 new messages