I really didn't care about formatting until I started learning to program in python.
Now I have to.
Here are some notes on going beyond the defaults with the vim editor.
I generally use a .vimrc dotfile for both CLI and GUI versions of vim. Some people like to use .gvimrc for directives that only apply to the GUI.
A good color scheme can improve productivity in vim, just as in any other editor. Several built-in themes are available, like slate, but I prefer Josh Dick's onedark.vim (inspired by the Atom editor's default OneDark theme).
Plugins can provide vim with useful features not in the base package.
A good minimalist plugin manager is June Gunn's vim-plug. After updating .vimrc with each plugin's GitHub HTTPS URL (or the significant part after "https://github.com"), run :PlugInstall
to install the plugins. In some cases further tweaking of .vimrc or other configuration files may be required.
Customize vim's behavior with a .vimrc file, like this one:
" My vimrc
set nocompatible
filetype on
filetype indent on
set number
set ignorecase
set tabstop=4
set shiftwidth=4
set softtabstop=4
set expandtab
set backspace=indent,eol,start
set nobackup
set encoding=utf-8
set fileencodings=ucs-bom,utf-8
set formatoptions=1
set fileformat=unix
syntax on
colorscheme slate
Here's what it looks like with the onedark color scheme, a nice font, and some plugins loaded:
set nocompatible
filetype on
filetype indent on
set number
set ignorecase
set tabstop=4
set shiftwidth=4
set softtabstop=4
set expandtab
set autoindent
set fileformat=unix
set backspace=indent,eol,start
set nobackup
set encoding=utf-8
set fileencodings=ucs-bom,utf-8
set formatoptions=1
set guifont=Fira\ Code\ Retina\ 12
set colorcolumn=80
" netrw (vim file explorer) options
let g:netrw_banner = 0
let g:netrw_liststyle = 2
let g:netrw_winsize = 25
let g:netrw_list_hide='\(^\|\s\s\)\zs\.\S\+'
" Setup plugin manager (vim-plug)
call plug#begin()
" OneDark theme
Plug 'joshdick/onedark.vim'
" Airline fonts
Plug 'vim-airline/vim-airline'
" ALE linting
Plug 'dense-analysis/ale'
" Better indenting for python
Plug 'vim-scripts/indentpython.vim'
call plug#end()
" vim airline options
let g:airline_powerline_fonts = 1
" load the onedark theme
syntax on
colorscheme onedark
Status bar plugins like vim-airline (and its inspiration, powerline) may be a hard sell to minimalists, especially because they require special fonts (sudo apt install fonts-powerline
), but I'm finding it useful. ALE, the "Asynchronous Lint Engine", integrates linting into vim.
I used to load vim-polyglot here, until I saw it display commas as pipes inside csv files: very disconcerting! After finally reading its doc carefully I realized I really didn't need it... yet.
Sort of looks like Sublime Text, only in a terminal.
Finally, I recently added the NERDTree plugin for a file explorer that's a bit more fun than the native netrw.
filetype on
filetype indent on
set number
set ignorecase
set tabstop=4
set shiftwidth=4
set softtabstop=4
set expandtab
set autoindent
set fileformat=unix
set backspace=indent,eol,start
set nobackup
set encoding=utf-8
set fileencodings=ucs-bom,utf-8
set formatoptions=1
set guifont=Fira\ Code\ Retina\ 12
set colorcolumn=80
set noerrorbells
set vb t_vb=
" netrw (vim file explorer) options
let g:netrw_banner = 0
let g:netrw_liststyle = 2
let g:netrw_winsize = 25
let g:netrw_list_hide='\(^\|\s\s\)\zs\.\S\+'
" Setup plugin manager (vim-plug)
call plug#begin()
" OneDark theme
Plug 'joshdick/onedark.vim'
" Airline fonts
Plug 'vim-airline/vim-airline'
" ALE linting
Plug 'dense-analysis/ale'
" Better indenting for python
Plug 'vim-scripts/indentpython.vim'
" NERDTree
Plug 'preservim/nerdtree'
call plug#end()
" vim airline options
let g:airline_powerline_fonts = 1
" load the onedark theme
syntax on
colorscheme onedark
" For neovim
set laststatus=2
" Start NERDTree if no file specified
autocmd StdinReadPre * let s:std_in=1
autocmd VimEnter * if argc() == 0 && !exists('s:std_in') | NERDTree | endif
" Map shortcuts for NERDTree
nnoremap <C-n> :NERDTree<CR>
nnoremap <C-t> :NERDTreeToggle<CR>
On Windows vimrc is supposed to be stored under %USERPROFILE%\vimfiles as vimrc (no leading dots or underscores). But if you're also using Git for Windows (GfW), put vimrc in the root of %USERPROFILE% as _vimrc (with the leading underscore). You'll find that vim in GfW automatically saves _viminfo there are well.
On most Windows systems %USERPROFILE% maps to the root of the user's home folder, like "C:\Users\myuser". The full path to vimrc would then be like "C:\Users\myuser\ _vimrc". If %USERPROFILE% is mapped to a weird place by a group policy (like an old server file share that no longer exists), you can set up a custom User environment variable by opening a Command Prompt and typing setx HOME "C:\Users\myuser"
. The editor will then be able to find your _vimrc and vimfiles under "C:\Users\myuser".
Josh Dick. "onedark.vim". GitHub, https://github.com/joshdick/onedark.vim.
Adam Stankiewicz. "vim polyglot". GitHub, https://github.com/sheerun/vim-polyglot.
Vim Airline Project. "vim airline". GitHub, https://github.com/vim-airline/vim-airline.
June Gunn. "vim-plug". GitHub, https://github.com/junegunn/vim-plug.
Daniel Miessler. "Learn Vim for the Last Time: A Tutorial and Primer". Daniel Miessler, 6 May 2021, https://danielmiessler.com/study/vim/.
Heiker Curiel. "Using netrw, vim's builtin file exlorer". Devlog, 10 January 2021, https://vonheikemen.github.io/devlog/tools/using-netrw-vim-builtin-file-explorer/.
Ricardo Girardi. "Top five Vim plugins for sysadmins". Red Hat Enable Sysadmin, 16 October 2020, https://www.redhat.com/sysadmin/five-vim-plugins.
Carlo Teubner. "Vim help files". vim help, https://vimhelp.org/.
Christian Brabant. "VIM FAQ". vim help, https://vimhelp.org/vim_faq.txt.html.
Arnold Robbins. vi Editor Pocket Reference. O'Reilly, 1999.