Vim Tips Wiki
(Uploaded by JohnBot from a locally edited file)
No edit summary
(7 intermediate revisions by 5 users not shown)
Line 1: Line 1:
{{review}}
 
 
{{TipImported
 
{{TipImported
 
|id=189
 
|id=189
Line 9: Line 8:
 
|version=5.7
 
|version=5.7
 
|rating=18/14
 
|rating=18/14
  +
|category1=Usage
  +
|category2=
 
}}
 
}}
 
Put this in your vimrc and then you'll be able to type Control-Backspace to delete the previous word.
 
Put this in your vimrc and then you'll be able to type Control-Backspace to delete the previous word.
Line 14: Line 15:
 
<pre>
 
<pre>
 
" map control-backspace to delete the previous word
 
" map control-backspace to delete the previous word
:imap &lt;C-BS&gt; &lt;Esc&gt;vBc
+
:imap <C-BS> <C-W>
 
</pre>
 
</pre>
   
==Comments==
+
==References==
  +
*{{help|i_CTRL-W}}
Vim has a built-in keyboard command for deleting the previous word while in Insert mode: Ctrl-W, which works the same way it does on the command line of your favorite shell (bash, right? (-;)
 
   
So this also works:
+
==See also==
  +
*{{help|i_CTRL-U}}
   
  +
==Comments==
:imap &lt;C-BS&gt; &lt;C-W&gt;
 
  +
In my version of Linux, this works properly in gvim, but not in terminal-vim. My keyboard mapping doesn't have a control-backspace. --[[User:Kanliot|Kanliot]] 08:38, May 28, 2012 (UTC)
 
----
 
In ''insert'' mode only, &lt;Ctrl-W&gt; will backward delete one word at a time until the cursor reaches the beginning of the inserted text for the current line. Also in INSERT &lt;Ctrl-D&gt; will backtab autoindents and &lt;Ctrl-U&gt; will delete all inserted text on the current line. However, nobody uses these vi feature in Vim since Vim has more general solutions for these needs.
 
   
 
----
 
----
  +
There are some issues with <C-w>. For example it considers the insert mode's point of entry as a word boundary. Also, in readline <C-w> usually means to kill the previous WORD. There is a way to make it more readline-ish:
  +
<pre>
  +
inoremap <C-w> <C-\><C-o>dB
  +
inoremap <C-BS> <C-\><C-o>db
  +
</pre>

Revision as of 00:46, 3 November 2013

Tip 189 Printable Monobook Previous Next

created January 2, 2002 · complexity basic · author Robert Ames · version 5.7


Put this in your vimrc and then you'll be able to type Control-Backspace to delete the previous word.

" map control-backspace to delete the previous word
:imap <C-BS> <C-W>

References

See also

Comments

In my version of Linux, this works properly in gvim, but not in terminal-vim. My keyboard mapping doesn't have a control-backspace. --Kanliot 08:38, May 28, 2012 (UTC)


There are some issues with <C-w>. For example it considers the insert mode's point of entry as a word boundary. Also, in readline <C-w> usually means to kill the previous WORD. There is a way to make it more readline-ish:

inoremap <C-w> <C-\><C-o>dB
inoremap <C-BS> <C-\><C-o>db