I put key mapping like this nnoremap <space>d "_d
in my .vimrc
, so I can delete text more comfortable. But when I in visual mode or visual block mode, the cursor will advance one more column, and delete more than I wanted.
I know I can change <space>
to other key, like <alt>
, and it works fine. But <space>
is the most easily to pressed, I still want to use it. Is there any way to solve this problem? Thank you.
Just add the same mapping in Visual mode as well:
nnoremap <space>d "_d
xnoremap <space>d "_d
You can also use a simple noremap
, which maps in Normal, Visual and Selection mode, just in that case you might want to undo the mapping in Selection mode (which is probably inappropriate for that mode):
noremap <space>d "_d
sunmap <space>d
-
2There is also
xnoremap
which will map for visual-mode only (no select) – Peter Rincker Sep 16 '19 at 21:39 -
2And if you really like mapping prefixes, consider using mapleader and <leader> – D. Ben Knoble♦ Sep 16 '19 at 22:47
-
1
-
@PeterRincker Ah yes,
xnoremap
is what I had in mind! Updated the answer. Thanks! – filbranden♦ Sep 17 '19 at 7:13