linux-config/playbooks/files/dotfiles/vimrc

374 lines
13 KiB
VimL
Raw Normal View History

2021-10-22 11:45:20 +00:00
"==============================================================================
" vim-plug
"==============================================================================
" plugins list
call plug#begin('~/.vim/plugged')
Plug 'sheerun/vim-polyglot' " A ton of language syntax
Plug 'morhetz/gruvbox' " Gruvbox theme
Plug 'sickill/vim-monokai' " Monokai Theme
Plug 'arcticicestudio/nord-vim' " Nord theme
Plug 'itchyny/lightline.vim' " vim status bar
Plug 'shinchu/lightline-gruvbox.vim' " Gruvbox theme for status line
Plug 'airblade/vim-gitgutter' " Git gutter
Plug 'lilydjwg/colorizer' " Displays the colors in file
Plug 'jiangmiao/auto-pairs' " Auto create bracket/parens/quote pairs
Plug 'vim-syntastic/syntastic' " coding-errors checker
Plug 'neoclide/coc.nvim', {'branch': 'release'} " Lanuage server integrations
Plug 'tpope/vim-fugitive' " git wrapper
Plug 'fatih/vim-go', { 'do': ':GoUpdateBinaries' } " golang plugin for vim
Plug 'Yggdroot/indentLine' " Indentation LInes
Plug 'junegunn/fzf' " Fuzzy search
Plug 'junegunn/fzf.vim' " Fuzzy search
Plug 'francoiscabrol/ranger.vim' " Ranger <leader>f
Plug 'scrooloose/nerdtree' " NerdTree - File tree (ctr-n)
Plug 'Xuyuanp/nerdtree-git-plugin' " Git support in NERDTree
Plug 'ryanoasis/vim-devicons' " File Icons - Always load last
call plug#end()
" Set encoding to utf8
set encoding=UTF-8
2021-11-04 11:52:54 +00:00
" Set no compatible
set nocompatible
" File type plugin on
filetype plugin on
" Turn on syntax
syntax on
2021-10-22 11:45:20 +00:00
" install plugins automatically
autocmd VimEnter *
\ if len(filter(values(g:plugs), '!isdirectory(v:val.dir)'))
\| PlugInstall --sync | q
\| endif
" remove unused plugins automatically
autocmd VimEnter *
\ if len(filter(split(globpath(g:plug_home, '*'), "\n"), 'isdirectory(v:val)'))
\ > len(filter(values(g:plugs), 'stridx(v:val.dir, g:plug_home) == 0'))
\| PlugClean | q
\| endif
" Toggle NerdTree with Ctrl+n
map <C-n> :NERDTreeToggle<CR>
" Open fzf Files search
map <C-p> :Files<CR>
" Open file search
map <C-f> :BLines<CR>
" Indent Guides auto start
let g:indent_guides_enable_on_vim_startup = 1
" Tab navigation and creation
map <C-t> :tabnew<CR>
2021-11-01 07:42:10 +00:00
noremap <Tab><Tab> :tabn<CR>
2021-10-22 11:45:20 +00:00
" Insert mode navigation Alt+hjkl
imap <C-s-h> <Left>
imap <C-s-l> <Right>
imap <C-s-j> <Down>
imap <C-s-k> <Up>
" Set line heighlight on by default
set cursorline
" Set Clipboard to system
set clipboard=unnamedplus
" Enable mouse use in all modes
set mouse=a
" Auto highlight similar words when staying on a word after .5 sec
set updatetime=500
augroup highlight_current_word
au!
au CursorHold *
\ if ( expand("%") != 'NERD_tree_1' )
\ | :exec 'match Search /\V\<' . expand('<cword>') . '\>/'
\ | endif
augroup END
"==============================================================================
" Sync NERDTree with file
"==============================================================================
" Check if NERDTree is open or active
function! IsNERDTreeOpen()
return exists("t:NERDTreeBufName") && (bufwinnr(t:NERDTreeBufName) != -1)
endfunction
" Call NERDTreeFind iff NERDTree is active, current window contains a modifiable
" file, and we're not in vimdiff
function! SyncTree()
if &modifiable && IsNERDTreeOpen() && strlen(expand('%')) > 0 && !&diff
NERDTreeFind
wincmd p
endif
endfunction
" Highlight currently open buffer in NERDTree
autocmd BufRead * call SyncTree()
" Nerdtree show hidden files
let NERDTreeShowHidden=1
" Dont show .git folder
let NERDTreeIgnore=['\.git$']
"==============================================================================
" Theme settings
"==============================================================================
2021-11-04 11:52:54 +00:00
let &t_8f = "\<Esc>[38;2;%lu;%lu;%lum"
let &t_8b = "\<Esc>[48;2;%lu;%lu;%lum"
2021-10-22 11:45:20 +00:00
"set termguicolors
" Theme
colorscheme nord
" Setting dark mode
2021-11-04 11:52:54 +00:00
set background=dark
2021-10-22 11:45:20 +00:00
"==============================================================================
" line number
"==============================================================================
" set relative number on visual mode and absolute number on insert mode
set relativenumber
set number
autocmd InsertEnter * :set number norelativenumber
autocmd InsertLeave * :set nonumber relativenumber
" set backgrond and font color of line number
highlight LineNr ctermfg=grey ctermbg=black
" open files at the last remember line
if has("autocmd")
au BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$")
\| exe "normal! g`\""
\| endif
endif
"==============================================================================
" TAB settings
"==============================================================================
"filetype plugin indent on
" show existing tab with 4 spaces width
set tabstop=4
" when indenting with '>', use 4 spaces width
set shiftwidth=4
" On pressing tab, insert 4 spaces
set expandtab
"==============================================================================
" set column
"==============================================================================
" set coding style limit at 80 chars
set colorcolumn=80
"==============================================================================
" mouse settings
"==============================================================================
" enable mouse
set mouse=a
"==============================================================================
" file title
"==============================================================================
" always show current file title
set title
"==============================================================================
" normal mode mapping
"==============================================================================
" mapping capsLock to ctrl
map CapsLock Ctrl
" this package is extending % to <> and other sifferent closures
packadd! matchit
:let b:match_words = '<:>,<tag>:</tag>'
" enable ci( of all sorts to work from outside the parenthese
nnoremap ci( %ci(
nnoremap ci[ %ci[
nnoremap ci{ %ci{
" NOTE: use 'normal' for <> because % is not a regular vim command (package)
nnoremap ci< :normal %<CR>ci<
" enable di( of all sorts to work from outside the parenthese
nnoremap di( %di(
nnoremap di[ %di[
nnoremap di{ %di{
" NOTE: use 'normal' for <> because % is not a regular vim command (package)
nnoremap di< :normal %<CR>di<
" easy navigation on split screen
nnoremap <C-J> <C-W><C-J>
nnoremap <C-K> <C-W><C-K>
nnoremap <C-L> <C-W><C-L>
nnoremap <C-H> <C-W><C-H>
" easy access to buffers
" \l : list buffers
" \b \f \g : go back/forward/last-used
" \d : delete buffer
nnoremap <Leader>l :ls<CR>
nnoremap <Leader>b :bp<CR>
nnoremap <Leader>f :bn<CR>
nnoremap <Leader>g :e#<CR>
nnoremap <Leader>c :bd<CR>
" make 'Y' act like 'D' and 'C' instead of working like 'yy'
nnoremap Y y$
"==============================================================================
" search settings
"==============================================================================
" ignore CASE in search
set ignorecase
" higlight search matches
set hlsearch
"==============================================================================
" vim && tmux
"==============================================================================
" makes split-navigation act differently when in vim\tmux
" in both cases navigation will be done with ctr + hjkl (without tmux prefix)
if exists('$TMUX')
function! TmuxOrSplitSwitch(wincmd, tmuxdir)
let previous_winnr = winnr()
silent! execute "wincmd " . a:wincmd
if previous_winnr == winnr()
call system("tmux select-pane -" . a:tmuxdir)
redraw!
endif
endfunction
let previous_title = substitute(system("tmux display-message -p '#{pane_title}'"), '\n', '', '')
let &t_ti = "\<Esc>]2;vim\<Esc>\\" . &t_ti
let &t_te = "\<Esc>]2;". previous_title . "\<Esc>\\" . &t_te
nnoremap <silent> <C-h> :call TmuxOrSplitSwitch('h', 'L')<cr>
nnoremap <silent> <C-j> :call TmuxOrSplitSwitch('j', 'D')<cr>
nnoremap <silent> <C-k> :call TmuxOrSplitSwitch('k', 'U')<cr>
nnoremap <silent> <C-l> :call TmuxOrSplitSwitch('l', 'R')<cr>
else
map <C-h> <C-w>h
map <C-j> <C-w>j
map <C-k> <C-w>k
map <C-l> <C-w>l
endif
"==============================================================================
" split settings
"==============================================================================
"
" more intuitive default splits
set splitbelow
set splitright
"==============================================================================
" Lightline.vim plugin & status line
"==============================================================================
" make status line always visible
set laststatus=2
" NOTE: 'FugitiveHead' is 'vim-fugitive' plugin's function and depend on it
" configure lightline.vim status line
let g:lightline = {
\ 'active': {
\ 'left': [ [ 'mode', 'paste' ],
\ [ 'gitbranch', 'readonly', 'filename', 'modified' ] ]
\ },
\ 'component_function': {
\ 'gitbranch': 'FugitiveHead',
\ 'filename': 'LightlineFilename',
\ },
\ }
" lightline colorscheme
let g:lightline.colorscheme = 'nord'
" function to get the filename from vim to lightline.vim
function! LightlineFilename()
return &filetype ==# 'vimfiler' ? vimfiler#get_status_string() :
\ &filetype ==# 'unite' ? unite#get_status_string() :
\ &filetype ==# 'vimshell' ? vimshell#get_status_string() :
\ expand('%') !=# '' ? expand('%') : '[No Name]'
endfunction
let g:unite_force_overwrite_statusline = 0
let g:vimfiler_force_overwrite_statusline = 0
let g:vimshell_force_overwrite_statusline = 0
" actually this have no effect when lightline.vim plugin is installed
set statusline+=%f "relative path (use %F for absolute path)
set statusline+=%m "modified flag
set statusline+=%= "left/right separator
set statusline+=%l/%L "cursor line/total lines
set statusline+=\ %P "percent through file
"==============================================================================
" Spelling settings
"==============================================================================
" make spell checker underline errors with vim 'set spell' command
" Note: must appear after the last line that is altering colorscheme
hi clear SpellBad
hi SpellBad cterm=underline
"==============================================================================
" Delete settings
"==============================================================================
" make backspace always erase in insert mode and not only new inputs
set backspace=indent,eol,start
"==============================================================================
" Fold settings
"==============================================================================
set foldmethod=marker
"==============================================================================
" swp files
"==============================================================================
" Don't use swapfile
set noswapfile
2021-11-01 07:42:10 +00:00
"==============================================================================
" Coc Key mapping
"==============================================================================
"" Use <c-space> to trigger completion.
if has('nvim')
inoremap <silent><expr> <c-space> coc#refresh()
else
inoremap <silent><expr> <c-@> coc#refresh()
endif
" Symbol renaming.
nmap <F2> <Plug>(coc-rename)
" Hit tab go see documentation
nmap <Tab> :silent call <SID>show_documentation()<CR>
function! s:show_documentation()
if (index(['vim','help'], &filetype) >= 0)
execute 'h '.expand('<cword>')
elseif (coc#rpc#ready())
call CocActionAsync('doHover')
else
execute '!' . &keywordprg . " " . expand('<cword>')
endif
endfunction