1

I am using NeoVim with Tmux on an Ubuntu on Windows setup. I have bound neovim's clipboard to the system clipboard by using : set clipboard+=unnamedplus and further configuration inside tmux.

So far, everything works just fine, except for a detail that bothers me.

As of now, when I delete a character in insert mode with DEL, it works just fine. However, when I do that in normal mode, the character is deleted but also copied to the clipboard.

Why is there this difference ? Is there a way to disable this behaviour ?

NOTE: I've also tried this on a Xubuntu machine running the same tmux config and vim.gtk, and I have the same issue

2

One quick fix I can think of is remapping the del key so it will use _ register. so if you just add nnoremap <Del> "_x into your $MYVIMRC init.nvim for neovim or ~/.vimrc for standard vim it should just do what you ask

  • while this solution keeps my registry alone, it also moves my cursor 1 character to the right. Is there a way to avoid this and keep the current position ? – Aserre Nov 29 '17 at 0:25
  • @Aserre can you please describe what do you mean it moves cursor to the right ? – nikoss Nov 29 '17 at 0:42
  • Because for me it seems its just replacing the deleted character would you like to move the cursor left afterwards ? @Aserre – nikoss Nov 29 '17 at 0:46
  • it moves the cursor to the right at the moment, i.e. if you have DEMOTEXT and the cursor is under D, pressing DEL will show EMOTEXT, but cursor will be under M instead of E (which is the insert mode behaviour : cursor doesn't move, only text does) – Aserre Nov 29 '17 at 0:52
  • 1
    Well, adding the <Left> does the trick for me. Thanks ! – Aserre Nov 29 '17 at 1:06
3

This is because <del> is equivalent to x, or dl, which not only delete, but also yank to the unnamed register by default. From :h <del>

["x]<Del>   or                  *<Del>* *x* *dl*
["x]x           Delete [count] characters under and after the cursor
            [into register x] (not |linewise|).  Does the same as
            "dl".
            The <Del> key does not take a [count].  Instead, it
            deletes the last character of the count.
            See |:fixdel| if the <Del> key does not do what you
            want.  See |'whichwrap'| for deleting a line break
            (join lines).  {Vi does not support <Del>}

The fix is really simple. Just add

nnoremap <del> "_x

to your .vimrc file. This will make it delete into the black-hole register (like /dev/null on linux) and leave your other registers the same.

  • while this solution keeps my registry alone, it also moves my cursor 1 character to the right. Is there a way to avoid this and keep the current position ? – Aserre Nov 29 '17 at 0:25

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.