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
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.
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
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
> 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
Hi Tony,
I am running Linux, not windows. Sorry for not mention this...
Best regards,
mcc
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
For me the question remains, whether zsh from which vim is started
recognizes ALT-Backspace well and vim does not... ?!
Best regards,
mcc
> 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
> 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
> 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
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
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.
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.
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!
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