Fix vim right click paste not working
The issue is using putty ssh to a linux host ,let’s say Debian 10 , then use command VIM file
to open a file , then type i
to change to insert mode , then use right-click to paste something into vim , instead of pasting vim is changed to (insert) VISUAL
mode.
Workarounds
-
For current user only
Normally this issue happens when you don’t have
~/.vimrc
file , so you can create one using below command, then re-open file usingvim
touch ~/.vimrc
-
System wide
Above one fix the issue for current user only , to fix it in system-wide,uncomment below line from
/etc/vim/vimrc
let g:skip_defaults_vim = 1
This will prevent vim sourcing file
$VIMRUNTIME/defaults.vim
if you don’t have~/.vimrc
file -
Temporary workaround
The reason is option
set mouse=a
is enabled , so you can fix it temporarily using below command inside vim::set mouse=
Or use keyboard shortcut:
Shift+Ins(ert)
Wait ,but why
As mentioned above , right-click pasting not working is caused due to set mouse=a
was enabled ,but how did it been enabled.
:help defaults.vim
You will get below after inputting above command in VIM
If Vim is started normally and no user vimrc file is found, the
$VIMRUNTIME/defaults.vim script is loaded
And for $VIMRUNTIME/defaults.vim
,it points to /usr/share/vim/vim81/defaults.vim
root@localhost:~# grep mouse /usr/share/vim/vim81/defaults.vim
" text scroll if you mouse-click near the start or end of the window.
" In many terminal emulators the mouse works just fine. By enabling it you
" can position the cursor, Visually select and scroll with the mouse.
if has('mouse')
set mouse=a
See, we found it. And that’s why we can fix this issue in system-wide by modifying file /etc/vim/vimrc