VIMRC
VIMRC is the configurations for vi or vim. You can copy the script below and easily and quickly paste it using the following command (assuming you installed xclip
):
$ xclip -selection clipboard -o > ~/.vimrc
My Current Recipe
My Current Recipe
Currently, I'm maintaining this version of vimrc.
" Switch on syntax
syntax on
" Jump to the last position when reopening a file
au BufWinLeave * mkview
au BufWinEnter * silent loadview
" color to col 256
set synmaxcol=256
set t_Co=256
" define highlights
highlight Warning ctermbg=red ctermfg=white guibg=#592929
highlight Normal ctermfg=black ctermbg=white
highlight StatusLine ctermfg=black ctermbg=yellow guibg=#f2f2f2
set background=light
" whitespace detection
:set listchars=tab:>-,trail:~,extends:>,precedes:<
:set list
:nnoremap <c-l> :set list!<cr>
match Warning /\s\+$/
autocmd BufWinEnter * match Warning /\s\+$/
autocmd InsertEnter * match Warning /\s\+\%#\@<!$/
autocmd InsertLeave * match Warning /\s\+$/
autocmd BufWritePre * %s/\s\+$//e
" tab functions
function! UseTabs()
set ts=8 sts=8 sw=8 noexpandtab
endfunction
call UseTabs()
function! UseSpaces()
set ts=8 sts=8 sw=8 expandtab
endfunction
" set 80 column margins
match Warning /\%81v.\+/
set cc=81
" disable F1 and F2 unused command
:nmap <F1> <nop>
:nmap <F2> <nop>
" disable current line hilite
set nocursorline
" use legacy regex
set re=1
" always sync syntax highlighting on-screen and load the latest
autocmd BufEnter * :syntax sync fromstart
autocmd BufEnter * :edit!
" yaml file
autocmd! FileType yaml call UseSpaces()
autocmd! FileType yml call UseSpaces()
" sass /scss
autocmd! FileType sass call UseTabs()
autocmd! FileType scss call UseTabs()
" .bashrc
autocmd! FileType bashrc call UseSpaces()
" .vimrc
autocmd! FileType vimrc call UseSpaces()
" go
function! CheckGo(filename, dirpath)
echo 'checking with gofmt now...'
let cmd = 'gofmt -w -s ' . a:filename
echo system(cmd)
if v:shell_error
return 1
endif
echo "checking with golangci-lint now...\n\n"
let cmd = 'golangci-lint run ' . a:dirpath
echo system(cmd)
:exe "normal \<C-\[>"
endfunction
autocmd BufWritePost *.go call CheckGo(expand('%:p'), expand('%:p:h'))
autocmd BufWritePost *.go :edit!
autocmd BufWritePost *.go :syntax sync fromstart
" .sh, .bash shebang
function! CheckShebang()
if did_filetype()
finish
endif
if getline(1) =~# '^#!.*/bin/sh\>'
set syntax=sh
endif
if getline(1) =~# '^#!.*/bin/bash\>'
set syntax=bash
endif
endfunction
autocmd! VimEnter * call CheckShebang()
That's all about VIMRC.