vim
Content-sensitive text editing using vim .
2022-09-01 Raspbian buster-bullseye, Ubuntu 20.04-22.04, macOS 12.1-15.5
Plain example
Adorned example
Debian OS
graham:~ sudo apt install vim
Often vim-tiny (or nothing) is pre-installed. Replace it!
graham:~ sudo vi /etc/vim/vimrc.local
/etc/vim/vimrc.local
new file
" status line
augroup use_status_line " indivisible unit
autocmd!
set noruler " replaced with status line
set statusline= " start afresh
set statusline+=\ %F\ %M\ %Y\ %R " left side: file name, type, etc
set statusline+=%= " divider, if needed
set statusline+=\ %c,%l\ %L/%02p%% " right side: col,row, #lines
set laststatus=2 " always show status line
highlight StatusLine term=bold cterm=bold ctermbg=159 guibg=PaleTurquoise1
augroup END
" enable local commands
let mapleader = ";" " namespace for local commands
" indentation & tabs
set autoindent backspace=indent,eol " indentation
set tabstop=8 softtabstop=4 shiftwidth=4 " tab stops
set expandtab smarttab " expand tabs
" simple input hints
syntax enable " content sensitive
if &statusline == '' " if not using status line...
set ruler " show simple cursor position
endif
set list " show whitespace hints
set listchars=tab:▸· " whitespace: show tab width
set showmatch " auto-show matching bracket
set cursorcolumn " show cursor alignemnt
highlight CursorColumn ctermbg=255 " very light grey column
highlight OverLength ctermbg=lightred ctermfg=black " pale red background
" cues for being in insert mode
augroup insert_mode_cues
autocmd!
if &term == 'xterm-256color' || &term == 'screen-256color'
let &t_EI = "\<Esc>[1 q" " command mode = blinking block
"let &t_SR = "\<Esc>[3 q" " replace mode = blinking _
let &t_SR = "\<Esc>[1 q" " replace mode = blinking block
let &t_SI = "\<Esc>[5 q" " insert mode = blinking I-bar
endif
autocmd InsertEnter * set cursorline " insert mode = underline line
autocmd InsertLeave * set nocursorline " command mode = remove underline
augroup END
" searching
set noincsearch " incremental search off
set hlsearch " highlight search strings
" scrolling
set scrolloff=1 " scroll offset = 1 line
" buffer controls
set wildmenu wildmode=longest,list,full " tab completion
" auto-folding
set foldmethod=indent foldlevel=99 " enable toggle folding
nnoremap <leader>f za " local command ;f toggles fold
" filetype-specific formatting
autocmd! BufRead,BufNewFile *.inc set filetype=html " force this
autocmd! BufRead,BufNewFile *.plist setfiletype xml " macOS property list
autocmd! BufRead,BufNewFile */etc/nginx/sites-*/* setfiletype nginx
autocmd! BufRead,BufNewFile */etc/sudoers.d/* setfiletype sudoers
filetype plugin on " content-specific commands
"filetype indent off " i dislike their indenting
" python content
augroup python_content
autocmd!
" autocmd filetype python set number " display line numbers
autocmd filetype python match OverLength /\%81v.\+/
augroup END
" web-related content
augroup web_content
autocmd!
autocmd filetype css\|html\|javascript\|json\|xhtml\|xml
\ set softtabstop=2 shiftwidth=2
autocmd filetype xml set matchpairs+=<:>
if !&filetype " if filetypes not enabled...
autocmd filetype html\|xhtml set matchpairs+=<:>
endif
autocmd filetype html\|json\|xhtml\|xml set nowrap
augroup END
If you need any personal overrides:
graham:~ vi .vimrc
~/.vimrc
new file
" personal settings
Append your settings to this file.
Sometimes pre-installed vim config files override these
custom system-wide settings;
changing scrolloff
> 1 is prevalent and very
annoying.
Set it (again) here, if required.
Alternatively, if too many such (re)settings, just
source /etc/vim/vimrc.local
to load them all again.
Similarly, if root
needs overrides:
graham:~ sudo vi ~root/.vimrc
~root/.vimrc
new file
" personal settings
Repeat personal .vimrc
for root
.
macOS
There is no standard location for custom system-wide vim settings.
Place all the content for Debian OS's /etc/vim/vimrc.local
above into your ~/.vimrc
instead.
Follow same instructions for .vimrc
.