summaryrefslogtreecommitdiff
path: root/nvim/init.vim
blob: 4957a6e594a5f4b6f54d045490735e24ca3053b0 (plain)
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
"line numbers
set nu
"unix newlines
set ff=unix
"set the highlight column at 80
set colorcolumn=80
" displace spaces, tabs, and newlines
set list
set listchars=tab:→\ ,space:·,nbsp:␣,trail:•,eol,precedes:«,extends:»
"2 lines of cmd, needed for echodoc
set cmdheight=2
if has('win32')
	source $VIMRUNTIME/mswin.vim
endif
let g:python3_host_prog='python3'

call plug#begin('~/.vim/plugged')

"Formatting and navigation
Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' }
Plug 'scrooloose/nerdcommenter'
Plug 'godlygeek/tabular'

"Git
Plug 'xuyuanp/nerdtree-git-plugin'
Plug 'tpope/vim-fugitive'

"Fuzzy file search
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
Plug 'junegunn/fzf.vim'

"tab completion
Plug 'Shougo/denite.nvim'
Plug 'Shougo/deoplete.nvim', { 'do': ':UpdateRemotePlugins' }
Plug 'Shougo/echodoc.vim'
Plug 'deoplete-plugins/deoplete-jedi'
Plug 'raimon49/requirements.txt.vim'

" Scala tab completion
"Plug 'nvim-lua/plenary.nvim'
"Plug 'scalameta/nvim-metals'

" CSV formatting
Plug 'chrisbra/csv.vim'

" Lua, Moonscript, Teal
Plug 'xolox/vim-misc'
Plug 'xolox/vim-lua-ftplugin'
Plug 'VaiN474/vim-etlua'
Plug 'leafo/moonscript-vim'
Plug 'teal-language/vim-teal'

"Plug 'whonore/Coqtail'

"Color schemes
Plug 'mhartington/oceanic-next'
Plug 'vim-scripts/Wombat'
Plug 'zeis/vim-kolor'
Plug 'alessandroyorba/despacio'
Plug 'alessandroyorba/alduin'
Plug 'tomasr/molokai'
Plug 'sainnhe/vim-color-forest-night'
Plug 'sts10/vim-pink-moon'
Plug 'severij/vadelma'
Plug 'kkpmw/sacredforest-vim'
Plug 'jsit/toast.vim'
Plug 'henrynewcomer/vim-theme-papaya'
Plug 'sainnhe/edge'
Plug 'kjssad/quantum.vim'
Plug 'kyoz/purify'
Plug 'jonathanfilip/vim-lucius'
Plug 'joshdick/onedark.vim'
Plug 'cocopon/iceberg.vim'
Plug 'wolf-dog/sceaduhelm.vim'
Plug 'danilo-augusto/vim-afterglow'
Plug 'kamwitsta/mythos'
Plug 'softmotions/vim-dark-frost-theme'
Plug 'ghifarit53/tokyonight-vim'

"Icons, requires a nerd font
Plug 'ryanoasis/vim-devicons'

" Terraform
"Plug 'hashivim/vim-terraform'
call plug#end()

colorscheme onedark

"deoplete
let g:deoplete#enable_at_startup = 1
inoremap <silent><expr> <TAB> pumvisible() ? "\<C-n>" : <SID>check_back_space() ? "\<TAB>" : deoplete#manual_complete()
function s:check_back_space() abort "{{{
	let col = col('.') - 1
	return !col || getline('.')[col-1] =~ '\s'
endfunction"}}}
autocmd CompleteDone * if pumvisible() == 0 | silent! pclose | endif

" echodoc
let g:echodoc#enable_at_startup=1
let g:echodoc#type="floating"
highlight link EchoDocFloat Pmenu

"python
let g:deoplete#sources#jedi#python_path='python3'
let g:deoplete#sources#jedi#enable_short_types=1
let g:deoplete#sources#jedi#show_docstring=1
call deoplete#custom#source('jedi','max_info_width',0)
set completeopt-=preview

"lua
let g:lua_compiler_name='lua'
"let g:lua_compiler_name='lua'
let g:lua_complete_dynamic=1
let g:lua_complete_keywords=0
au BufReadPost *.busted set syntax=lua
au BufReadPost *.spec set syntax=lua
au BufReadPost *.etlua set syntax=html
"Overwrite xolox:ftplugin's "Help" with shift-k
au BufReadPost *.lua nunmap <buffer> K

"scala
augroup lsp
  au!
  au FileType java,scala,sbt lua m=require("metals"); mc=m.bare_config(); mc.init_options.statusBarProvider="on"; m.initialize_or_attach(mc)
augroup end

"NERDTree config
autocmd BufEnter * if tabpagenr('$') == 1 && winnr('$') == 1 && exists('b:NERDTree') && b:NERDTree.isTabTree() |
	\ quit | endif


nnoremap <C-\> :NERDTreeToggle<Cr>
nnoremap <C-r> :NERDTreeFind<Cr>
let NERDTreeMapHelp='y'
let NERDTreeMapJumpLastChild='y'
let NERDTreeMapJumpFirstChild='y'

"NERDCommenter config
nnoremap <C-/> :call NERDComment('x', 'toggle')<CR>

"Fuzzy file search
let g:fzf_layout = { 'window': {'width': 0.9, 'height': 0.6} }
noremap <A-p> :call fzf#run(fzf#wrap({'sink': 'tabe', 'left': '20%', 'source': 'git ls-files'}))<Cr>
noremap <C-p> :call fzf#run(fzf#wrap({'sink': 'vsplit', 'left': '50%', 'source': 'git ls-files'}))<Cr>

"Fuzzy git checkout branch
noremap <C-c> :call fzf#run(fzf#wrap({'sink': 'Git checkout', 'left':'20%', 'source': 'git branch --format "%(refname:short)"'}))<Cr>
noremap <C-a> :call fzf#run(fzf#wrap({'sink': 'Git checkout', 'left':'50%', 'source': 'ag --nogroup --column --color --', 'preview-window':'up','preview':expand('<sfile>:p:h:h:h').'/bin/preview.sh'}))<Cr>


"Fuzzy sbt
function! s:VTerm(command)
	vsplit
	termopen(a:command)
endfunction

"ctrl+s saves
nmap <C-s> :w<Cr>

"For some reason this is different between linux and windows
if has('win32')
	vmap <C-/> <leader>c<Space>
else
	vmap <C-_> <leader>c<Space>
endif

"Set leader
let mapleader=";"

"Shortcut to modify vim config
nnoremap <leader>ec :tabe $MYVIMRC<Cr>

"Move around quickly
nnoremap J 5j
nnoremap K 5k
nnoremap H 5h
nnoremap L 5l

"Navigate splits
tnoremap <A-h> <C-\><C-n><C-w>h
tnoremap <A-j> <C-\><C-n><C-w>j
tnoremap <A-k> <C-\><C-n><C-w>k
tnoremap <A-l> <C-\><C-n><C-w>l

nnoremap <A-h> <C-\><C-n><C-w>h
nnoremap <A-j> <C-\><C-n><C-w>j
nnoremap <A-k> <C-\><C-n><C-w>k
nnoremap <A-l> <C-\><C-n><C-w>l

"Resize splits
"noremap <C-h> :vertical resize -5<Cr>
"noremap <C-l> :vertical resize +5<Cr>
"noremap <C-j> :res +5<Cr>
"noremap <C-k> :res -5<Cr>

function! s:HasNeighbor(direction)
	return winnr() != winnr(a:direction)
endfunction

function! s:PushResize(direction, amount)
	if a:direction == 'l' || a:direction == 'h'
		let l:cmd = 'vertical resize'
	else
		let l:cmd = 'resize'
	endif

	if s:HasNeighbor(a:direction)
		let l:amount = '+'.a:amount
	else
		let l:amount = '-'.a:amount
	endif

	echo l:cmd . ' ' . l:amount
	execute l:cmd . ' ' . l:amount
endfunction

nnoremap <C-h> :call <SID>PushResize('h',5)<CR>
nnoremap <C-j> :call <SID>PushResize('j',5)<CR>
nnoremap <C-k> :call <SID>PushResize('k',5)<CR>
nnoremap <C-l> :call <SID>PushResize('l',5)<CR>

"Navigate tabs
noremap <C-]> gt
noremap <C-[> gT

"Add a semicolon at the end of the line
vnoremap <C-;> :'<,'>s/\([^;]\)$/\1;/g<Cr>

"Vertical split and make
noremap <C-b> :vsplit term://make all<Cr>

"Start a terminal
noremap <C-t> :vsplit<CR>:terminal<CR>

"Find and open in a new tab
noremap <C-f> :Ag<Cr>

"Restart vim (alt+1)
noremap <A-1> :source $MYVIMRC \| :PlugInstall<Cr>

filetype plugin indent on
syntax enable

"Unmap a bunch of stuff set by lunarvim
if has_key(environ(), "LUNARVIM_BASE_DIR")
	lua lvim.builtin.which_key.mappings.e = nil
	lua lvim.lsp.buffer_mappings.normal_mode.K = nil
	let $MYVIMRC=$LUNARVIM_BASE_DIR . "\\vimrc.vim"
	nmap <C-Bslash> :NvimTreeToggle<CR>
	vunmap <C-/>
	vmap <C-/> :call NERDComment('x', 'toggle')<CR>
	nnoremap <C-/> :call nerdcommenter#Comment('x', 'toggle')<CR>
endif