Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vim deleting backward tricks

Tags:

vim

People also ask

How do I forward a vim delete?

Its the fn key and backspace ( <X) ) or alt and backspace ( <X) ). I think what TK is getting at is a way to forward delete without breaking hand position on home row, in the same quick way you can backspace with Ctrl-H. It's an important capability for maintaining high editing speed and minimizing repetitive strain.

How do I delete a previous character in Vim?

Shift + x is instead the appropriate command because was meant for that: Shift + x delete the previous character like Shift + p paste in the previous column.


In general, d<motion> will delete from current position to ending position after <motion>. This means that:

  1. d<leftArrow> will delete current and left character
  2. d$ will delete from current position to end of line
  3. d^ will delete from current backward to first non-white-space character
  4. d0 will delete from current backward to beginning of line
  5. dw deletes current to end of current word (including trailing space)
  6. db deletes current to beginning of current word

Read this to learn all the things you can combine with the 'd' command.


I have been in this scenario many times. I want to get rid of all the spaces in line 10 so it would join with line 9 after the comma.

enter image description here

This is basically a simple line join in VIM.

kJ does the trick (watch below)

Vim Join Lines


To answer point #3, diw and daw are excellent.


In insert mode:

  • ^w
  • ^u
  • can't answer out of my head ;-)

Otherwise:

  • dw
  • v0x
  • can't answer out of my head ;-)

In command mode:

  1. bdw, back delete word.
  2. d^ (to the first non-blank), d0 (to the first character)
  3. BdW (go to first whitespace delete to next whitespace)

(Community wiki, feel free to hack.)