I use vim as my standard editor for editing files at the command prompt. Almost all Linux based operating systems install it by default. When you first install the OS there is no extra programs to install in order to start editing files — it’s ready to rock out of the box.
That said, some Linux distributions ship with a very stripped back default configuration for vim and doing simple things like middle-click cut-n-paste with the mouse may not work when shelled into a new host from a remote location. This is because vim’s visual mode is not turned on.
It can be annoying to set it continuously so we can make it a default. We do this by adding/modifying the following lines to the default vim configuration file located at /etc/vim/vimrc (root permissions required):
set mouse=v
If root/sudo/doas access is not available this can also be added to the user level vim configuration file in the home directory (~/.vimrc).
More information can be found about mouse settings by typing :help mouse in vim.
I typically will add a few more setings as well. I like syntax highlighting to be turned on:
syntax on
wildmenu provides command completion inside vim:
set wildmenu
Showing the column and row numbers of the cursor is helpful:
set ruler
Using vim in a dark mode terminal can be difficult to read so vim has a way to brighten the default syntax highlighting colours:
set bg=dark
Setting tab stops is helpful:
set tabstop=3 set softtabstop=3 set shiftwidth=3
Turn on auto-indenting:
set autoindent
Turn on search highlighting (i.e. when you search all matches will be highlighted in the doc):
set hlsearch
You can also make vim show line number:
set number
I don’t have that one default to on though.
Putting this all together to ease cut-n-paste:
set mouse=v set wildmenu syntax on set ruler "set number set tabstop=3 set softtabstop=3 set shiftwidth=3 set autoindent set hlsearch
The use of " in a vimrc file is a comment marker. Remove that character if you really want to try leading line numbers.
Thanks for reading.