summaryrefslogtreecommitdiffstats
path: root/vim/vimrc
blob: 80dedf15b90f184e99b7c6c09e5d955b8fafb39d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
" from https://jamesdixon.dev/posts/a-minimal-vimrc/

if filereadable(expand('$VIMRUNTIME/defaults.vim'))
	unlet! g:skip_defaults_vim
	source $VIMRUNTIME/defaults.vim
endif
"
" leader
let maplocalleader = "\\"
let mapleader = ","

" this needs to be here when using vim native package manager:
" https://github.com/dracula/vim/issues/161
"packadd! dracula | colorscheme dracula

" leader
let maplocalleader = "\\"
let mapleader = ","

set novisualbell
set nonumber	"show line numbers
set wildmenu	"enable a menu that shows tab completion options in the status bar
set showmatch	"highlights matching brackets on cursor hover
set ruler	"show cursor position in status bar
set showcmd	"shows the normal mode command before it gets executed
set encoding=utf-8
set fileformats=unix,dos,mac
set nohlsearch	"highlights searches
set incsearch	"incremental search (searches character by character)
set ignorecase	"ignores the case of a search
set smartcase	"only ignores case if there are no capital letters in search (only works after ignorecase has been set)
set tabstop=4		"the amount of spaces that vim will equate to a tab character
set softtabstop=4	"like tabstop, but for editing operations (insert mode)
set splitbelow " split horiz below
set noswapfile
set splitright " split new to the right when doing vertical
set shiftwidth=4	"used for autoindent and << and >> operators in normal mode
set autoindent		"copies indent from current line to the next line
set expandtab		"tabs will expand to whitespace characters
set esckeys		"allows function keys to be recognized in Insert mode
set ttimeoutlen=20	"timeout for a key code mapping
set timeoutlen=1000	"time(ms) to wait for key mappings
set hidden
set number
 
" vim-plug
call plug#begin('~/.vim/plugged')
Plug 'morhetz/gruvbox'
Plug 'sheerun/vim-polyglot'
Plug 'neoclide/coc.nvim', {'branch': 'release'}
Plug 'tpope/vim-commentary'
Plug 'tpope/vim-dispatch'
Plug 'tpope/vim-fugitive'
Plug 'tpope/vim-sensible'
Plug 'tpope/vim-unimpaired'
Plug 'tpope/vim-surround'
Plug 'dense-analysis/ale'
Plug 'vim-test/vim-test'
Plug 'jlanzarotta/bufexplorer'
Plug 'preservim/nerdtree'
Plug 'mhinz/vim-signify'
Plug 'mattn/emmet-vim'
Plug 'junegunn/fzf'
Plug 'junegunn/fzf.vim'
Plug 'SirVer/Ultisnips'
Plug 'honza/vim-snippets'
Plug 'pangloss/vim-javascript'
Plug 'fatih/vim-go', { 'tag': '*' }
Plug 'altercation/vim-colors-solarized'
Plug 'powerman/vim-plugin-AnsiEsc'
Plug 'majutsushi/tagbar'
call plug#end()
 
" vim-test

" use vim-dispatch to run tests in the quickfix window
" from Modern Vim Ch.4
" the mappings below are from vim-test
" https://github.com/vim-test/vim-test
" dispatch opens send test output to quickfix window
" let test#strategy = "vimterminal"
let test#strategy = "basic"
let test#python#runner = "pytest"
let test#vim#term_position = "topleft 10"
" let test#python#pytest#options = '-vvv --tb=short'
let test#python#pytest#options = '--tb=short'
let test#go#runner = 'gotest'
"let test#go#gotest#options = '-v'
" To run mypy using vim-dispath -with Dispatch
autocmd FileType python let b:dispatch = 'mypy --ignore-missing-imports'

nmap <silent> t<C-n> :TestNearest<CR>
nmap <silent> t<C-f> :TestFile<CR>
nmap <silent> t<C-s> :TestSuite<CR>
"nmap <silent> t<C-l> :TestLast<CR>
nmap <silent> <S-F10> :TestLast<CR>
nmap <silent> t<C-g> :TestVisit<CR>

" CoC extensions
let g:coc_global_extensions = ['coc-tsserver', 'coc-pyright', 'coc-html']

" Coc Use `[g` and `]g` to navigate diagnostics
" Coc Use `:CocDiagnostics` to get all diagnostics of current buffer in location list.
nmap <silent> [g <Plug>(coc-diagnostic-prev)
nmap <silent> ]g <Plug>(coc-diagnostic-next)

" CoC GoTo code navigation.
nmap <silent> gd <Plug>(coc-definition)
nmap <silent> gy <Plug>(coc-type-definition)
nmap <silent> gi <Plug>(coc-implementation)
"
" ALE ale config
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_hover_cursor = 1
let g:ale_enabled = 1
let g:ale_sign_column_always = 1
let g:ale_open_list = 0
let g:ale_set_highlights = 0
let g:ale_set_signs = 0
let g:ale_set_loclist = 1
let g:ale_set_quickfix = 0
let g:ale_echo_cursor = 1
let g:ale_echo_msg_error_str = 'Error'
let g:ale_echo_msg_format = '%linter% - %code: %%s'
let g:ale_loclist_msg_format = '%linter% - %code: %%s'
let g:ale_echo_msg_warning_str = 'Warning'
let g:ale_linters = {'python': ['flake8', 'mypy'],
\                    'ocaml': ['merlin'],
\                    'cpp': ['clang'],
\                    'yaml': ['yamllint'],
\                    'c': ['clang'],
\                    'go': ['gopls', 'golint', 'gofmt'],
 \}
let g:ale_fixers = {
\           'python': ['isort', 'yapf', 'black'],
\           'go': ['gofmt'],
\           'rust': ['rustfmt']
\           }
let g:ale_python_mypy_ignore_invalid_syntax = 1
let g:ale_python_mypy_executable = 'mypy'
let g:ale_python_mypy_options = '--config-file mypy.ini'
" let g:ale_sign_error = '>>'
let g:ale_fix_on_save = 1
let g:ale_linters_explicit = 0
nmap <silent> gr <Plug>(coc-references)

" Use K to show documentation in preview window.
nnoremap <silent> K :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
"
"" Quick Editing vimrc
nnoremap <leader>ev <C-w>s<C-w>j<C-w>L:e $MYVIMRC<cr>

" Highlight the symbol and its references when holding the cursor.
autocmd CursorHold * silent call CocActionAsync('highlight')

" clear search highlights
nnoremap <leader><space> :noh<cr>:call clearmatches()<cr>

" previews in netrw
let g:netrw_preview = 1

" journal stuff
autocmd BufNewFile,BufReadPost *.md map <leader>jj <Esc>:r! date +" - \%H:\%M: "<ENTER>kJA<Esc>$<space><Esc> 
autocmd BufNewFile,BufReadPost *.md map <leader>jd <Esc>:r! date +"(\%Y-\%m-\%dT\%H:\%M)"<ENTER>i<backspace><space><Esc>

" switch off Coc with Markdown
autocmd FileType markdown let b:coc_suggest_disable = 1

"syntax on			"turn syntax highlighting on
filetype plugin indent on	"load plugin and indent files associated a detected filetype
runtime macros/matchit.vim	"allows jumping between brackets with % in normal mode

" Go stuff
let g:go_highlight_fields = 1
let g:go_highlight_functions = 1
let g:go_highlight_function_calls = 1
let g:go_highlight_extra_types = 1
let g:go_highlight_operators = 1
let g:go_doc_keywordprg_enabled = 1
let g:go_list_height = 0
let g:go_highlight_operators = 1
let g:go_highlight_function_parameters = 1
let g:go_doc_max_height = 50
let g:go_doc_popup_window = 1
let g:go_list_height = 10


" vim-go debugger window settings
let g:go_debug_windows = {
        \ 'vars':       'leftabove 40vnew',
        \ 'stack':      'leftabove 20new',
        \ 'goroutines': 'botright 10new',
        \ 'out':        'botright 5new',
\ }

" vim-go and gopls
let g:go_def_mode='gopls'
let g:go_info_mode='gopls'
let g:go_play_browser_command = 'firefox %URL% &'
let g:go_test_show_name = 1
let g:go_auto_type_info = 1
let test#go#runner = 'gotest'
let g:go_term_mode = "split"
let g:go_term_height = 50
let g:go_highlight_fields = 1
let g:go_highlight_functions = 1

"autocmd FileType go nmap <leader>r :w<CR>:split <bar> terminal go run %<CR>
autocmd FileType go nmap <leader>R :GoRun<CR>
" highlights the variable in the file for you..
"let g:go_auto_sameids = 1
" auto import...
let g:go_fmt_command = "goimports"
" automatic type info on cursor
let g:go_auto_type_info = 1
let g:go_snippet_engine = "ultisnips"
au Filetype go nmap <leader>ga <Plug>(go-alternate-edit)
au Filetype go nmap <leader>gah <Plug>(go-alternate-split)
au Filetype go nmap <leader>gav <Plug>(go-alternate-vertical)
au FileType go nmap <F8> :GoTestFunc -short<cr>
au FileType go nmap <F10> :GoTest -short<cr>
au FileType go nmap <F9> :DlvToggleBreakpoint<CR>
au FileType go nmap <S-F9> :DlvTest<CR>
au FileType go nmap <F11> :DlvDebug<CR>
au FileType go nmap <S-F5> :GoRename<CR>

" FZF
" This is the default extra key bindings
let g:fzf_action = {
  \ 'ctrl-t': 'tab split',
  \ 'ctrl-x': 'split',
  \ 'ctrl-v': 'vsplit' }

" - FZF Popup window (center of the screen)
let g:fzf_layout = { 'window': { 'width': 0.9, 'height': 0.6 } }

" Customize fzf colors to match your color scheme
let g:fzf_colors =
\ { 'fg':      ['fg', '#f8f8f2'],
  \ 'bg':      ['bg', '#282a36'],
  \ 'hl':      ['fg', '#bd93f9'],
  \ 'fg+':     ['fg', 'CursorLine', 'CursorColumn', 'Normal'],
  \ 'bg+':     ['bg', 'CursorLine', 'CursorColumn'],
  \ 'hl+':     ['fg', 'Statement'],
  \ 'info':    ['fg', '#ffb86c'],
  \ 'prompt':  ['fg', '#50fa7b'],
  \ 'pointer': ['fg', 'Exception'],
  \ 'marker':  ['fg', 'Keyword'],
  \ 'spinner': ['fg', '#ffb86c'],
  \ 'header':  ['fg', '#6272a4'] }
"  More fzf settings
" (https://github.com/zenbro/dotfiles/blob/master/.nvimrc#L151-L187)
 let g:fzf_nvim_statusline = 0 " disable statusline overwriting

" command history is :History:
  nnoremap <C-s> :GFiles!<CR>
  nnoremap <leader><C-p> :<C-u>FZF!<CR>
  nnoremap <leader>t :Files<CR>
  nnoremap <leader>o :Tags<CR>
  nnoremap <leader>h :History<CR>
  nnoremap <silent> <leader>0 :Files<CR>
  nnoremap <silent> <leader>; :BLines<CR>
  nnoremap <silent> <leader>l :Lines<CR>
  nnoremap <silent> <leader>o :BTags<CR>
  nnoremap <silent> <leader>bu :Buffers<CR>
  nnoremap <silent> <leader>? :History:<CR>
  nnoremap <silent> <leader>/ :execute 'Ag ' . input('Ag/')<CR>
  nnoremap <silent> <leader>P :call SearchWordWithAg()<CR>
  vnoremap <silent> <leader>P :call SearchVisualSelectionWithAg()<CR>
  nnoremap <silent> <leader>ft :Filetypes<CR>
  nnoremap <silent> <leader>CC :Commands<CR>
  imap <C-x><C-f> <plug>(fzf-complete-file-ag)
  imap <C-x><C-l> <plug>(fzf-complete-line)

" Search with ripgrep
command! -bang -nargs=* Rg
      \ call fzf#vim#grep(
      \   'rg --column --line-number --no-heading --color=always --ignore-case '.shellescape(<q-args>), 1,
      \   <bang>0 ? fzf#vim#with_preview('up:60%')
      \           : fzf#vim#with_preview('right:50%:hidden', '?'),
      \   <bang>0)

nnoremap <C-p>a :Rg 

"" Quick Editing vimrc
nnoremap <leader>ev <C-w>s<C-w>j<C-w>L:e $MYVIMRC<cr>

" dracula (must be set before colorscheme)
let g:dracula_colorterm = 0
let g:dracula_bold = 1
let g:dracula_italic = 0 " this has to be set to 0 to avoid lots of erroneous highlighting (https://github.com/dracula/vim/issues/219)
let g:dracula_underline = 1

" Colorscheme
"colorscheme dracula
"colorscheme elflord
let g:gruvbox_contrast_dark = 'hard'
set background=dark
colorscheme gruvbox


map <F7> :if exists("g:syntax_on") <Bar>
\   syntax off <Bar>
\ else <Bar>
\   syntax enable <Bar>
\ endif <CR>

augroup general
    autocmd!
    "keep equal proportions when windows resized
    autocmd VimResized * wincmd =
    "save cursor position in a file
    autocmd BufReadPost * if line("'\"") > 1 && line("'\"")
                \ <= line("$") | exe "normal! g'\"" | endif
augroup END

augroup languages
    autocmd!
    autocmd BufNewFile,BufRead *.bash set syntax=sh
    autocmd FileType python xnoremap <leader>r <esc>:'<,'>:w !python3<CR>
    autocmd FileType go set noexpandtab
    autocmd FileType html :syntax sync fromstart
    autocmd FileType html,javascript,css,json,yaml,sh
                \ setlocal ts=2 sts=2 sw=2 expandtab
augroup ENDj

hi Search cterm=NONE ctermfg=black ctermbg=blue
hi Visual cterm=NONE ctermfg=black ctermbg=blue