Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to backspace from command mode in Vim?

Tags:

vim

backspace

If I'm in command mode, how do I backspace? Hitting the delete key on my Macbook just moves the cursor to the left one space. The fastest way I know to do this is h, x, but is there a better way, maybe with one key?

like image 719
ma11hew28 Avatar asked Jun 29 '11 11:06

ma11hew28


People also ask

What does Ctrl d do in vim?

You will see list of commands that matches characters in front of the cursor by pressing CTRL-D in the command mode. For example, if you pressed :se in normal mode, then pressed CTRL-D , you will see list of commands that start with se .

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 character in vim?

To delete one character, position the cursor over the character to be deleted and type x . The x command also deletes the space the character occupied—when a letter is removed from the middle of a word, the remaining letters will close up, leaving no gap.


2 Answers

x deletes to the right, X deletes to the left

This may be useful for you: Vim Cheat Sheet

like image 108
Steven Don Avatar answered Oct 05 '22 18:10

Steven Don


In command mode, r might also be useful in some circumstances. It allows you to replace a single character under the cursor.

Typically I often use rSpace, to remove a character on a line without changing the indentation or alignement.

For example if you have the following code :

var anotherOne   = NULL;
var short1       = NULL;
var veryLongLong = NULL;

by using rSpace on '1', your now have :

var anotherOne   = NULL;
var short        = NULL;
var veryLongLong = NULL;

instead of

var anotherOne   = NULL;
var short       = NULL;
var veryLongLong = NULL;

In the latter case, you must switch to insert mode to add another space.

like image 44
Xavier T. Avatar answered Oct 05 '22 17:10

Xavier T.