Vim#
Installation#
Debian#
$ sudo apt-get install vim
RedHat#
$ sudo dnf install vim
Configuration#
~/.vimrc#
" Create silently backup directory
" `~/.vim/backups` will prevent swap and backup file to be either in the
" current directory (bad for version control system) or in /tmp (bad for
" security on shared system)
silent !mkdir -p ~/.vim/backups
" Set the backup directory to `~/.vim/backups`
set backupdir=~/.vim/backups
" Set the swap file directory to `~/.vim/backups`
set directory=~/.vim/backups
" Set the undo directory to `~/.vim/backups`
set undodir=~/.vim/backups
" Enable undo history file
set undofile
" Set the character encoding to utf-8.
set encoding=utf-8
" Insert spaces instead of <Tab>.
set expandtab
" Insert 4 spaces to make a <Tab>.
set tabstop=4
" Always display the status line.
set laststatus=2
" Show the line and column number of the cursor position.
set ruler
" Enable syntax highlighting
set syntax=on
syntax on
set background=dark
" Highligh column 80 and 100
set colorcolumn=80,100
" *.sls is the extention for SaltStack state files (yaml)
autocmd BufRead,BufNewFile *.sls setfiletype yaml
autocmd FileType make set noexpandtab shiftwidth=4 softtabstop=0
" Start NERDTree and put the cursor back in the other window.
autocmd VimEnter * NERDTree | wincmd p
" Exit Vim if NERDTree is the only window remaining in the only tab.
autocmd BufEnter * if tabpagenr('$') == 1 && winnr('$') == 1 && exists('b:NERDTree') && b:NERDTree.isTabTree() | quit | endif
" Close the tab if NERDTree is the only window remaining in it.
" Vim < 9.0.907
"autocmd BufEnter * if winnr('$') == 1 && exists('b:NERDTree') && b:NERDTree.isTabTree() | quit | endif
" Vim >= 9.0.907
" Thanks to Gray Johnson (https://groups.google.com/g/vim_dev/c/Cw8McBH6DDM/m/-O7UhK_OAgAJ)
autocmd BufEnter * if winnr('$') == 1 && exists('b:NERDTree') && b:NERDTree.isTabTree() | call feedkeys(":quit\<CR>:\<BS>") | endif
" Open the existing NERDTree on each new tab.
autocmd BufWinEnter * if getcmdwintype() == '' && &buftype != 'quickfix' | silent NERDTreeMirror | endif
" Hide some stuff from the NERDTree tree
let NERDTreeIgnore=['^__pycache__$[[dir]]', '\.egg-info$[[dir]]']
"let g:NERDTreeNodeDelimiter = "\u00a0"
"let g:NERDTreeFileLines = 1
" Run Flake8 check every time a Python file is written
autocmd BufWritePost *.py call flake8#Flake8()
" Exit Vim if only a quickfix window remain
autocmd BufEnter * if tabpagenr('$') == 1 && winnr('$') == 1 && &buftype == 'quickfix' | quit | endif
Alternatives#
$ sudo update-alternatives --set editor /usr/bin/vim.basic