0

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.

1

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
  • 2
    There is also xnoremap which will map for visual-mode only (no select) – Peter Rincker Sep 16 at 21:39
  • 2
    And if you really like mapping prefixes, consider using mapleader and <leader> – D. Ben Knoble Sep 16 at 22:47
  • 1
    Thanks for advises. – Shan-Hung Hsu Sep 17 at 4:43
  • @PeterRincker Ah yes, xnoremap is what I had in mind! Updated the answer. Thanks! – filbranden Sep 17 at 7:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.