How to backspace from command mode in Vim?
Asked Answered
H

3

11

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?

Housework answered 29/6, 2011 at 11:47 Comment(0)
C
24

x deletes to the right, X deletes to the left

This may be useful for you: Vim Cheat Sheet

Ceilidh answered 29/6, 2011 at 11:50 Comment(1)
Bleh, that file no longer exists. I've posted a copy of the contents: shdon.com/blog/2013/11/27/vim-command-cheat-sheetCeilidh
B
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.

Bottomless answered 29/6, 2011 at 12:21 Comment(3)
Thanks. FYI, x is faster than r, Space and does exactly the same thing.Housework
@MattDiPasquale : see my exampleBottomless
Oh, oops! :-) Now, I get it. Only took me a few years. ;-) Thank you! :-)Housework
D
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
Dulcy answered 14/9, 2018 at 18:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.