Vim Tips Wiki
No edit summary
Tag: sourceedit
(4 intermediate revisions by 2 users not shown)
Line 6: Line 6:
 
|complexity=basic
 
|complexity=basic
 
|author=Robert Ames
 
|author=Robert Ames
|version=5.7
+
|version=6.0
 
|rating=18/14
 
|rating=18/14
 
|category1=Usage
 
|category1=Usage
 
|category2=
 
|category2=
 
}}
 
}}
  +
In insert mode, pressing Ctrl-W deletes the previous word ({{help|word}}). If a non-Vim method is wanted, the following mapping can be used in gvim to allow Ctrl-Backspace to be used instead of Ctrl-W:
Put this in your vimrc and then you'll be able to type Control-Backspace to delete the previous word.
 
 
 
<pre>
 
<pre>
" map control-backspace to delete the previous word
+
" Map Ctrl-Backspace to delete the previous word in insert mode.
 
:imap <C-BS> <C-W>
 
:imap <C-BS> <C-W>
  +
</pre>
  +
  +
If the mapping is always wanted, place the above in your [[vimrc]].
  +
  +
By default, Ctrl-W only deletes previous words in the text entered after last starting insert mode, and stops deleting text at the beginning of a line. The [[backspace and delete problems|'backspace' option]] can be set to control what is wanted. For example, the following causes Ctrl-W to always delete the previous word:
  +
<pre>
  +
:set backspace=indent,eol,start
 
</pre>
 
</pre>
   
Line 25: Line 31:
   
 
==Comments==
 
==Comments==
  +
Mapping Ctrl-Backspace does not work in terminal Vim. Following is a workaround.
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)
 
  +
<pre>
  +
noremap! <C-BS> <C-w>
  +
noremap! <C-h> <C-w>
  +
</pre>
  +
----
  +
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 07:50, 9 September 2015

Tip 189 Printable Monobook Previous Next

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


In insert mode, pressing Ctrl-W deletes the previous word (:help word). If a non-Vim method is wanted, the following mapping can be used in gvim to allow Ctrl-Backspace to be used instead of Ctrl-W:

" Map Ctrl-Backspace to delete the previous word in insert mode.
:imap <C-BS> <C-W>

If the mapping is always wanted, place the above in your vimrc.

By default, Ctrl-W only deletes previous words in the text entered after last starting insert mode, and stops deleting text at the beginning of a line. The 'backspace' option can be set to control what is wanted. For example, the following causes Ctrl-W to always delete the previous word:

:set backspace=indent,eol,start

References

See also

Comments

Mapping Ctrl-Backspace does not work in terminal Vim. Following is a workaround.

noremap! <C-BS> <C-w>
noremap! <C-h> <C-w>

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