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?
How to backspace from command mode in Vim?
x deletes to the right, X deletes to the left
This may be useful for you: Vim Cheat Sheet
Bleh, that file no longer exists. I've posted a copy of the contents: shdon.com/blog/2013/11/27/vim-command-cheat-sheet –
Ceilidh
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.
Thanks. FYI,
x
is faster than r, Space
and does exactly the same thing. –
Housework @MattDiPasquale : see my example –
Bottomless
Oh, oops! :-) Now, I get it. Only took me a few years. ;-) Thank you! :-) –
Housework
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
© 2022 - 2024 — McMap. All rights reserved.