" Plugin Management {{{ if ! filereadable(system('echo -n "$HOME/.vim/autoload/plug.vim"')) echo "Downloading junegunn/vim-plug to manage plugins..." silent !mkdir -p $HOME/.vim/autoload/ silent !curl "https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim" > ${XDG_CONFIG_HOME:-$HOME/.config}/nvim/autoload/plug.vim autocmd VimEnter * PlugInstall endif call plug#begin() " Fern Plug 'lambdalisue/fern.vim' " Fern git status Plug 'lambdalisue/fern-git-status.vim' " filemanager "Plug 'ms-jpq/chadtree', {'branch': 'chad', 'do': 'python3 -m chadtree deps'} " Tmux Plug 'christoomey/vim-tmux-navigator' Plug 'preservim/vimux' " Snippets Plug 'SirVer/ultisnips' Plug 'honza/vim-snippets' " Colorscheme Plug 'morhetz/gruvbox' Plug 'sainnhe/edge' Plug 'dracula/vim', { 'as': 'dracula' } Plug 'chriskempson/base16-vim' Plug 'arcticicestudio/nord-vim' " Whitespace Plug 'ntpeters/vim-better-whitespace' " Repeat Plug 'tpope/vim-repeat' " Expand region Plug 'terryma/vim-expand-region' " 100+ lazy loading syntax "Plug 'sheerun/vim-polyglot' " fzf integration Plug 'junegunn/fzf.vim' Plug 'junegunn/fzf', { 'do': { -> fzf#install() } } " float term Plug 'voldikss/vim-floaterm' " Color preview Plug 'ap/vim-css-color' " Fast movement in vim Plug 'easymotion/vim-easymotion' " Linting Plug 'dense-analysis/ale' " Aligment Plug 'junegunn/vim-easy-align' " Outliner for structured text " Plug 'vim-voom/VOoM' " Visualize undo tree Plug 'mbbill/undotree' " Vim prettier Plug 'prettier/vim-prettier', { \ 'do': 'npm install', \ 'for': ['json', 'markdown', 'yaml', 'html', 'javascript', 'css'] } " Statusline Plug 'itchyny/lightline.vim' " Git Plug 'tpope/vim-fugitive' Plug 'airblade/vim-gitgutter' " Surround Plug 'tpope/vim-surround' " Tags Plug 'majutsushi/tagbar' " TOML Plug 'cespare/vim-toml' " Markdown Plug 'plasticboy/vim-markdown' " Plug 'nelstrom/vim-markdown-folding' " For formating md tables Plug 'godlygeek/tabular' Plug 'dhruvasagar/vim-table-mode' " Ansible Plug 'pearofducks/ansible-vim' " Docker Plug 'ekalinin/Dockerfile.vim' " Go support Plug 'fatih/vim-go', { 'do': ':GoInstallBinaries' } " wrapper of Terminal and REPL " Plug 'kassio/neoterm' " Commenting Plug 'scrooloose/nerdcommenter' " Distraction free writing Plug 'junegunn/goyo.vim' " Dimm and highlight cursor line Plug 'junegunn/limelight.vim' " Latex " Plug 'vim-latex/vim-latex' " Better % matching Plug 'andymass/vim-matchup' " Key mapping menu " Plug 'liuchengxu/vim-which-key' " Rainbow Paranthesis " Plug 'luochen1990/rainbow' " Find and Replace " Plug 'brooth/far.vim' " bufkill Plug 'qpkorr/vim-bufkill' " Terraform Plug 'hashivim/vim-terraform' Plug 'juliosueiras/vim-terraform-completion' "Deoplete Plug 'Shougo/deoplete.nvim', { 'do': ':UpdateRemotePlugins' } " CSV Plug 'chrisbra/csv.vim' " Better f F t T Plug 'unblevable/quick-scope' " python Plug 'deoplete-plugins/deoplete-jedi' Plug 'vim-python/python-syntax' Plug 'jiangmiao/auto-pairs' Plug 'Yggdroot/indentLine' Plug 'elzr/vim-json' call plug#end() " }}} " Colors {{{ silent! colorscheme gruvbox " to work better with dracula "let g:polyglot_disabled = ['yaml'] " Follow transperancy from temrinal hi Normal guibg=NONE ctermbg=NONE if (has("termguicolors")) set termguicolors endif " Set comment color cause default dark blue is not readable hi Comment guifg=#cc99ff " }}} " UI {{{ set conceallevel=0 set number relativenumber " relative and absolute line numbers set showcmd " show command in bottom bar set cursorline " highlight current line " Space above/beside cursor from screen edges set scrolloff=3 set sidescrolloff=5 set wildmenu wildmode=full set wildignorecase set wildignore+=*/tmp/*,*.so,*.swp,*.zip,**/node_modules/**,**.git/**,**/target/**,**.terraform/** " MacOSX/Linux set encoding=utf-8 set showmatch " highlight matching [{()}] " }}} " Misc {{{ if has("win32") set clipboard=unnamed " default register is system clipboard else set clipboard=unnamedplus " default register is system clipboard endif " Highlight TODO in every file augroup HiglightTODO autocmd! autocmd WinEnter,VimEnter * :silent! call matchadd('Todo', 'TODO', -1) augroup END syntax on filetype indent plugin on set hidden set nocompatible set history=500 "set autochdir " set pwd always to current file set undofile " Maintain undo history between sessions set undodir=~/.vim/undodir set backupdir=$HOME/.vim/swp/ set directory=$HOME/.vim/swp/ " Delay for leader + key waiting for another key set timeoutlen=400 " Delay for leaving insert mode with esc set ttimeoutlen=0 " Disables automatic commenting on newline autocmd FileType * setlocal formatoptions-=c formatoptions-=r formatoptions-=o " Prevent wrong syntax redering - may slow down "autocmd BufEnter * :syntax sync fromstart " }}} " Search {{{ set incsearch " search as characters are entered set hlsearch " highlight matches set ignorecase " ignore case in search patterns set smartcase " highlight last inserted text nnoremap gV `[v`] " Turns off highlighting on the bits of code that are changed, so the line that is changed is highlighted but the actual text that has changed stands out on the line and is readable. if &diff highlight! link DiffText MatchParen endif " Center searches noremap n nzz noremap N Nzz " }}} " Default Mappings {{{ let mapleader=" " " paste over currently selected text without yanking it vnoremap p "_dP " write file with sudo cnoremap w!! execute 'silent! write !sudo tee % >/dev/null' edit! " move vertically by visual line when used withput count " and move by physical line when used with count noremap j (v:count == 0 ? 'gj' : 'j') noremap k (v:count == 0 ? 'gk' : 'k') " Disable arrow keys completely in Insert Mode imap imap imap imap " Visually move lines vmap J :m +1gv vmap K :m -2gv " change dire to current buufer nnoremap cd :cd %:p:h " open previously opened file nnoremap :e# " duplicate file nnoremap fd :clearsilent exec "!cp '%:p' '%:p:h/%:t:r-copy.%:e'"redrawecho "Copied " . expand('%:t') . ' to ' . expand('%:t:r') . '-copy.' . expand('%:e') " Change behaviour of Y similar to C and D nnoremap Y y$ " Keep selection active after indenting vmap > >gv vmap < :nohlsearch:echo " Toogle whitespace nnoremap tw :set list! " Buffer handling nnoremap bb :Buffers nnoremap bn :bn nnoremap bp :bp nnoremap bd :BD nnoremap bk :BD! nnoremap bs :w " Redo remap nnoremap U " Undotree nmap u :UndotreeShow " Substitute in current file if has("nvim") set inccommand=nosplit endif nnoremap r :let @s='\<'.expand('').'\>':%s/s//g xnoremap r "sy:%s/s//g " insert mode completion mappings " project tags inoremap " language and context aware inoremap " current buffer inoremap " dictionary inoremap " file path inoremap " whole line inoremap " Bash readline mappings inoremap ^ inoremap $ inoremap inoremap inoremap inoremap dw cnoremap cnoremap cnoremap cnoremap cnoremap cnoremap " Quickly insert an empty new line without entering insert mode nnoremap o o nnoremap O O " }}} " Folding {{{ set foldenable " enable folding set foldlevelstart=10 " open most folds by default set foldnestmax=2 " 10 nested fold max " }}} " Indenting {{{ set nowrap set tabstop=2 set shiftwidth=2 set expandtab set smartindent set autoindent " }}} " Whitespace {{{ " Better Whitespace " highlighting for the current line in normal mode can be disabled let g:current_line_whitespace_disabled_soft=1 " strip all trailing whitespace everytime you save let g:strip_whitespace_on_save = 1 " Do not ask for comfirmation let g:strip_whitespace_confirm=0 " Strip whitelines at end of file let g:strip_whitelines_at_eof=1 " characters for whitespaces set listchars=tab:→\ ,space:·,nbsp:␣,trail:•,eol:¶,precedes:«,extends:» " }}} " Windows handling {{{ " only show focused window nnoremap on :on "" Terminal mode: "tnoremap h "tnoremap j "tnoremap k "tnoremap l "" Insert mode: "inoremap h "imap j "inoremap k "inoremap l "" Visual mode: "vnoremap h "vmap j "vnoremap k "vnoremap l "" Normal mode: "nnoremap h "nmap j "nnoremap k "nnoremap l " Resizing nnoremap :vertical resize +1 nnoremap :vertical resize -1 nnoremap :resize -1 nnoremap :resize +1 " New nnoremap t :$tabnew " close nnoremap s :split nnoremap v :vsplit nnoremap q :close " }}} " Lightline {{{ set laststatus=2 set noshowmode " do not show mode because it is shown in the status line let g:lightline = { \ 'colorscheme': 'dracula', \ 'active': { \ 'left': [ [ 'mode', 'paste' ], \ [ 'gitbranch', 'readonly', 'filename', 'modified', 'spell' ] ] \ }, \ 'component_function': { \ 'gitbranch': 'FugitiveHead', \ 'filename': 'LightlineFilename' \ } \ } function! LightlineFilename() return expand('%:p') endfunction" }}} " Nerdtree {{{ "" Toggle NERDTree "nnoremap pt :NERDTreeToggle "nnoremap pv :NERDTreeFind "" quit vim if Nerdtree is the last buffer "autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif "" open NERDTree automatically ""autocmd StdinReadPre * let s:std_in=1 ""autocmd VimEnter * NERDTree "" Jump to the main window after Nerdtree is open "autocmd VimEnter * wincmd p "" sync open file with NERDTree "" " 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 BufEnter * call SyncTree() "" Automatically delete the buffer of the deleted file "let NERDTreeAutoDeleteBuffer = 1 "" Remove help message "let NERDTreeMinimalUI = 1 "let g:NERDTreeGitStatusIndicatorMapCustom = { " \ "Modified" : "✹", " \ "Staged" : "✚", " \ "Untracked" : "✭", " \ "Renamed" : "➜", " \ "Unmerged" : "═", " \ "Deleted" : "✖", " \ "Dirty" : "✗", " \ "Clean" : "✔︎", " \ 'Ignored' : '☒', " \ "Unknown" : "?" " \ } " }}} " Goyo and limelight {{{ " Goyo and limelight integration autocmd! User GoyoEnter Limelight autocmd! User GoyoLeave Limelight! " Limelight Color name (:help cterm-colors) or ANSI code let g:limelight_conceal_ctermfg = 'gray' let g:limelight_conceal_ctermfg = 240 " Limelight Color name (:help gui-colors) or RGB color let g:limelight_conceal_guifg = 'DarkGray' let g:limelight_conceal_guifg = '#777777' " }}} " Snippets {{{ let g:UltiSnipsExpandTrigger="" let g:UltiSnipsJumpForwardTrigger="" let g:UltiSnipsJumpBackwardTrigger="" let g:UltiSnipsSnippetDirectories=["UltiSnips", "custom-snippets"] augroup ultisnips_no_auto_expansion au! au VimEnter * au! UltiSnips_AutoTrigger augroup END " }}} " Gitgutter {{{ let g:gitgutter_map_keys = 0 nmap hn (GitGutterNextHunk) nmap hp (GitGutterPrevHunk) nmap hs (GitGutterStageHunk) nmap hu (GitGutterUndoHunk) nmap hv (GitGutterPreviewHunk) " }}} " FZF {{{ nnoremap :Files nnoremap rg :Rg nnoremap fr :History "nnoremap w :Windows nnoremap ; :BLines nnoremap : :BTags "nnoremap c :Commits nnoremap ft :Filetypes "nnoremap s :Snippets let g:fzf_layout = { 'window': { 'width': 0.8, 'height': 0.5, 'highlight': 'Comment', 'border': 'rounded' } } let g:fzf_action = { \ 'ctrl-t': 'tab split', \ 'ctrl-s': 'split', \ 'ctrl-v': 'vsplit' } if has('nvim') && !exists('g:fzf_layout') autocmd! FileType fzf autocmd FileType fzf set laststatus=0 noshowmode noruler \| autocmd BufLeave set laststatus=2 showmode ruler "autocmd Filetype fzf noremap "autocmd Filetype fzf noremap endif " }}} " EasyMotion {{{ " Disable default mappings let g:EasyMotion_do_mapping = 0 " Move to line map L (easymotion-bd-jk) nmap L (easymotion-overwin-line) " Move to word map W (easymotion-bd-w) nmap W (easymotion-overwin-w) " emulate vim-sneak nmap S (easymotion-s2) " }}} " EasyAlign {{{ " Start interactive EasyAlign in visual mode (e.g. vipga) xmap ga (EasyAlign) " Start interactive EasyAlign for a motion/text object (e.g. gaip) nmap ga (EasyAlign) " }}} " FLoaterm {{{ "let g:floaterm_keymap_toggle = 'f' "nnoremap fs :FloatermSend let g:floaterm_gitcommit = 'split' "command! VF FloatermNew vifm command! LF FloatermNew lf nnoremap lf :LF " }}} " Fern {{{ " Disable netrw. let g:loaded_netrw = 1 let g:loaded_netrwPlugin = 1 let g:loaded_netrwSettings = 1 let g:loaded_netrwFileHandlers = 1 augroup my-fern-hijack autocmd! autocmd BufEnter * ++nested call s:hijack_directory() augroup END function! s:hijack_directory() abort let path = expand('%:p') if !isdirectory(path) return endif bwipeout % execute printf('Fern %s', fnameescape(path)) endfunction " Custom settings and mappings. let g:fern#disable_default_mappings = 1 noremap p :Fern . -drawer -width=35 -toggle= noremap . :Fern %:h -drawer -width=35 -toggle= function! FernInit() abort augroup FernTypeGroup autocmd! * autocmd BufEnter silent execute "normal \(fern-action-reload)" augroup END nmap \ (fern-my-open-expand-collapse) \ fern#smart#leaf( \ "\(fern-action-open:select)", \ "\(fern-action-expand)", \ "\(fern-action-collapse)", \ ) nmap (fern-my-open-expand-collapse) nmap n (fern-action-new-path) nmap D (fern-action-trash) nmap m (fern-action-move) nmap M (fern-action-rename) nmap c (fern-action-copy) nmap r (fern-action-reload) nmap t (fern-action-mark:toggle) nmap s (fern-action-open:split) nmap v (fern-action-open:vsplit) nmap i (fern-action-hidden:toggle) nmap u (fern-action-leave) nmap e (fern-action-enter) nmap q :quit endfunction augroup FernGroup autocmd! autocmd FileType fern call FernInit() augroup END let g:fern#mark_symbol = '●' let g:fern#renderer#default#collapsed_symbol = '▷ ' let g:fern#renderer#default#expanded_symbol = '▼ ' let g:fern#renderer#default#leading = ' ' let g:fern#renderer#default#leaf_symbol = ' ' let g:fern#renderer#default#root_symbol = '~ ' let g:fern_git_status#disable_ignored = 1 let g:fern_git_status#disable_untracked = 1 let g:fern_git_status#disable_submodules = 1 " }}} " Tmux {{{ let g:tmux_navigator_disable_when_zoomed = 1 nnoremap :TmuxNavigateLeft nnoremap :TmuxNavigateDown nnoremap :TmuxNavigateUp nnoremap :TmuxNavigateRight nnoremap l :TmuxNavigatePrevious map tp :VimuxPromptCommand map tl :VimuxRunLastCommand map ti :VimuxInspectRunner map tz :VimuxZoomRunner " }}} " Deoplete {{{ let g:deoplete#enable_at_startup = 1 let g:deoplete#omni_patterns = {} let g:deoplete#omni_patterns.terraform = '[^ *\t"{=$]\w*' let g:deoplete#enable_at_startup = 1 call deoplete#initialize() " }}} " Terrafrom {{{ " (Optional)Remove Info(Preview) window set completeopt-=preview " (Optional)Hide Info(Preview) window after completions autocmd CursorMovedI * if pumvisible() == 0|pclose|endif autocmd InsertLeave * if pumvisible() == 0|pclose|endif " (Optional) Default: 0, enable(1)/disable(0) plugin's keymapping let g:terraform_completion_keys = 1 " (Optional) Default: 1, enable(1)/disable(0) terraform module registry completion let g:terraform_registry_module_completion = 0 " }}} " Markdown {{{ " Indet lists with 2 spaces let g:vim_markdown_new_list_item_indent = 0 " Open files followed by link in new tab let g:vim_markdown_edit_url_in = 'tab' let g:markdown_fenced_languages = ['bash=sh', 'css', 'javascript', 'js=javascript', 'json=javascript', 'xml', 'dockerfile', 'terraform', 'java'] let g:vim_markdown_conceal = 0 let g:vim_markdown_conceal_code_blocks = 0 " }}} " Quickscope {{{ " Trigger a highlight in the appropriate direction when pressing these keys: let g:qs_highlight_on_keys = ['f', 'F', 't', 'T'] let g:qs_buftype_blacklist = ['terminal', 'nofile'] highlight QuickScopePrimary guifg='#afff5f' gui=underline ctermfg=155 cterm=underline highlight QuickScopeSecondary guifg='#5fffff' gui=underline ctermfg=81 cterm=underline " }}} " Python {{{ au FileType python setl shiftwidth=4 tabstop=4 let g:python_highlight_all = 1 " Check Python files with flake8 and pylint. let b:ale_linters = ['flake8', 'pylint'] " Fix Python files with autopep8 and yapf. let b:ale_fixers = ['autopep8', 'yapf'] " Ignore line length linting let g:ale_python_flake8_options = '--ignore=E501' " open the go-to function in split, not another buffer let g:jedi#use_splits_not_buffers = "right" " Bind F5 to save file if modified and execute python script in a buffer. nnoremap :call SaveAndExecutePython() vnoremap :call SaveAndExecutePython() function! SaveAndExecutePython() " SOURCE [reusable window]: https://github.com/fatih/vim-go/blob/master/autoload/go/ui.vim " save and reload current file silent execute "update | edit" " get file path of current file let s:current_buffer_file_path = expand("%") let s:output_buffer_name = "Python" let s:output_buffer_filetype = "output" " reuse existing buffer window if it exists otherwise create a new one if !exists("s:buf_nr") || !bufexists(s:buf_nr) silent execute 'botright new ' . s:output_buffer_name let s:buf_nr = bufnr('%') elseif bufwinnr(s:buf_nr) == -1 silent execute 'botright new' silent execute s:buf_nr . 'buffer' elseif bufwinnr(s:buf_nr) != bufwinnr('%') silent execute bufwinnr(s:buf_nr) . 'wincmd w' endif silent execute "setlocal filetype=" . s:output_buffer_filetype setlocal bufhidden=delete setlocal buftype=nofile setlocal noswapfile setlocal nobuflisted setlocal winfixheight setlocal cursorline " make it easy to distinguish setlocal nonumber setlocal norelativenumber setlocal showbreak="" " clear the buffer setlocal noreadonly setlocal modifiable %delete _ " add the console output silent execute ".!python " . shellescape(s:current_buffer_file_path, 1) " resize window to content length " Note: This is annoying because if you print a lot of lines then your code buffer is forced to a height of one line every time you run this function. " However without this line the buffer starts off as a default size and if you resize the buffer then it keeps that custom size after repeated runs of this function. " But if you close the output buffer then it returns to using the default size when its recreated "execute 'resize' . line('$') " make the buffer non modifiable setlocal readonly setlocal nomodifiable endfunction " }}} " Bash {{{ au FileType sh setl shiftwidth=2 tabstop=2 nmap eb :w:!clear;bash % " }}} " YAML {{{ autocmd FileType yaml,yml setlocal ts=2 sts=2 sw=2 foldmethod=indent expandtab " }}} " JSON {{{ autocmd FileType json setlocal ts=4 sts=4 sw=4 foldmethod=syntax expandtab let g:vim_json_syntax_conceal = 0 " }}} " JavaScript {{{ autocmd FileType javascript setlocal shiftwidth=4 tabstop=4 " }}} " Fugitive {{{ " Conflict Resolution nnoremap gc :Gvdiff! nnoremap gdh :diffget //2 nnoremap gdl :diffget //3 " }}} " Indentline {{{ let g:indentLine_defaultGroup = 'SpecialKey' let g:indentLine_char_list = ['|', '¦', '┆', '┊'] let g:indentLine_concealcursor = 'nv' "let g:indentLine_conceallevel = 2 " }}} " Ale {{{ let g:ale_echo_msg_format = '[%linter%] %s [%severity%]' let g:ale_sign_error = '✘' let g:ale_sign_warning = '⚠' let g:ale_lint_on_text_changed = 'never' let g:ale_completion_enabled = 0 " }}} " Golang {{{ au FileType go setl shiftwidth=2 tabstop=2 au filetype go inoremap . . au BufRead,BufNewFile *.gohtml set filetype=gohtmltmpl autocmd FileType go nmap e (go-run) autocmd FileType go nmap d (go-describe) autocmd FileType go nmap i (go-info) autocmd FileType go nmap j :GoDeclsDir autocmd FileType go nmap B :call build_go_files() au Filetype go nmap ta (go-alternate-edit) au Filetype go nmap tah (go-alternate-split) au Filetype go nmap tav (go-alternate-vertical) au FileType go nmap gc :GoCoverageToggle -short " run :GoBuild or :GoTestCompile based on the go file function! s:build_go_files() let l:file = expand('%') if l:file =~# '^\f\+_test\.go$' call go#test#Test(0, 1) elseif l:file =~# '^\f\+\.go$' call go#cmd#Build(0) endif endfunction let g:go_bin_path = $HOME."/go/bin" let g:go_fmt_command = "goimports" " Run goimports along gofmt on each save let g:go_auto_type_info = 1 " Automatically get signature/type info for object under cursor let g:go_auto_sameids = 1 let g:go_highlight_types = 1 let g:go_highlight_fields = 1 let g:go_highlight_functions = 1 let g:go_highlight_function_calls = 1 let g:go_highlight_operators = 1 let g:go_highlight_extra_types = 1 let g:go_highlight_build_constraints = 1 let g:go_metalinter_enabled = ['vet', 'golint', 'errcheck'] let g:go_metalinter_autosave = 1 set updatetime=300 " }}} " Indenting {{{ " }}} " Indenting {{{ " }}} " Indenting {{{ " }}} " Indenting {{{ " }}} " Indenting {{{ " }}} " vim:foldmethod=marker:foldlevel=0