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
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
|
set nocompatible
syn on
set maxmempattern=32000
" because https://github.com/vim/vim/issues/6777#issuecomment-684776825
" Because Konsole font size
" https://github.com/neovim/neovim/issues/6798
set guicursor=
set nocscopeverbose
set ignorecase
set smartcase
set modeline
set modelines=5
set wildmode=longest:full
set wildmenu
set hlsearch
set pastetoggle=<F10>
set textwidth=120
set backspace=eol,indent,start
set number
set signcolumn=yes
"set mouse=a "Disabled
"set grepprg=grep\ -nH\ $*
set grepprg=rg\ --vimgrep\ $*
let g:tex_flavor = "latex"
setglobal formatoptions+=j
" so that :find and :tabfind work
set path=$PWD/**
" in visual mode, show count
set showcmd
set scrolloff=3
" persistent-undo
set undodir=~/.vim/undodir
set undofile
" remove toolbar
set guioptions-=T
" remove menu
set guioptions-=m
set formatoptions+=j " Delete comment character when joining commented lines
set history=1000
set tabpagemax=50
let mapleader="\<Space>"
call plug#begin('~/.vim/plugged')
Plug 'mileszs/ack.vim'
Plug 'airblade/vim-gitgutter'
Plug 'vim-scripts/git-time-lapse'
Plug 'vim-scripts/ifdef-highlighting'
Plug 'jparise/vim-graphql'
Plug 'ctrlpvim/ctrlp.vim'
Plug 'rust-lang/rust.vim'
Plug 'scrooloose/nerdtree'
Plug 'majutsushi/tagbar'
Plug 'vim-scripts/taglist.vim'
Plug 'tpope/vim-fugitive'
Plug 'https://gitlab.com/Nate_B/vim-adif'
Plug 'hashivim/vim-terraform'
if has("nvim")
Plug 'neovim/nvim-lspconfig'
endif
"Plug 'neoclide/coc.nvim', {'branch': 'release'}
call plug#end()
" dotnet tool install -g csharp-ls
if has("nvim")
lua << EOF
local nvim_lsp = require('lspconfig')
-- For debugging, use :LspInfo
--vim.lsp.set_log_level("debug")
-- Retrieve logs using :lua vim.cmd('e'..vim.lsp.get_log_path())
vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(
vim.lsp.diagnostic.on_publish_diagnostics, {
signs = false,
}
)
-- Use an on_attach function to only map the following keys
-- after the language server attaches to the current buffer
local on_attach = function(client, bufnr)
local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end
local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end
-- Enable completion triggered by <c-x><c-o>
buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc')
-- Mappings.
local opts = { noremap=true, silent=true }
-- See `:help vim.lsp.*` for documentation on any of the below functions
buf_set_keymap('n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<CR>', opts)
buf_set_keymap('n', '<Leader>D', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts)
buf_set_keymap('n', 'gd', '<cmd>lua vim.lsp.buf.definition()<CR>', opts)
buf_set_keymap('n', 'gK', '<cmd>lua vim.lsp.buf.hover()<CR>', opts)
buf_set_keymap('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', opts)
buf_set_keymap('n', '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts)
--buf_set_keymap('n', '<Leader>wa', '<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>', opts)
--buf_set_keymap('n', '<Leader>wr', '<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>', opts)
--buf_set_keymap('n', '<Leader>wl', '<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>', opts)
buf_set_keymap('n', '<F2>', '<cmd>lua vim.lsp.buf.rename()<CR>', opts)
buf_set_keymap('n', '<Leader>c', '<cmd>lua vim.lsp.buf.code_action()<CR>', opts)
buf_set_keymap('n', '<Leader>r', '<cmd>lua vim.lsp.buf.references()<CR>', opts)
buf_set_keymap('n', '<Leader>e', '<cmd>lua vim.lsp.diagnostic.show_line_diagnostics()<CR>', opts)
buf_set_keymap('n', '[d', '<cmd>lua vim.lsp.diagnostic.goto_prev()<CR>', opts)
buf_set_keymap('n', ']d', '<cmd>lua vim.lsp.diagnostic.goto_next()<CR>', opts)
buf_set_keymap('n', '<Leader>q', '<cmd>lua vim.lsp.diagnostic.set_loclist()<CR>', opts)
buf_set_keymap('n', '<Leader>F', '<cmd>lua vim.lsp.buf.formatting()<CR>', opts)
end
-- Use a loop to conveniently call 'setup' on multiple servers and
-- map buffer local keybindings when the language server attaches
local servers = { 'clangd', 'rust_analyzer', 'pylsp', 'tsserver' }
for _, lsp in ipairs(servers) do
nvim_lsp[lsp].setup {
on_attach = on_attach,
flags = {
debounce_text_changes = 150,
}
}
end
EOF
endif
if executable('rg')
let g:ackprg = "rg -ui --vimgrep"
let g:ack_default_options = " -ui --vimgrep"
elseif executable('ag')
let g:ackprg = 'ag -u --vimgrep'
endif
noremap <Leader>a :LAck! -t rust -t cpp -t c -t py <cword><CR>
noremap <Leader>A :LAck! <cword><CR>
"Show + - ~ in the margin for vim modification
let g:gitgutter_eager = 0 " only update on read/write
" Also search tags
let g:ctrlp_extensions = ['tag']
noremap <Leader>p :CtrlP<CR>
noremap <Leader>b :CtrlPBuffer<CR>
"let g:ctrlp_working_path_mode = 'a'
" Ignore some folders and files for CtrlP indexing
let g:ctrlp_custom_ignore = { 'dir': '\.git$\|\CODENAME_Data' }
"rust-lang/rust.vim
let g:rust_recommended_style = 0
au FileType rust nmap <Leader>m :make build<CR>
au FileType rust nmap <Leader>c :Cargo check<CR>
noremap <Leader>t :TagbarToggle<CR>
colorscheme bramwombat
function! ToggleFullScreen()
call system("wmctrl -i -r ".v:windowid." -b toggle,fullscreen")
redraw
endfunction
if has("nvim")
set termguicolors
set noincsearch
tnoremap <Esc> <C-\><C-n>
let g:terminal_color_0 = '#2e3436'
let g:terminal_color_1 = '#cc0000'
let g:terminal_color_2 = '#4e9a06'
let g:terminal_color_3 = '#c4a000'
let g:terminal_color_4 = '#4475b4'
let g:terminal_color_5 = '#75507b'
let g:terminal_color_6 = '#0b939b'
let g:terminal_color_7 = '#d3d7cf'
let g:terminal_color_8 = '#555753'
let g:terminal_color_9 = '#ef2929'
let g:terminal_color_10 = '#8ae234'
let g:terminal_color_11 = '#fce94f'
let g:terminal_color_12 = '#729fcf'
let g:terminal_color_13 = '#ad7fa8'
let g:terminal_color_14 = '#00f5e9'
let g:terminal_color_15 = '#eeeeec'
elseif has("gui_running")
set guifont="Source Code Pro Medium 15"
nnoremap <Leader><F11> :call ToggleFullScreen()<CR>
if has("gui_win32")
set guifont=Lucida_Console:h10:cANSI
endif
else
set t_Co=256
endif
set cursorline
"set a sudo vim
cmap w!! w !sudo tee % > /dev/null
"folding
set foldcolumn=2
set foldmethod=marker
" tabs are 4 space by default
set shiftwidth=4
set tabstop=4
set expandtab
"What highlighting group is the current cursor on ?
function! SyntaxItem()
return synIDattr(synID(line("."),col("."),1),"name")
endfunction
"Nice statusbar
set laststatus=2
set statusline=
set statusline+=%-3.3n\ " buffer number
set statusline+=%f\ " file name
set statusline+=%h%m%r%w " flags
set statusline+=\[%{strlen(&ft)?&ft:'none'}, " filetype
set statusline+=%{&fileencoding}, " encoding
set statusline+=%{&fileformat}, " file format
set statusline+=%{((exists(\"+bomb\")\ &&\ &bomb)?\"B,\":\"\")}]\ " BOM
set statusline+=%{strftime('%a\ %b\ %e\ %H:%M')}\ " hour
"set statusline+=%{SyntaxItem()} " syntax highlight group under cursor
set statusline+=%= " right align
if !empty(glob("$HOME/.vim/pack/tpope/start/vim-fugitive/plugin/fugitive.vim"))
set statusline+=%{fugitive#statusline()}\ " git branch
endif
set statusline+=0x%-8B\ " current char
set statusline+=%-14.(%l,%c%V%)\ %<%P " offset
"tags
set tags=tags,./tags,../tags,../../tags
"ARM Assembler for .s files
autocmd BufNewFile,BufRead *.s set filetype=armasm
"Markdown, not modula2
autocmd BufNewFile,BufRead *.md set filetype=markdown
autocmd BufNewFile,BufRead *.toml set filetype=dosini
autocmd BufNewFile,BufRead *.j2 set filetype=jinja
set nostartofline
"Leader-f switches from C source .c to header .h file
"It automatically detects .cpp <-> .h
" .c <-> .h
" .cpp <-> .hpp
function! MPB_Flip_Ext()
python3 << endpython
import vim
import os.path
def loadfile(filename):
vim.command("e {}".format(filename))
currentfile = vim.eval('expand("%")')
c_exts = ["c", "cpp", "cc"]
h_exts = ["h", "hpp"]
currentfile_split = currentfile.split(".")
if len(currentfile_split) > 0:
ext = currentfile_split[-1]
basename = currentfile[:-(1+len(ext))]
if ext in c_exts:
for h_ext in h_exts:
h_filename = basename + "." + h_ext
if os.path.exists(h_filename):
loadfile(h_filename)
elif ext in h_exts:
for c_ext in c_exts:
c_filename = basename + "." + c_ext
if os.path.exists(c_filename):
loadfile(c_filename)
endpython
endfun
noremap <F4> :call MPB_Flip_Ext()<CR>
" Added for QSO logging
function! MPB_Prepend_Time()
python << endpython
import vim
import datetime
now = datetime.datetime.utcnow()
vim.current.line = now.strftime("%Y%m%d %H%M ") + vim.current.line
endpython
endfun
noremap <F3> :call MPB_Prepend_Time()<CR>
noremap <Leader>m :lmake -j4<CR>
noremap <Leader>M :lmake -C build -j4<CR>
"Show trailing whitespace
highlight ExtraWhitespace ctermbg=darkgreen guibg=#344011
autocmd BufEnter * exe ':2match ExtraWhitespace /\s\+$\| \+\ze\t\|\t\+\ze /'
" F5 sets the search register to the word under cursor, without moving
" the cursor
noremap <F5> :let @/ = expand('<cword>')<CR>:3match none<CR>
" F6: Highlight the word under cursor in darkcyan
highlight ManualHighlight ctermbg=darkcyan guibg=darkcyan
noremap <F6> :exe printf('match ManualHighlight /%s/', escape(expand('<cword>'), '/\'))<CR>
"Show tabs
set listchars=tab:›\ ,trail:␣
set list
set completeopt=menu,menuone,longest
noremap <Leader>R :cscope reset<Enter>:CtrlPClearAllCaches<Enter>
"some CScope maps
noremap <Leader>fs :cscope f s <cword><Enter>
if has("cscope")
" add any database in current directory
if filereadable("cscope.out")
cs add cscope.out
" else add database pointed to by environment
elseif $CSCOPE_DB != ""
cs add $CSCOPE_DB
endif
endif
"short tag and tselect
noremap <Leader>[ :tselect <C-r><C-w><CR>
noremap <Leader>] :tag <C-r><C-w><CR>
"I use bnext and bprev a lot
noremap [b :bprev<CR>
noremap ]b :bnext<CR>
"Same for location list
noremap [l :lprev<CR>
noremap ]l :lnext<CR>
"Error list
noremap [e :cNext<CR>
noremap ]e :cnext<CR>
noremap [h :GitGutterPrevHunk<CR>
noremap ]h :GitGutterNextHunk<CR>
"GIT stuff
noremap <Leader>gt :call TimeLapse()<cr>
noremap <Leader>gb :Git blame<cr>
noremap <Leader>e :NERDTreeToggle<CR>
noremap <Leader>T :set expandtab!<CR>
" Vim. Live it.
noremap <up> <nop>
noremap <down> <nop>
noremap <left> <nop>
noremap <right> <nop>
inoremap <down> <nop>
inoremap <left> <nop>
inoremap <right> <nop>
inoremap <up> <nop>
"very magic search
noremap <Leader>/ /\v
filetype plugin indent on
|