How to backspace from command mode in Vim?
If I'm in command mod开发者_Go百科e, 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?
x deletes to the right, X deletes to the left
This may be useful for you: Vim Cheat Sheet
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.
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
精彩评论