setup-cockpit/dotfiles/vim/vimrc

211 lines
6.9 KiB
VimL

" 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
" split navigation
nnoremap <leader>h :wincmd h<CR>
nnoremap <leader>j :wincmd j<CR>
nnoremap <leader>k :wincmd k<CR>
nnoremap <leader>l :wincmd l<CR>
" }}}
" VUNDLE {{{
filetype off
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'VundleVim/Vundle.vim' " let Vundle manage Vundle, required
" AUTOCOMPLETION, FORMATTING AND LINTING
Plugin 'ycm-core/YouCompleteMe' " Main autocompletion
Plugin 'nvie/vim-flake8' " PEP8 linting for Python
Plugin 'dense-analysis/ale' " Vim integration for various linters
Plugin 'psf/black' " Black autoformatter for Python
" HIGHLIGHTING
Plugin 'ntpeters/vim-better-whitespace' " Whitespace highlighting and removal
Plugin 'python-mode/python-mode' " Python syntax highlighting
Plugin 'c.vim' " C syntax highlighting
Plugin 'rust-lang/rust.vim' " Rust syntax highlighting
Plugin 'godlygeek/tabular' | Plugin 'plasticboy/vim-markdown' " Markdown syntax highlighting
" STATUSLINE
Plugin 'vim-airline/vim-airline'
Plugin 'vim-airline/vim-airline-themes'
" MISC.
Plugin 'preservim/nerdtree' " A tree explorer plugin
Plugin 'Xuyuanp/nerdtree-git-plugin' " A NERDTree plugin showing git status
Plugin 'Yggdroot/indentLine' " Display thin vertical lines at each indentation level
call vundle#end()
filetype plugin indent on
" }}}
" PLUGIN OPTIONS {{{
let g:ale_python_mypy_options = '--strict --strict-optional'
let g:pymode_options_max_line_length = 90
let g:pymode_options_colorcolumn = 0
let g:pymode_lint_ignore = ["E203"]
let g:ycm_extra_conf_globlist = ['!~/*'] " is overwritten in autogroups for c
let g:ycm_autoclose_preview_window_after_insertion = 1
" in normal mode run YCM's GoTo subcommand
nnoremap <leader>gd :YcmCompleter GoTo<CR>
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']
" }}}
" COLORS {{{
colorscheme badwolf
let g:airline_theme='badwolf'
syntax on
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 {{{
" The default cursor in normal mode is block but this will be overridden by any shell configuration.
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><space> :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
" space opens and closes folds
nnoremap <space> za
" }}}
" MOVEMENT {{{
" move vertically by visual line (don't jump wrapped lines)
nnoremap j gj
nnoremap k gk
" }}}
" AUTOGROUPS {{{
augroup configgroup
autocmd!
" reset cursor on start:
autocmd VimEnter * silent !echo -en "\e[2 q"
autocmd VimEnter * highlight clear SignColumn
" Automatically open NERDTree when vim starts up without files specified
autocmd StdinReadPre * let s:std_in=1
autocmd VimEnter * if argc() == 0 && !exists("s:std_in") | NERDTree | endif
" Close vim if the only window left open is a NERDTree
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif
" Run StripWhitespace function on write
autocmd BufWritePre * :StripWhitespace
" Run Flake8 on write in python files
autocmd BufWritePost *.py call flake8#Flake8()
" 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 java setlocal noexpandtab
autocmd FileType java setlocal list
autocmd FileType java setlocal listchars=tab:+\ ,eol:-
autocmd FileType java setlocal formatprg=par\ -w80\ -T4
autocmd FileType php setlocal expandtab
autocmd FileType php setlocal list
autocmd FileType php setlocal lischars=tab:+\ ,eol:-
autocmd FileType php setlocal formatprg=par\ -w80\ -T4
autocmd FileType ruby setlocal tabstop=2
autocmd FileType ruby setlocal shiftwidth=2
autocmd FileType ruby setlocal softtabstop=2
autocmd FileType ruby setlocal commentstring=#\ %s
autocmd FileType rust nnoremap <F9> :RustFmt<CR>
autocmd FileType python setlocal commentstring=#\ %s
autocmd FileType python setlocal foldmethod=indent
autocmd FileType python setlocal colorcolumn=80
autocmd FileType python let g:ycm_python_interpreter_path = ''
autocmd FileType python let g:ycm_python_sys_path = []
autocmd FileType python let g:ycm_extra_conf_vim_data = ['g:ycm_python_interpreter_path', 'g:ycm_python_sys_path']
autocmd FileType python let g:ycm_global_ycm_extra_conf = '~/.global_extra_conf.py'
autocmd FileType python nnoremap <F9> :Black<CR>
autocmd FileType yaml setlocal foldmethod=indent
autocmd BufEnter *.cls setlocal filetype=java
autocmd BufEnter *zsh-theme setlocal filetype=zsh
autocmd BufEnter Makefile setlocal noexpandtab
autocmd BufEnter Makefile setlocal tabstop=6
autocmd BufEnter Makefile setlocal shiftwidth=6
autocmd BufEnter Makefile setlocal softtabstop=0
autocmd BufEnter *.asm setlocal noexpandtab
autocmd BufEnter *.asm setlocal tabstop=6
autocmd BufEnter *.asm setlocal shiftwidth=6
autocmd BufEnter *.asm setlocal softtabstop=0
autocmd BufEnter *.html setlocal foldmethod=indent
autocmd BufEnter *.sh setlocal tabstop=2
autocmd BufEnter *.sh setlocal shiftwidth=2
autocmd BufEnter *.sh setlocal softtabstop=2
autocmd BufEnter *.sh setlocal foldmethod=marker
autocmd BufEnter *.sh setlocal foldlevel=0
augroup END
" }}}
set modelines=1
" vim:foldmethod=marker:foldlevel=0