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?
Asked
Active
Viewed 6,359 times
11

Brian Tompsett - 汤莱恩
- 5,753
- 72
- 57
- 129

ma11hew28
- 121,420
- 116
- 450
- 651
3 Answers
24
x deletes to the right, X deletes to the left
This may be useful for you: Vim Cheat Sheet

Steven Don
- 2,436
- 15
- 14
-
Bleh, that file no longer exists. I've posted a copy of the contents: http://www.shdon.com/blog/2013/11/27/vim-command-cheat-sheet – Steven Don Nov 27 '13 at 01:16
6
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.

Xavier T.
- 40,509
- 10
- 68
- 97
-
Thanks. FYI, `x` is faster than `r, Space` and does exactly the same thing. – ma11hew28 Jun 29 '11 at 12:57
-
2
-
Oh, oops! :-) Now, I get it. Only took me a few years. ;-) Thank you! :-) – ma11hew28 Sep 14 '18 at 19:29
0
Map it to g space or your preferred shortcut in your vimrc. This works in command mode
nnoremap <silent> g<Space> i<Space><Esc>
if you want to perform a move action after space, append the move action after Esc. e.g. below moves mouse to the left after space
nnoremap <silent> g<Space> i<Space><Esc>j

Anthony Awuley
- 3,455
- 30
- 20