mapping ALT-backspace

651 views
Skip to first unread message

meino....@gmx.de

unread,
Nov 1, 2011, 10:53:28 PM11/1/11
to vim...@googlegroups.com
Hi,

the zsh I am using is recoginzing ALT-backspace as "delete one
word backward", which is very handy.

Unfortunately I have not found a way to map this in a similiar
way for vim.

How can I map ALT-backspace in vim?

Thank you very much in advance for any help!
Best regards,
mcc

Tony Mechelynck

unread,
Nov 2, 2011, 1:36:30 AM11/2/11
to vim...@googlegroups.com

In Console Vim, it may depend on your terminal: I'm not sure that every
terminal passes something recognizable to Vim when you hit Alt-Backspace.

In gvim, it's <M-BS> and my gvim (with GTK2/Gnome2 GUI) sees it.

To see if Vim gets something when you hit that key combo, open Vim in
Insert mode in an empty buffer and hit Ctrl-V followed by Alt-Backspace,
then Ctrl-K followed by Alt-Backspace. If you don't get anything, Vim
hasn't seen the keypress. If it sees something, in gvim you should see
the <> equivazlent in both cases; in Console Vim you should see the
bytes passed by the keyboard interface after Ctrl-V, or the <>
equivalent (here, <M-BS>, unless the keyboard passes something else)
after Ctrl-K.

In Insert mode, to delete the word before the cursor you can hit Ctrl-W,
see :help i_CTRL-W

In Normal mode, you should be able to use Shift-Left as a modifier to
the d (delete) command, to delete [count] words leftwards, or the
command daw ("delete a word") to delete the word under the cursor (on
both sides) and the white space on one side of it. See :help text-objects


Best regards,
Tony.
--
hundred-and-one symptoms of being an internet addict:
209. Your house stinks because you haven't cleaned it in a week.

meino....@gmx.de

unread,
Nov 2, 2011, 10:54:33 PM11/2/11
to vim...@googlegroups.com
Tony Mechelynck <antoine.m...@gmail.com> [11-11-02 06:40]:
> --
> 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
>


Hi Tony,

Thank you very much for your explanations. Since I am using console
vim most of the time I am trying to get it working there.

The result of the test is, that vim doesn't see any of the keypresses.
You wrote that is due to the terminal.

I dont understand this completly I fear...

The zsh, running under the same terminal adn which was the one startet
vim, does see ALT-nackspace.

What I am doing/inderstanding wrong here?

Best regards,
mcc


Tony Mechelynck

unread,
Nov 3, 2011, 2:12:05 AM11/3/11
to vim...@googlegroups.com

I don't know. Maybe nothing: Vim in Windows console uses "cooked" input
IIRC, and that puts it more at the mercy of the DOS-like keyboard driver
than if it used "raw" input; but OTOH (IIUC), "raw" input would read
AaZzQqWwMm incorrectly on AZERTY keyboards, YyZz and maybe Ww on QWERTZ
keyboards, and practically everything on Dvorak keyboards, not to
mention non-Latin keyboards. But maybe I don't UC.

See also :help win32-problems (I'm not sure how applicable these are to
Windows NT / XP / Vista / 7).


Best regards,
Tony.
--
We gave you an atomic bomb, what do you want, mermaids?
-- I. I. Rabi to the Atomic Energy Commission

Benjamin R. Haskell

unread,
Nov 3, 2011, 9:29:01 AM11/3/11
to vim...@googlegroups.com
On Wed, 2 Nov 2011, meino....@gmx.de wrote:

> Hi,
>
> the zsh I am using is recoginzing ALT-backspace as "delete one word
> backward", which is very handy.
>
> Unfortunately I have not found a way to map this in a similiar way for
> vim.
>
> How can I map ALT-backspace in vim?

Try using <Esc><BS> as your {lhs}. Works for me under rxvt-unicode
(what I normally use) and uxterm (tested). See the description under:

:help :map-alt-keys

for what's happening.

Most terminal emulators don't by default send what Vim assumes they
will. Default for most terms is to send Alt+{key} as <esc> followed by
{key}, but Vim expects {key} OR'ed with 0x80. Good emulators can be
told to send what Vim expects, and it's possibly a better situation (not
ambiguous between a literal <esc> then {key} and <alt>+{key}), but
frankly, just as often it causes problems (cf. numerous posts about
problems with mapping characters outside of US-ASCII).

--
Best,
Ben

meino....@gmx.de

unread,
Nov 3, 2011, 12:07:47 PM11/3/11
to vim...@googlegroups.com
Tony Mechelynck <antoine.m...@gmail.com> [11-11-03 17:00]:

Hi Tony,

I am running Linux, not windows. Sorry for not mention this...

Best regards,
mcc

Tony Mechelynck

unread,
Nov 5, 2011, 1:43:49 AM11/5/11
to vim...@googlegroups.com
On 03/11/11 17:07, meino....@gmx.de wrote:
> Tony Mechelynck<antoine.m...@gmail.com> [11-11-03 17:00]:

Well, under Linux each different terminal (Linux console, KDE konsole,
gnome-terminal, xterm, mlterm, ...) can react differently, but gvim has
a better grasp of what you type than any of them, because there's one
fewer layer between Vim and your keyboard. For a similar reason it also
gives you better control of what you display (more colours, better
control of: fonts, multi-language texts, cursor shapes, ...). IMHO the
only job for which console Vim is better than the GUI is when displaying
RTL and LTR scripts together in a single file, in a full-bidi terminal
such as mlterm.


Best regards,
Tony.
--
It's odd, and a little unsettling, to reflect upon the fact that
English is the only major language in which "I" is capitalized; in many
other languages "You" is capitalized and the "i" is lower case.
-- Sydney J. Harris

meino....@gmx.de

unread,
Nov 5, 2011, 1:55:53 AM11/5/11
to vim...@googlegroups.com
Tony Mechelynck <antoine.m...@gmail.com> [11-11-05 06:48]:


For me the question remains, whether zsh from which vim is started
recognizes ALT-Backspace well and vim does not... ?!

Best regards,
mcc

Benjamin R. Haskell

unread,
Nov 5, 2011, 12:21:52 PM11/5/11
to vim...@googlegroups.com
On Sat, 5 Nov 2011, Tony Mechelynck wrote:

> Well, under Linux each different terminal (Linux console, KDE konsole,
> gnome-terminal, xterm, mlterm, ...) can react differently, but gvim
> has a better grasp of what you type than any of them, because there's
> one fewer layer between Vim and your keyboard. For a similar reason it
> also gives you better control of what you display (more colours,
> better control of: fonts, multi-language texts, cursor shapes, ...).
> IMHO the only job for which console Vim is better than the GUI is when
> displaying RTL and LTR scripts together in a single file, in a
> full-bidi terminal such as mlterm.

I found mlterm great for just-Arabic, but I could never quite get fonts
set up properly for displaying RTL and LTR simultaneously.

But, you're also leaving out (IMHO the best reason to use console Vim:)
how nice it is to have a consistent UI regardless of whether you're
working locally or on a remote machine. I do most of my work in
terminal emulators, and the fact that Vim behaves exactly the same
whether I've first ssh'ed somewhere else is great. The overhead from
X11 over slightly-unreliable network links is just enough to be
irritating.

--
Best,
Ben

Benjamin R. Haskell

unread,
Nov 5, 2011, 12:24:34 PM11/5/11
to vim...@googlegroups.com, meino....@gmx.de
On Sat, 5 Nov 2011, meino....@gmx.de wrote:

> For me the question remains, whether zsh from which vim is started
> recognizes ALT-Backspace well and vim does not... ?!

Did you try my suggestion? (My mail has been getting spam-listed more
frequently of late -- still trying to figure out why -- not on any
blacklists, AFAIK.)

Try <esc><bs> instead of <m-bs> or <a-bs>.

See:

:help :map-alt-keys

--
Best,
Ben

Benjamin R. Haskell

unread,
Nov 5, 2011, 12:34:07 PM11/5/11
to vim...@googlegroups.com, meino....@gmx.de
On Sat, 5 Nov 2011, Benjamin R. Haskell wrote:

> On Sat, 5 Nov 2011, meino....@gmx.de wrote:
>
>> For me the question remains, whether zsh from which vim is started
>> recognizes ALT-Backspace well and vim does not... ?!
>

Also, more to the point, see what Zsh thinks represents alt+backspace
for you:

(in zsh:)
$ bindkey -L | grep backward-kill-word


For me, that returns:
bindkey "^W" backward-kill-word
bindkey "^[^H" backward-kill-word
bindkey "^[^?" backward-kill-word

Which means that all three of <Ctrl>+<w>, <Alt>+<Delete> (==
<Esc>+<Delete>), and <Alt>+<Backspace> (== <Esc>+<Backspace>) do the
same thing. Maybe your Backspace and Delete are reversed? (Seems
unlikely, because that makes operating in Vim kind of awkward, IMO, so
you'd've probably fixed it already.)

See:

:help :fixdel

--
Best,
Ben

Dotan Cohen

unread,
Nov 5, 2011, 1:56:13 PM11/5/11
to vim...@googlegroups.com
On Wed, Nov 2, 2011 at 07:36, Tony Mechelynck
<antoine.m...@gmail.com> wrote:
> In Normal mode, you should be able to use Shift-Left as a modifier to the d
> (delete) command, to delete [count] words leftwards, or the command daw
> ("delete a word") to delete the word under the cursor (on both sides) and
> the white space on one side of it. See :help text-objects
>

Tony, is there an alternative way to delete the previous word from
Command mode. I often i^w<esc> but if I could save some keystrokes I
would appreciate it. For that matter, what is the keyboard shortcut
for going _back_ one word?

Shift-Left is mapped by default to Previous Tab in Konsole, and I use
that feature often enough to not want to change it. That said, I work
on disparate servers (SSH) so I prefer to learn the 'right' VIM way as
opposed to remapping when I can.

Thanks.

--
Dotan Cohen

http://gibberish.co.il
http://what-is-what.com

Tony Mechelynck

unread,
Nov 5, 2011, 3:01:48 PM11/5/11
to vim...@googlegroups.com, Benjamin R. Haskell

I guess the reason I left this out is that I never work on a remote machine.

Best regards,
Tony.
--
Job Placement, n.:
Telling your boss what he can do with your job.

Tony Mechelynck

unread,
Nov 5, 2011, 3:07:43 PM11/5/11
to vim...@googlegroups.com, Dotan Cohen
On 05/11/11 18:56, Dotan Cohen wrote:
> On Wed, Nov 2, 2011 at 07:36, Tony Mechelynck
> <antoine.m...@gmail.com> wrote:
>> In Normal mode, you should be able to use Shift-Left as a modifier to the d
>> (delete) command, to delete [count] words leftwards, or the command daw
>> ("delete a word") to delete the word under the cursor (on both sides) and
>> the white space on one side of it. See :help text-objects
>>
>
> Tony, is there an alternative way to delete the previous word from
> Command mode. I often i^w<esc> but if I could save some keystrokes I
> would appreciate it. For that matter, what is the keyboard shortcut
> for going _back_ one word?

Shift-Left, as I said. Or, by looking it up (by ":help <S-Left>" without
the quotes), you would have found b as a synonym.

>
> Shift-Left is mapped by default to Previous Tab in Konsole, and I use
> that feature often enough to not want to change it. That said, I work
> on disparate servers (SSH) so I prefer to learn the 'right' VIM way as
> opposed to remapping when I can.
>
> Thanks.
>

The rightest of the "right" Vim ways is to RTFM.


Best regards,
Tony.
--
hundred-and-one symptoms of being an internet addict:

211. Your husband leaves you...taking the computer with him and you
call him crying, and beg him to bring the computer back.

Dotan Cohen

unread,
Nov 5, 2011, 3:59:58 PM11/5/11
to Tony Mechelynck, vim...@googlegroups.com
On Sat, Nov 5, 2011 at 21:07, Tony Mechelynck
<antoine.m...@gmail.com> wrote:
>> Tony, is there an alternative way to delete the previous word from
>> Command mode. I often i^w<esc>   but if I could save some keystrokes I
>> would appreciate it. For that matter, what is the keyboard shortcut
>> for going _back_ one word?
>
> Shift-Left, as I said. Or, by looking it up (by ":help <S-Left>" without the
> quotes), you would have found b as a synonym.
>

I did not realize would be how to look it up. The VIM help pages are
very flexible in the input they will accept! Thanks.


> The rightest of the "right" Vim ways is to RTFM.
>

Ouch, I deserved that!

Thanks, Tony. Have a great week!

meino....@gmx.de

unread,
Nov 6, 2011, 1:43:34 AM11/6/11
to vim...@googlegroups.com
Benjamin R. Haskell <v...@benizi.com> [11-11-05 17:36]:
> --
> 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
>

Hi Benjamin,

I want to summarize, what I have found:
I am using vim under linux -- gvim is used very very very seldom.
The TERM variable is set to:xterm-256color.
I am using utf-8.

First experiment:
Using ALT-BS under zsh works. bindkey -L | grep backward-kill-word
gives me:


bindkey "^W" backward-kill-word
bindkey "^[^H" backward-kill-word
bindkey "^[^?" backward-kill-word

which seems to be the same as what you see with your zsh...

Second experiment:
Opening vim from this zsh/terminal and
doing CTRL-k ALT-Backspace in insert mode gives: <nothing>
Same goes for CTRL-v
No trying to insert ALT-backspace on the commandline of vim:
This puts me back to the buffer, leaving the commandline.
=> There is "something", vim recognizing, otherwise it stay
in the commandline. But it seems not enough to be recognized
as a valid keystroke.

Now trying <ESC><BS> as keystrokes, same experiments:
In insert mode, the <ESC> key puts me back to command mode
instantly.
Commandline: Same scenario.

In /etc/inputrc (this is the only inputrcon this system) there is set:

set input-meta on # Enable Meta input with eighth bit set
set meta-flag on # Synonym for the above
set convert-meta off # Do NOT strip the eighth bit
set output-meta on # Enable Meta output with eighth bit set

Regarding to the ctrl-v- and ctrl-k-experiments there would be no
hope to get any mapping with ALT-backspace working.
From what can be acchieved with zsh and regarding to the inputrc
it /should/ work nevertheless.

Finally I put a
nmap <esc><bs> db
into the .vimrc

and...it works! After all I dont know why.

Final thing I want to fix (help appreciated ;)
is this:
When I put a "imap <esc><bs> :normal db<cr>"
into .vimrc and restart vim to execute ALT-backspace
in input mode it prints :normal db at the cursor
position and jumps to the next line.
Is there a way to get it working in input mode also?

Best regards and have a nice sunday!
mcc

Reply all
Reply to author
Forward
0 new messages