aboutsummaryrefslogtreecommitdiff
path: root/dotfiles/.config/nvim/init.vim
blob: 21371638a57f556f9763aa145bd83b0a6815165a (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
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
let mapleader = ","

" Check if vim-plug is installed, otherwise download and install
if empty(glob('~/.local/share/nvim/site/autoload/plug.vim'))
	silent !curl -fLo ~/.local/share/nvim/site/autoload/plug.vim --create-dirs
	\ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
	autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
endif

call plug#begin('~/.local/share/nvim/site/plugged')
	Plug 'junegunn/goyo.vim'
	Plug 'PotatoesMaster/i3-vim-syntax'
	Plug 'tpope/vim-commentary'
	Plug 'junegunn/fzf'
	Plug 'junegunn/fzf.vim'
	Plug 'preservim/nerdtree'
	Plug 'ervandew/supertab'
	Plug 'jamessan/vim-gnupg'
	Plug 'majutsushi/tagbar'
	Plug 'rust-lang/rust.vim'
	Plug 'cespare/vim-toml'
	Plug 'pangloss/vim-javascript'
	Plug 'ap/vim-css-color'
	Plug 'https://gitlab.com/HiPhish/info.vim'
	Plug 'rhysd/git-messenger.vim'
	Plug 'tpope/vim-ragtag'
	Plug 'tpope/vim-fugitive'
	Plug 'mmarchini/bpftrace.vim'
	Plug 'junkblocker/git-time-lapse'
	Plug 'tikhomirov/vim-glsl'
	Plug 'aklt/plantuml-syntax'
	if has('nvim-0.6')
		Plug 'neovim/nvim-lspconfig'
		Plug 'ojroques/nvim-lspfuzzy'
	endif
	if has('nvim-0.9')
		Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'}
	endif
call plug#end()

" Some basics:
	set nocompatible
	filetype plugin on
	syntax on
	set foldmethod=syntax
	set omnifunc=syntaxcomplete#Complete
	set completeopt=menuone,noinsert
	set guicursor=n-v-sm:block,i-ci-c-ve:ver25,r-cr-o:block
	set cursorline
	set redrawtime=1000
	set relativenumber
	set scrolloff=5
	set colorcolumn=+1
	set textwidth=80
	set mouse=a
	set number

" Colors
	let g:ultramar_italic=1
	let g:ultramar_opaque_bg=0
	colorscheme ultramar
	if $COLORSCHEME == "light"
		set background=light
	endif
	set termguicolors
	function! ChangeBG()
		if &background == "light"
			set background=dark
			return
		endif
		set background=light
	endfunction
	map <F10> :call ChangeBG()<CR>
	autocmd Signal SIGUSR1 call ChangeBG()
	let g:markdown_fenced_languages = ['c', 'go', 'sh', 'bash=sh', 'python', 'html', 'css', 'javascript']

" Set screen title
	set title
	" let &titlestring = "NVIM - " . expand("%:t")
	" if &term == "screen"
	" 	set t_ts=^[k
	" 	set t_fs=^[\
	" endif
	" au BufEnter * let &titlestring = "NVIM - " . expand("%t")

" Functions for git branch name on statusline
	function! GitBranch()
	return system("git rev-parse --abbrev-ref HEAD 2>/dev/null | tr -d '\n'")
	endfunction
	function! StatuslineGit()
	let l:branchname = GitBranch()
	return strlen(l:branchname) > 0?'   '.l:branchname.' ':''
	endfunction

" git-messenger settings
	let g:git_messenger_floating_win_opts = { 'border': 'single' }
	let g:git_messenger_popup_content_margins = v:false
	hi! link diffAdded DiffAdd
	hi! link diffRemoved DiffDelete
	hi! link diffWordsAdded DiffText
	hi! link diffWordsRemoved DiffText

" Statusline
	let laststatus=2
	set statusline=
	set statusline+=%#SignColumn#
	set statusline+=%{StatuslineGit()}
	set statusline+=%#StatusLine#
	set statusline+=%<
	set statusline+=\ %f%r%m
	set statusline+=%=
	set statusline+=\ %l/%L,%c%V
	set statusline+=\ 
	set statusline+=%#StatusLineNC#
	set statusline+=\ %Y
	set statusline+=\ %{&fileencoding?&fileencoding:&encoding}
	set statusline+=\[%{&fileformat}\]
	set statusline+=\ 

" default indentation
	filetype plugin indent on
	set noexpandtab
	set copyindent
	set preserveindent
	set softtabstop=0
	set tabstop=4
	set shiftwidth=4

" Splits open at the bottom and right, which is non-retarded, unlike vim defaults.
	set splitbelow
	set splitright

" To avoid switching between keyboards
	set langmap=ФИСВУАПРШОЛДЬТЩЗЙКЫЕГМЦЧНЯХЪБЮ;ABCDEFGHIJKLMNOPQRSTUVWXYZ{}<>,фисвуапршолдьтщзйкыегмцчняхъэ;abcdefghijklmnopqrstuvwxyz[]'

" Toggle relative line numbers
	map <leader>e :set invrelativenumber<CR>
	map <leader>у :set invrelativenumber<CR>

" Shortcutting split navigation, saving a keypress:
	map <C-h> <C-w>h
	map <C-j> <C-w>j
	map <C-k> <C-w>k
	map <C-l> <C-w>l

" Open the selected text in a split (i.e. should be a file).
	map <leader>o "oyaW:sp <C-R>o<CR>
	xnoremap <leader>o "oy<esc>:sp <C-R>o<CR>
	vnoremap <leader>o "oy<esc>:sp <C-R>o<CR>

" Replace all is aliased to S.
	nnoremap S :%s//g<Left><Left>
	nnoremap Ы :%s//g<Left><Left>

" Compile document
	map <leader>c :!doccompiler <c-r>%<CR>
	map <leader>с :!doccompiler <c-r>%<CR>

" Spell-check set to F2:
	map <F2> :setlocal spell! spelllang=en_us,es,ru<CR>

" Save changes
	noremap <leader>s :update<CR>
	noremap <leader>ы :update<CR>

" Copy to clipboard
	vnoremap  <leader>y  "+y
	nnoremap  <leader>Y  "+yg_
	nnoremap  <leader>y  "+y
	nnoremap  <leader>yy  "+yy
	vnoremap  <leader>н  "+y
	nnoremap  <leader>Н  "+yg_
	nnoremap  <leader>н  "+y
	nnoremap  <leader>нн  "+yy

" Copy everything in the buffer to clipboard
	nnoremap <leader>ya :%y +<CR>
	nnoremap <leader>нф :%y +<CR>

" Paste from clipboard
	nnoremap <leader>p "+p
	nnoremap <leader>P "+P
	vnoremap <leader>p "+p
	vnoremap <leader>P "+P
	nnoremap <leader>з "+p
	nnoremap <leader>З "+P
	vnoremap <leader>з "+p
	vnoremap <leader>З "+P

" Enable autocompletion:
	set wildmode=list:longest,full
	set wildmenu

" Automatically deletes all tralling whitespace on save.
	"autocmd BufWritePre * %s/\s\+$//e

" Runs a script that cleans out tex build files whenever I close out of a .tex file.
	autocmd VimLeave *.tex !texclear %

" Disables automatic commenting on newline:
	autocmd FileType * setlocal formatoptions-=o

" C-T for new tab
	nnoremap <C-t> :tabe<Space>

" Navigating with guides
	inoremap <leader><Tab> <Esc>/<++><Enter>"_c4l
	vnoremap <leader><Tab> <Esc>/<++><Enter>"_c4l
	map <leader><Tab> <Esc>/<++><Enter>"_c4l
	inoremap ;gui <++>
	inoremap жпгш <++>
	inoremap ñgui <++>

" Replace ex mode with gq
	map Q gq
" with russian layout
	map Й gq

" For normal mode when can't remap caps to escape
	inoremap jw <Esc>
	inoremap wj <Esc>

" SuperTab
	let g:SuperTabDefaultCompletionType = "context"
	let g:SuperTabContextDefaultCompletionType = "<c-x><c-o>"

" NERDTree
	map <leader>r :NERDTreeToggle<CR>
	map <leader>к :NERDTreeToggle<CR>

" FZF
	let g:fzf_preview_window = ['hidden,right,50%,<70(hidden,up,40%)', 'ctrl-\']
	map <leader>f :Files<CR>
	map <leader>а :Files<CR>
	map <leader>F :Rg 
	map <leader>А :Rg 

" Open new terminal in current directory
	map <leader>t :!setsid $TERMINAL &<CR>
	map <leader>е :!setsid $TERMINAL &<CR>

" Tagbar
	map <F3> :TagbarToggle<CR>

" Goyo
	let g:goyo_width = 100
	let g:goyo_linenr = 1
	map <leader>gg :Goyo<CR>

" Insert datetime
	map <leader>d :r!date +"\%Y-\%m-\%dT\%H:\%M:\%S"<CR>kJ
	map <leader>в :r!date +"\%Y-\%m-\%dT\%H:\%M:\%S"<CR>kJ

" Hack to open all folds in current scope recursively
	nmap <leader>z zCzO
	nmap <leader>я zCzO

" LSP
	if has('nvim-0.6')
		set omnifunc=v:lua.vim.lsp.omnifunc
		source ~/.config/nvim/lua.lua
	endif


" LSP keybinds
	nmap <silent> gd <cmd>lua vim.lsp.buf.definition()<CR>
	nmap <silent> gD <cmd>lua vim.lsp.buf.declaration()<CR>
	nmap <silent> gK <cmd>lua vim.lsp.buf.hover()<CR>
	nmap <silent> gz <cmd>lua vim.lsp.buf.references()<CR>
	nmap <silent> <leader>n <cmd>lua vim.lsp.buf.rename()<CR>
	nmap <silent> <leader>b <cmd>lua vim.lsp.buf.format()<CR>
	nmap <silent> <leader>a <cmd>lua vim.lsp.buf.code_action()<CR>
	nmap <silent> <leader>qw <cmd>lua vim.lsp.buf.workspace_symbol()<CR>
	nmap <silent> <leader>qd <cmd>lua vim.lsp.buf.document_symbol()<CR>
	nmap <silent> <leader>l <cmd>lua vim.diagnostic.setloclist()<CR>
	nmap <silent> ]g <cmd>lua vim.diagnostic.goto_next()<CR>
	nmap <silent> [g <cmd>lua vim.diagnostic.goto_prev()<CR>

" Treesitter
	if has('nvim-0.9')
		" XXX: neovim's built-in C et al treesitter parsers are better, although
		" not ideal either.
		lua require('nvim-treesitter.configs').setup{ ensure_installed = {  "go", "rust", "python", "lua", "comment", "zig" }, highlight = { enable = true, disable = { "c", "cpp", "vim", "make" } }}
		set foldmethod=expr
		set foldexpr=nvim_treesitter#foldexpr()
	endif

" Termdebugger keybinds
	nmap <silent> <leader>gn <cmd>:Over<CR>
	nmap <silent> <leader>gs <cmd>:Step<CR>
	nmap <silent> <leader>gc <cmd>:Continue<CR>
	nmap <silent> <leader>gu <cmd>:Until<CR>
	nmap <silent> <leader>gb <cmd>:Break<CR>
	nmap <silent> <leader>gC <cmd>:Clear<CR>

" File format preferences
	" MFing neovim overrding my omnifunc with whatever ccomplete is
	autocmd FileType c,ch,header,cpp setlocal omnifunc=v:lua.vim.lsp.omnifunc fdm=syntax
	" No, Rust, spaces is not superior to tabs, 100 lines is too much
	autocmd FileType rust, meson setlocal noet ci pi sts=0 ts=4 sw=4 tw=80
	autocmd FileType mail setlocal spell spelllang=en_us,es,ru tw=72 |
				\ let b:SuperTabContextDefaultCompletionType = "<c-p>"
	autocmd FileType text,tex,markdown,html,rst setlocal spell spelllang=en_us,es,ru tw=80 |
				\ let b:SuperTabContextDefaultCompletionType = "<c-p>"
	" Having this on is a retarded default
	let g:zig_fmt_autosave = 0

" C indentation rules
	set cino=:0l1

" For project-specific configuration
	set exrc
	set secure