-
Notifications
You must be signed in to change notification settings - Fork 0
/
.vimrc
executable file
·364 lines (298 loc) · 9.9 KB
/
.vimrc
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
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
set nocompatible
filetype plugin on
let mapleader = ","
"Mappings
"For spellcheck (go to next or previous)
"nnoremap <spaces>s ]s
"nnoremap <space>S [s
"For spellcheck correction
nnoremap z0 z=
"nnoremap <space>g zg
"nnoremap <space>c z=
"""""""""""""""""""""""
" Splits and tabs
"""""""""""""""""""""""
set splitbelow
set splitright
nnoremap <C-J> <C-W><C-J> " Down
nnoremap <C-K> <C-W><C-K> " Up
nnoremap <C-L> <C-W><C-L> " Right
nnoremap <C-H> <C-W><C-H> " Left
:command Pretty %!python -m json.tool
:command Adoc asciidoctor @%
"set backspace=indent,eol,start
set history=1000
set autoread
set hidden
" TMP file options
set directory=$HOME/.vim/swp// "Directory for swap files
set nobackup
set undofile "Mantain undo history between sessions
set undodir=$HOME/.vim/undodir
" User Interface Options
set wildmenu
set number
set mouse=a
set background=dark
set title
set colorcolumn=80
" Indentation options
"set autoindent
"filetype plugin indent on
set tabstop=4
set softtabstop=4
set shiftwidth=4
set expandtab
" Search options
set incsearch
set hlsearch
" Text rendering options
set encoding=utf-8
set linebreak
set scrolloff=3
syntax on
" Open files from the vim explorer
"let g:netrw_liststyle = 3
"let g:netrw_winsize = 20
"let g:netrw_banner = 0
"let g:netrw_browse_split = 1
" Specify a directory for plugins
" - For Neovim: stdpath('data') . '/plugged'
" - Avoid using standard Vim directory names like 'plugin'
" Install plugins via vim +PlugInstall +q +q
" Clean via vim +PlugClean
call plug#begin('~/.vim/plugged')
" Multiple language packs
Plug 'sheerun/vim-polyglot'
" Editorconfig (to share the config of editors across multiple users!)
" https://github.com/editorconfig/editorconfig-vim
Plug 'editorconfig/editorconfig-vim'
" Spell check for vim
Plug 'reedes/vim-lexical'
" Color scheme
Plug 'joshdick/onedark.vim'
Plug 'sonph/onehalf', { 'rtp': 'vim/' }
" IDE like features
Plug 'preservim/nerdtree'
Plug 'tpope/vim-commentary' " gcc for line comment and gc in visual mode
Plug 'dense-analysis/ale'
Plug 'vim-airline/vim-airline' " Best status line
Plug 'vim-airline/vim-airline-themes'
Plug 'tpope/vim-fugitive' " use :G to execute any git command
Plug 'airblade/vim-gitgutter' " Which lines were modified in a file
Plug 'neoclide/coc.nvim', {'branch': 'release'} " vs code like completition
" AI companion
"Plug 'Exafunction/codeium.vim', { 'branch': 'main' }
Plug 'vim-ctrlspace/vim-ctrlspace' " workspace management
Plug 'preservim/tagbar' " File structure (classes, functiuons, methods)
Plug 'habamax/vim-asciidoctor'
Plug 'rust-lang/rust.vim'
Plug 'tpope/vim-dispatch' " Async background tasks (for tests for example)
" Initialize plugin system
call plug#end()
" Codeium AI companion
"set statusline+=%3{codeium#GetStatusString()}
let g:codeium_disable_bindings = 1
imap <script><silent><nowait><expr> <C-g> codeium#Accept()
imap <C-;> <Cmd>call codeium#CycleCompletions(1)<CR>
imap <C-,> <Cmd>call codeium#CycleCompletions(-1)<CR>
imap <C-x> <Cmd>call codeium#Clear()<CR>
let g:rustfmt_autosave = 1
let g:rustfmt_emit_files = 1
let g:rustfmt_fail_silently = 0
"colorscheme onedark
syntax on
set t_Co=256
set cursorline
colorscheme onehalfdark
let g:airline_theme='onehalfdark'
if exists('+termguicolors')
let &t_8f = "\<Esc>[38;2;%lu;%lu;%lum"
let &t_8b = "\<Esc>[48;2;%lu;%lu;%lum"
set termguicolors
endif
" Better comments for dark env
highlight Comment ctermfg=252 ctermbg=236 guifg=#919baa guibg=#282c34
highlight CocInlayHint ctermfg=100 ctermbg=236 guifg=#958862 guibg=#282c34
" air-line
" let g:airline_powerline_fonts = 1
if !exists('g:airline_symbols')
let g:airline_symbols = {}
endif
" powerline symbols
let g:airline_left_sep = ''
let g:airline_left_alt_sep = ''
let g:airline_right_sep = ''
let g:airline_right_alt_sep = ''
let g:airline_symbols.branch = ''
let g:airline_symbols.readonly = ''
let g:airline_symbols.linenr = ''
"let g:airline_symbols.maxlinenr = ''
let g:EditorConfig_exclude_patterns = ['fugitive://.*', 'scp://.*']
" Set ctrlspace settings
" needed for nvim
let g:CtrlSpaceDefaultMappingKey = "<C-space> "
nnoremap <silent><C-p> :CtrlSpace O<CR>
" Remove it if it does not work for you
"if has('win32')
" let s:vimfiles = '~/vimfiles'
" let s:os = 'windows'
"else
" let s:vimfiles = '~/.vim'
" if has('mac') || has('gui_macvim')
" let s:os = 'darwin'
" else
" " elseif has('gui_gtk2') || has('gui_gtk3')
" let s:os = 'linux'
" endif
"endif
"
"let g:CtrlSpaceFileEngine = s:vimfiles . '/plugged/vim-ctrlspace' . '/bin/file_engine_' . s:os . '_amd64'
set wildignore+=*/node_modules/*,_site,*/__pycache__/,*/venv/*,*/target/*,*/.vim$,\~$,*/.log,*/.aux,*/.cls,*/.aux,*/.bbl,*/.blg,*/.fls,*/.fdb*/,*/.toc,*/.out,*/.glo,*/.log,*/.ist,*/.fdb_latexmk
" vim-lexical
" See https://linuxhint.com/vim_spell_check/
" and https://web.archive.org/web/20200313074256/https://linuxhint.com/vim_spell_check/
let g:lexical#spell = 1
augroup lexical
autocmd!
autocmd FileType markdown,mkd call lexical#init()
autocmd FileType asciidoc call lexical#init()
autocmd FileType html,html.tmpl call lexical#init()
autocmd FileType textile call lexical#init()
autocmd FileType text call lexical#init({ 'spell': 0 })
augroup END
let g:lexical#spelllang = ['en_us']
let g:lexical#thesaurus = ['~/.vim/thesaurus/moby_thesaurus.txt',]
let g:lexical#spellfile = ['~/.vim/spell/en.utf-8.add',]
""""""""""""""""""""""""""
" Directory tree
""""""""""""""""""""""""""
" Focus via \n
nnoremap <leader>n :NERDTreeFocus<CR>
nnoremap <C-n> :NERDTree<CR>
nnoremap <C-f> :NERDTreeFind<CR>
" Start NERDTree and put the cursor back in the other window.
autocmd VimEnter * NERDTreeFind | wincmd p
" Exit Vim if NERDTree is the only window remaining in the only tab.
autocmd BufEnter * if tabpagenr('$') == 1 && winnr('$') == 1 && exists('b:NERDTree') && b:NERDTree.isTabTree() | quit | endif
let NERDTreeShowHidden=1
" From https://stackoverflow.com/questions/6624043/how-to-open-or-close-nerdtree-and-tagbar-with-leader
function! ToggleNERDTreeAndTagbar()
let w:jumpbacktohere = 1
" Detect which plugins are open
if exists('t:NERDTreeBufName')
let nerdtree_open = bufwinnr(t:NERDTreeBufName) != -1
else
let nerdtree_open = 0
endif
let tagbar_open = bufwinnr('__Tagbar__') != -1
" Perform the appropriate action
if nerdtree_open && tagbar_open
NERDTreeToggle "NERDTreeClose
TagbarClose
elseif nerdtree_open
TagbarOpen
elseif tagbar_open
NERDTreeToggle "NERDTree
else
NERDTreeToggle "NERDTree
TagbarOpen
endif
" Jump back to the original window
for window in range(1, winnr('$'))
execute window . 'wincmd w'
if exists('w:jumpbacktohere')
unlet w:jumpbacktohere
break
endif
endfor
endfunction
nnoremap <C-t> :call ToggleNERDTreeAndTagbar()<CR>
nnoremap <leader>t :call ToggleNERDTreeAndTagbar()<CR>
" To avoid issues when closing
" See https://github.com/preservim/tagbar/issues/869
"autocmd QuitPre * qall
""""""""""""""""""""""""""""
" Linting
""""""""""""""""""""""""""""
" See coc.vim
"
""""""""""""""""""""""""""""
" Git
""""""""""""""""""""""""""""
" ,gd for git diff
function GitDiff()
:silent write
:silent execute '!git diff --color=always -- "' . expand('%:p') . '" | less --RAW-CONTROL-CHARS'
:redraw!
endfunction
nnoremap <leader>gd :call GitDiff()<cr>
let g:airline#extensions#tabline#enabled = 1
let g:airline#extensions#tabline#buffer_nr_show = 1
:call tagbar#autoopen(0)
" Fold for long files
set foldmethod=indent
set foldnestmax=2
nnoremap <space> za
vnoremap <space> zf
"""""""""""""""""""""""""""""""""""""""""
" Conquer of Completion plugin (IDE-like)
"""""""""""""""""""""""""""""""""""""""""
" Some servers have issues with backup files, see #649.
set nowritebackup
" Give more space for displaying messages.
set cmdheight=2
" Having longer updatetime (default is 4000 ms = 4 s) leads to noticeable
" delays and poor user experience.
set updatetime=300
" Don't pass messages to |ins-completion-menu|.
set shortmess+=c
source ~/.vim/coc.vim
let g:my_coc_file_types = ['c', 'cpp', 'h', 'java', 'scala', 'vim', 'sh', 'py', 'rs']
"function! s:disable_coc_for_type()
" if index(g:my_coc_file_types, &filetype) == -1
" :silent! CocDisable
" else
" :silent! CocEnable
" endif
"endfunction
"
"augroup CocGroup
" autocmd!
" autocmd BufNew,BufEnter * call s:disable_coc_for_type()
"augroup end
"""""""""""""""""""""""""""""""
" Asciidoctor
"""""""""""""""""""""""""""""""
"let g:asciidoctor_executable = 'asciidoctor'
let g:asciidoctor_extensions = ['asciidoctor-diagram']
"let g:asciidoctor_pdf_executable = 'asciidoctor-pdf'
let g:asciidoctor_pdf_extensions = ['asciidoctor-diagram']
" List of filetypes to highlight, default `[]`
let g:asciidoctor_fenced_languages = ['python', 'scala', 'javascript']
" Function to create buffer local mappings and add default compiler
fun! AsciidoctorMappings()
"nnoremap <buffer> <leader>oo :AsciidoctorOpenRAW<CR>
"nnoremap <buffer> <leader>op :AsciidoctorOpenPDF<CR>
"nnoremap <buffer> <leader>oh :AsciidoctorOpenHTML<CR>
"nnoremap <buffer> <leader>ox :AsciidoctorOpenDOCX<CR>
nnoremap <buffer> <leader>ch :Dispatch :Asciidoctor2HTML<CR>
nnoremap <buffer> <leader>cp :Dispatch :Asciidoctor2PDF<CR>
"nnoremap <buffer> <leader>cx :Asciidoctor2DOCX<CR>
nnoremap <buffer> <leader>p :AsciidoctorPasteImage<CR>
" :make will build pdfs
compiler asciidoctor2pdf
xnoremap <leader>b xi**<Esc>Pgv
xnoremap <leader>i xi__<Esc>Pgv
set tabstop=2
set softtabstop=2
set shiftwidth=2
endfun
" Call AsciidoctorMappings for all `*.adoc` and `*.asciidoc` files
augroup asciidoctor
au!
au BufEnter *.adoc,*.asciidoc call AsciidoctorMappings()
augroup END
"augroup ON_ASCIIDOCTOR_SAVE | au!
" au BufWritePost *.adoc :Dispatch :Asciidoctor2HTML
"augroup end