~nch/dotfiles

dotfiles/.vimrc -rw-r--r-- 7.1 KiB
1461a02f — nc clean up panel a bit 8 months ago
                                                                                
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
set nocompatible
syntax enable
filetype plugin indent on

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

Plug 'itchyny/lightline.vim'

Plug 'tpope/vim-repeat'
Plug 'tpope/vim-sleuth'
Plug 'tpope/vim-surround'
Plug 'tpope/vim-vinegar'
Plug 'tpope/vim-unimpaired'
Plug 'tpope/vim-eunuch'
Plug 'tpope/vim-fugitive'
Plug 'mbbill/undotree'
Plug 'markonm/traces.vim' " nicer search/replace
Plug 'junegunn/vim-slash'
Plug 'https://git.sr.ht/~leon_plickat/paige'
Plug 'jlanzarotta/bufexplorer'
Plug 'mtth/scratch.vim'
Plug 'stefandtw/quickfix-reflector.vim'
" Hack for my current machine
source /usr/share/doc/fzf/examples/fzf.vim
Plug 'junegunn/fzf.vim'
Plug 'wsdjeg/FlyGrep.vim'
Plug 'stefandtw/quickfix-reflector.vim'
let g:vimwiki_list = [{'path': '~/shared/areas/notes',
      \ 'syntax': 'markdown', 'ext': '.md'}]
Plug 'vimwiki/vimwiki'
Plug 'junegunn/vim-peekaboo'
Plug 'sillybun/vim-repl'
Plug 'vim-test/vim-test'
let test#strategy = "asyncrun_background"

let g:nv_search_paths = ['~/shared/areas/notes']
let g:nv_date_prefix_fmt = '%Y%m%d%I%M-'
Plug 'charles-l/notational-fzf-vim'

" Python
Plug 'davidhalter/jedi-vim'
let g:jedi#completions_enabled = 0 " too slow -- can always use C-X C-O if needed
let g:pymode_rope = 0
Plug 'Vimjas/vim-python-pep8-indent'
let g:python_pep8_indent_hang_closing=1

Plug 'w0rp/ale'
let g:ale_fixers = { 'python': ['autopep8'], 'rust': ['rustfmt']}
let g:ale_linters = { 'rust': ['rls'] }
Plug 'skywind3000/asyncrun.vim'

" Lisp
Plug 'guns/vim-sexp'
Plug 'tpope/vim-sexp-mappings-for-regular-people'

" D
autocmd FileType d set efm=%*[^@]@%f\(%l\):\ %m,%f\(%l\\,%c\):\ %m,%f\(%l\):\ %m
Plug 'idanarye/vim-dutyl'

" Go
Plug 'fatih/vim-go'

" Racket
Plug 'wlangstroth/vim-racket'

" Nim
Plug 'charles-l/nim.vim'
autocmd FileType nim map <buffer> <C-]> :call GotoDefinition_nim()<CR>

call plug#end()

" Python
" TODO: add keybinding to run only on staged code (stash, run, unstash)
" TODO: list most recently used buffers and map ctrl-{1,2,3,4} to switch to
" the top 4
autocmd FileType python set makeprg=python3\ %

let mapleader = " "

set backspace=2
set laststatus=2
set shiftwidth=4
set tabstop=4
set modeline
set modelines=5
set noshowmode nonumber expandtab smarttab autoindent smartindent
set hidden nowrap nobackup noswapfile showmatch incsearch
set path+=**
set wildmenu
set synmaxcol=200
set switchbuf=useopen
let g:netrw_banner = 0
let g:netrw_browse_split = 4
let g:netrw_altv = 1
let g:netrw_liststyle = 3
let g:netrw_list_hide = netrw_gitignore#Hide()

"Strip trailing whitespace when writing a file
au BufWritePre * :%s/\s\+$//e

"Move windows with C-Direction
nmap <C-h> <C-w>h
nmap <C-j> <C-w>j
nmap <C-k> <C-w>k
nmap <C-l> <C-w>l

" use vim 8 terms -- open a popup term or hide it
function! OpenTerminal()
    let winname = '!' . expand('$SHELL')
    let m = bufwinnr(winname)
    if m > 0
        exec m . 'wincmd q'
    else
        let n = bufnr(winname)
        if n > 0
            exec 'botright sb' . n
        else
            exec 'botright term'
        endif
        exec 'resize 20'
        exec 'set winfixheight'
    endif
endfunction

function! RunCommandInTerminal(cmd)
  let n = bufnr('!' . a:cmd)
  if n > 0
    exec 'botright sb' . n
  else
    exec 'botright term ' . a:cmd
  endif
  exec 'resize 20'
  exec 'set winfixheight'
  exec 'nmap <buffer> q :bd<CR>'
endfunction

""" rust {
autocmd FileType rust nnoremap <silent> <leader>r :call RunCommandInTerminal('cargo run')<CR>
autocmd FileType rust setlocal omnifunc=ale#completion#OmniFunc
autocmd FileType rust nnoremap <silent> <Space> :ALEHover<CR>
""" }

function! ToggleVExplorer()
  if exists("t:expl_buf_num")
      let expl_win_num = bufwinnr(t:expl_buf_num)
      if expl_win_num != -1
          let cur_win_nr = winnr()
          exec expl_win_num . 'wincmd w'
          close
          exec cur_win_nr . 'wincmd w'
          unlet t:expl_buf_num
      else
          unlet t:expl_buf_num
      endif
  else
      exec '1wincmd w'
      Vexplore
      let t:expl_buf_num = bufnr("%")
  endif
endfunction

" Add indicator to lightline when async job is running.
" Cribbed from https://github.com/albertomontesg/lightline-asyncrun
function! LightlineAsyncRunStatus()
        let l:status = asyncrun#status()
        if l:status == 'none'
                return ""
        elseif l:status == 'run'
                return "Running..."
        else
                return l:status
        endif
endfunc

let g:lightline = {
      \ 'colorscheme': 'wombat',
      \ 'active': {
      \   'left': [ [ 'mode', 'paste' ],
      \             [ 'readonly', 'filename', 'modified', 'asyncrunstatus' ] ]
      \ },
      \ 'component_function': {
      \   'asyncrunstatus': 'LightlineAsyncRunStatus'
      \ },
      \ }

let g:fuzzyfunc = &omnifunc

function! FuzzyCompleteFunc(findstart, base)
  let Func = function(get(g:, 'fuzzyfunc', &omnifunc))
  let results = Func(a:findstart, a:base)

  if a:findstart
    return results
  endif

  if type(results) == type({}) && has_key(results, 'words')
    let l:words = []
    for result in results.words
      call add(words, result.word . ' ' . result.menu)
    endfor
  elseif len(results)
    let l:words = results
  endif

  if len(l:words)
    let result = fzf#run({ 'source': l:words, 'down': '~40%', 'options': printf('--query "%s" +s', a:base) })

    if empty(result)
      return [ a:base ]
    endif

    return [ split(result[0])[0] ]
  else
    return [ a:base ]
  endif
endfunction

set completefunc=FuzzyCompleteFunc
set completeopt=menu
set colorcolumn=80

nnoremap <silent> <leader>o :Files<CR>
nnoremap <silent> gb :Buffers<CR>
nnoremap <silent> <leader>m :AsyncRun -mode=terminal -program=make<CR>
nnoremap <silent> <leader>M :AsyncRun -program=make<CR>
nnoremap <silent> <leader>q :call asyncrun#quickfix_toggle(16)<cr>
nnoremap <silent> <leader>ad :ALEDetail<CR>
nnoremap <silent> <leader>bd :lclose<bar>b#<bar>bd #<CR>
" magic from https://vi.stackexchange.com/questions/2350/how-to-map-alt-key
execute "set <m-=>=\e="
nnoremap <silent> <m-=> :exec OpenTerminal()<CR>
tnoremap <silent> <m-=> <c-\><c-n>:exec OpenTerminal()<CR>
nnoremap <silent> <leader>/ :FlyGrep<CR>
nnoremap <silent> <leader>n :NV<CR>
nnoremap <silent> <leader>t :TestLast<CR>

nnoremap <silent> <Backspace> <C-^>
inoremap <silent> <F5> <C-R>=strftime('%Y%m%d%I%M')<CR>

augroup c
    autocmd!
    " run default recipe in makefile
    au BufNewFile,BufRead *.cc,*.cpp,*.c,*.h nnoremap <buffer> <silent> <leader>r :execute "!./" . split(filter(readfile('makefile'), 'v:val =~ ":"')[0], ":")[0]<CR>
augroup END

vnoremap . :norm.<CR>

"packadd termdebug
packadd! matchit
packadd! editexisting

autocmd FileType lisp,racket,scheme :iabbrev .\ λ
autocmd FileType lisp,racket,scheme :iabbrev (.\ (λ<DEL>
autocmd FileType lisp,racket,scheme let b:delimitMate_quotes = "\""

if executable("rg")
    set grepprg=rg\ --vimgrep\ --no-heading
    set grepformat=%f:%l:%c:%m,%f:%l:%m
endif

colorscheme paige

if has("gui_running")
    " don't ruin up/right/left/arrow keys in console which esc to send signal
    tnoremap <Esc> <C-w>N
    tnoremap <C-v><Esc> <Esc>

    set guioptions-=T
    set guioptions-=L
    set guioptions-=r
    set guioptions-=m
endif

" use steady bar cursor in insert mode
let &t_SI = "\e[6 q"
" block cursor in command mode
let &t_EI = "\e[2 q"