The officially official Devuan Forum!

You are not logged in.

#1 Today 16:08:22

kaiyel
Member
Registered: 2019-10-16
Posts: 35  

HOWTO : Disable mouse cursor movement inside vim document

When editing in "vi" it is common practice for me to hit "i"nsert, highlight a block of text, and click the middle-mouse button to paste the selected text at the insert position.  That worked well during my years in the RedHat ecosystem.  Transitioning to Devuan, I discovered the default vim installation intercepted mouse clicks to implement cursor movement inside the document.  Clicking to highlight a block of text moved the cursor from the original insert point and made a mess of the document on paste.

My quick-n-dirty solution was to delete the "defaults.vim" from "/usr/share/vim/vimNN/" to reset to a barebones vim configuration that did not set a mouse mode.  But that was not a robust solutions that survived updates, so I made it a goal to dig deeper and my solution evolved to create a "/etc/vim/vimrc.local" with the following contents :

" Tell Devuan to stop overriding this file with defaults.vim
let g:skip_defaults_vim = 1

" Eliminate source of RCE/malicious text file security/resource exploits
set nomodeline

" Prevent startup scripts from executing shell code or writing files
set secure

" Prevent leaking sensitive data into local directories via swap files
set noswapfile

" Turn syntax highlighting back on safely
if has("syntax")
  syntax on
endif

" Prevent vim from intercepting mouse events handled by X11/Wayland
if has("mouse")
  set mouse=
endif

" Global 2-space tab configuration
" Use :retab in vim to replace tabs with spaces in existing documents
set tabstop=2
set shiftwidth=2
set expandtab

" Core essential editing behaviors stripped by skipping defaults
" hlsearch:   Highlight all matches when searching text
" incsearch:  Show search matches instantly as you type
" backspace:  Make the Backspace key work normally over line breaks
" scrolloff:  Show context above/below cursor when scrolling
" nowrap:     Prevent line wrap with an infinitely long right edge
set hlsearch
set incsearch
set backspace=indent,eol,start
set scrolloff=3
set nowrap

If anyone has had similar experience and tweaked "/etc/vim/vimrc.local" further for safety, security, or efficiency please chime in.

This guide was very helpful to me discerning the settings : https://danmc.net/posts/2019/vim-config-1/

Cheers,
--K

Offline

Board footer