Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

alt+backspace to delete words in vim

How can I remap alt+backspace to delete words like native *NIX text manipulation? I checked out this thread: Using alt+backspace key in vim command line to delete by words

And the examples like: cmap <a-bs> <c-w> and :imap <A-BS> <C-W> don't do anything. And the accepted answer was actually to not even remap it, but to use ctrl+w. Since VIM's alt+backspace doesn't do anything I'd rather remap it to something I'm used to.

I'm using terminal based VIM (specifically in iTerm)

like image 702
Oscar Godson Avatar asked Jul 25 '12 22:07

Oscar Godson


2 Answers

The Alt/Meta key is problematic in Vim and most terminals, see this answer of mine for an overview of the situation (the situation is the same for Meta and Alt).

In short, Vim doesn't receive Alt at all: hitting Alt+Backspace is exactly the same as hitting Backspace.

Anyway, it will be better for you in the long term to learn and get accustomed to Vim's default key-mappings.

like image 58
romainl Avatar answered Oct 16 '22 18:10

romainl


On macOS with iTerm2, I have the option keys mapped to +Esc (like many people), and I found that pressing Option+Backspace actually was interpreted by vim as an Escape press followed by a Backspace press, so the following binding worked perfectly for me; I recommend trying it even if your configuration is different than mine, just in case it works for you!

:imap <Esc><BS> <C-w>
like image 22
Christopher Shroba Avatar answered Oct 16 '22 17:10

Christopher Shroba