1" Enable Vundle: Vim plugin manager
2set rtp+=~/.vim/bundle/Vundle.vim
3call vundle#begin()
4
5" Basic plugins
6Plugin 'VundleVim/Vundle.vim'
7Plugin 'scrooloose/nerdtree' " File tree explorer with Ctrl+N
8Plugin 'vim-airline/vim-airline' " Stylish status bar
9Plugin 'jiangmiao/auto-pairs' " Automatic insertion of brackets, quotes, etc.
10Plugin 'w0rp/ale' " Syntax checking and linting
11Plugin 'honza/vim-snippets' " Collection of useful snippets
12Plugin 'garbas/vim-snipmate' " Snippet management (deprecated, consider using UltiSnips or vim-snippets instead)
13Plugin 'tomtom/tlib_vim' " Required for some plugins
14Plugin 'MarcWeber/vim-addon-mw-utils' " More utilities for Vim
15Plugin 'sainnhe/sonokai' " Beautiful colorscheme
16
17" Conditionally load coc.nvim
18let g:use_coc = 0 " Set to 1 to enable coc.nvim
19
20if g:use_coc
21 Plugin 'neoclide/coc.nvim' " Intellisense engine
22endif
23
24call vundle#end()
25
26" INSTALL PLUGINS WITH :PluginInstall
27
28" Basic Behavior and Interface
29set number " Show line numbers
30set wrap " Wrap lines
31set encoding=utf-8 " Use UTF-8 encoding
32set mouse=a " Enable mouse support
33set wildmenu " Visual autocomplete for command menu
34set lazyredraw " Redraw screen only when needed
35set showmatch " Highlight matching parentheses / brackets [{()}]
36set laststatus=2 " Always show statusline
37set ruler " Show line and column number of the cursor
38set signcolumn=yes " Show sign column for LSP diagnostics
39set clipboard=unnamedplus " Use system clipboard
40
41" Key Bindings
42nnoremap j gj " Move down by visual line (don't skip wrapped lines)
43nnoremap k gk " Move up by visual line (don't skip wrapped lines)
44nnoremap <C-d> <C-d>zz " Scroll down half screen
45nnoremap <C-u> <C-u>zz " Scroll up half screen
46nnoremap Q <nop> " Disable Ex mode
47nnoremap <C-a> ggVG " Select all text
48nnoremap <C-c> <cmd>%y<CR> " Copy all text
49
50vnoremap J :m '>+1<CR>gv=gv
51vnoremap K :m '<-2<CR>gv=gv
52
53" Toggle NERDTree file tree
54nnoremap <C-n> :NERDTreeToggle<CR>
55
56" Find and replace in all files with CTRL+S in normal mode
57nnoremap <C-s> :%s/\<<C-r><C-w>\>/<C-r><C-w>/gI<Left><Left><Left>
58
59" Vim Appearance
60colorscheme sonokai " Set colorscheme
61set termguicolors " Enable true colors support
62autocmd vimenter * hi Normal guibg=NONE ctermbg=NONE " Set background to transparent
63
64" Use filetype-based settings
65syntax enable " Enable syntax highlighting
66filetype plugin indent on " Enable filetype-specific plugins and indentation
67
68" Tab Settings
69set tabstop=4 " Set tab width to 4 spaces
70set expandtab " Use spaces instead of <TAB>
71set shiftwidth=4 " Number of spaces to use for (auto)indent
72set softtabstop=4 " Backspace deletes up to 4 spaces
73
74" Search Settings
75set incsearch " Highlight matches as characters are entered
76set hlsearch " Highlight all matches
77
78" Turn off search highlighting with <CR> (carriage-return)
79nnoremap <CR> :nohlsearch<CR><CR>
80
81" Miscellaneous Settings
82set background=dark " Use dark background
83set autoread " Autoread files changed outside Vim
84set scrolloff=8 " Minimum lines to keep above/below cursor
85set colorcolumn=80 " Highlight column 80
86set hidden " Allow hiding buffers with unsaved changes
87set undofile " Save undo history to file
88set undodir=$HOME/.vimundo/ " Directory for undo files
89set backspace=eol,start,indent " Allow backspace in insert mode
90set whichwrap+=<,>,h,l " Allow <BS>, <Del>, etc. in insert mode
91set lazyredraw " Don't redraw while executing macros
92set magic " Enable magic in regular expressions
93set showmatch " Show matching brackets when text indicator is over them
94
95" Files, Backups, and Undo
96set nobackup " No backup files
97set nowb " No write backup files
98set noswapfile " No swap files
99
100let g:snipMate = { 'snippet_version' : 1 }
101nnoremap <SPACE> <Nop>
102let mapleader=" "
103set ph=10 " Max height of windows appearing
104
105if g:use_coc
106 " CoC.nvim configuration
107 " Autocomplete and diagnostics settings
108 inoremap <silent><expr> <CR> coc#pum#visible() ? coc#pum#confirm() : "\<CR>"
109 inoremap <silent><expr> <C-j> coc#pum#visible() ? coc#pum#next(1) : "\<C-j>"
110 inoremap <silent><expr> <C-k> coc#pum#visible() ? coc#pum#prev(1) : "\<C-k>"
111
112 " GoTo code navigation.
113 nmap <silent> gd <Plug>(coc-definition)
114 nmap <silent> gy <Plug>(coc-type-definition)
115 nmap <silent> gi <Plug>(coc-implementation)
116 nmap <silent> gr <Plug>(coc-references)
117
118 " Use K to show documentation in preview window.
119 nnoremap <silent> K :call <SID>show_documentation()<CR>
120
121 function! s:show_documentation()
122 if CocAction('hasProvider', 'hover')
123 call CocActionAsync('doHover')
124 else
125 call feedkeys('K', 'in')
126 endif
127 endfunction
128
129 " Highlight the symbol and its references when holding the cursor.
130 " autocmd CursorHold * silent call CocActionAsync('highlight')
131
132 " Symbol renaming.
133 nmap <leader>rn <Plug>(coc-rename)
134
135 " Formatting selected code.
136 xmap <leader>f <Plug>(coc-format-selected)
137 nmap <leader>f <Plug>(coc-format-selected)
138 nnoremap <silent> <C-f> :call CocAction('format')<CR>
139
140 " Update signature help on jump placeholder.
141 autocmd User CocJumpPlaceholder call CocActionAsync('showSignatureHelp')
142
143 " Applying code actions to the selected code block.
144 nmap <leader>ac <Plug>(coc-codeaction-selected)
145 xmap <leader>ac <Plug>(coc-codeaction-selected)
146 " Remap keys for applying code actions at the current cursor position.
147 nmap <leader>ca <Plug>(coc-codeaction)
148
149 " Remap keys for applying code actions for the current buffer.
150 nmap <leader>cA <Plug>(coc-codeaction-all)
151
152 " Use `[g` and `]g` to navigate diagnostics
153 " Use `:CocDiagnostics` to get all diagnostics of current buffer in location list.
154 nmap <silent> [g <Plug>(coc-diagnostic-prev)
155 nmap <silent> ]g <Plug>(coc-diagnostic-next)
156endif