setup-cockpit/dotfiles/vim/vimrc

214 lines
6.2 KiB
VimL

" flyingscorpio's VIM Configuration File
" most of this comes from https://dougblack.io/words/a-good-vimrc.html
set nocompatible " disable vi compatibility (emulation of old bugs)
" UTF-8 ENCODING {{{
set enc=utf-8
set fenc=utf-8
set termencoding=utf-8
" }}}
" LEADER SHORTCUTS {{{
let mapleader=" "
" jk is escape
inoremap jk <esc>
" F2 to save file
nmap <F2> :w<CR>
imap <F2> <ESC>:w<CR>i
" global copy/paste
nmap <leader>y "*yy
nmap <leader>p "*p
" run make
nmap <leader>m :w<CR>:!make<CR>
" open terminal in split window
if has('nvim')
nmap <leader>t :below 10split<CR>:terminal<CR>i
else
nmap <leader>t :below terminal ++rows=10<CR>
endif
" }}}
" VIM-PLUG {{{
call plug#begin('~/.vim/plugged')
" AUTOCOMPLETION, FORMATTING AND LINTING
" Main autocompletion
Plug 'neoclide/coc.nvim', { 'branch': 'release' }
"Auto close parens and such
Plug 'Townk/vim-autoclose'
" PEP8 linting for Python
Plug 'nvie/vim-flake8'
" Vim integration for various linters
Plug 'dense-analysis/ale'
" Black autoformatter for Python
Plug 'psf/black', { 'branch': 'stable' }
"Surround
Plug 'tpope/vim-surround'
" Snippets
Plug 'SirVer/ultisnips'
Plug 'honza/vim-snippets'
"COLOR SCHEMES
Plug 'morhetz/gruvbox'
Plug 'sjl/badwolf'
" HIGHLIGHTING
" Whitespace highlighting and removal
Plug 'ntpeters/vim-better-whitespace'
" C syntax highlighting
Plug 'vim-scripts/c.vim'
" Rust syntax highlighting
Plug 'rust-lang/rust.vim'
" Markdown syntax highlighting
Plug 'godlygeek/tabular' | Plug 'plasticboy/vim-markdown'
" Ansible syntax highlighting
Plug 'pearofducks/ansible-vim', { 'do': './UltiSnips/generate.sh' }
" PowerShell syntax hightlighting
Plug 'PProvost/vim-ps1'
" STATUSLINE
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
" MISC.
" Python IDE
Plug 'python-mode/python-mode', { 'for': 'python', 'branch': 'develop' }
" A tree explorer plugin
Plug 'preservim/nerdtree'
" A NERDTree plugin showing git status
Plug 'Xuyuanp/nerdtree-git-plugin'
" Display thin vertical lines at each indentation level
Plug 'Yggdroot/indentLine'
" VimTeX
Plug 'lervag/vimtex'
call plug#end()
" }}}
" PLUGIN OPTIONS {{{
function! s:check_back_space() abort
let col = col('.') - 1
return !col || getline('.')[col - 1] =~ '\s'
endfunction
inoremap <silent><expr> <TAB>
\ pumvisible() ? "\<C-n>" :
\ <SID>check_back_space() ? "\<TAB>" :
\ coc#refresh()
let g:ale_python_mypy_options = '--strict --strict-optional'
let g:ale_linters_ignore = ['lacheck']
let g:pymode_options_max_line_length = 90
let g:pymode_options_colorcolumn = 0
let g:pymode_lint_ignore = ["E203"]
let g:coc_global_extensions = [ 'coc-clangd', 'coc-sh', 'coc-powershell', 'coc-pyright', 'coc-json', 'coc-html', 'coc-css', 'coc-vimtex' ]
let NERDTreeIgnore=['^__pycache__$', '\.pyc', '\~$'] " ignore files in NERDTree
" in normal mode open NERDTree
nmap <leader>ne :NERDTree<CR>
" let g:indentLine_char = '▏'
let g:indentLine_fileType = ['html', 'htmldjango']
let g:tex_flavor = 'latex'
let g:vimtex_view_method = 'zathura'
let g:vimtex_quickfix_autoclose_after_keystrokes = 2
let g:vimtex_quickfix_open_on_warning = 0
let g:UltiSnipsExpandTrigger = '<S-tab>'
" }}}
" COLORS {{{
syntax on
set termguicolors
let g:gruvbox_contrast_dark='hard'
let g:gruvbox_transparent_bg = 1
let g:gruvbox_italic = 1
set background=dark
colorscheme gruvbox
"let g:airline_theme='gruvbox'
let &t_ut = '' " Disable BCE (background color erase)
" }}}
" SPACES & TABS {{{
set expandtab " expand tabs to spaces
set shiftwidth=4
set softtabstop=4 " number of spaces in tab when editing
" }}}
" UI CONFIG {{{
let &t_SI = "\e[5 q" " cursor beam on insert mode
let &t_SR = "\e[3 q" " cursor underline on replace mode
let &t_EI = "\e[2 q" " cursor block otherwise
set number relativenumber " hybrid line numbers
set spelllang=en,fr
set showcmd " show command in bottom bar
set cursorline " highlight current line
filetype indent on " load filetype-specific indent files
set autoindent " use indentation of previous line
set smartindent " use intelligent indentation for C
set wildmenu " visual autocomplete for command menu
set lazyredraw " redraw only when necessary
set showmatch " highlight matching braces
" }}}
" SEARCHING {{{
set path+=** " Find files in sub-folders too
set incsearch " search as characters are entered
set hlsearch " highlight matches
" turn off search hightlight after search
nnoremap <leader>, :nohlsearch<CR>
" }}}
" FOLDING {{{
set foldenable " enable folding
set foldlevelstart=10 " open most folds by default (0 to 99)
set foldnestmax=10 " guard against too many nested folds
set foldmethod=syntax " fold based on filetype
" }}}
" MOVEMENT {{{
" move vertically by visual line (don't jump wrapped lines)
"nnoremap j gj
"nnoremap k gk
" move between splits more easily
map <C-h> <C-w>h
map <C-j> <C-w>j
map <C-k> <C-w>k
map <C-l> <C-w>l
" }}}
" AUTOGROUPS {{{
augroup configgroup
autocmd!
" Reset cursor on start: the default cursor in normal mode is block but this
" will be overridden by any shell/terminal configuration.
autocmd VimEnter * silent !echo -en "\e[2 q"
" Remove garbage in command section due to the above line
autocmd VimEnter * redraw!
autocmd VimEnter * highlight clear SignColumn
" Run StripWhitespace function on write
autocmd BufWritePre * :StripWhitespace
" Run Flake8 on write in python files
autocmd BufWritePost *.py call flake8#Flake8()
" Run make clean when leaving a LaTeX file if Makefile exists in directory
"autocmd VimLeave *.tex ![ -f ./Makefile ] && make clean
" Toggle relative number and absolute number according to focus and insert
autocmd BufEnter,FocusGained,InsertLeave * set relativenumber
autocmd BufLeave,FocusLost,InsertEnter * set norelativenumber
"autocmd FileType c let g:ycm_extra_conf_globlist = ['~/*']
autocmd FileType rust nnoremap <F9> :RustFmt<CR>
autocmd FileType python nnoremap <F9> :Black<CR>
autocmd FileType html,htmldjango,python,tex,plaintex,yaml setlocal foldmethod=indent
autocmd FileType python setlocal colorcolumn=80
autocmd BufEnter Makefile,*.asm setlocal noexpandtab tabstop=6 shiftwidth=6 softtabstop=0
autocmd BufEnter *.sh setlocal shiftwidth=2 tabstop=2 softtabstop=2 foldlevel=0 foldmethod=marker
augroup END
" }}}
set modelines=1
" vim:foldmethod=marker:foldlevel=0