-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathvimrc
More file actions
273 lines (225 loc) · 6.83 KB
/
Copy pathvimrc
File metadata and controls
273 lines (225 loc) · 6.83 KB
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
" Use Plug to load bundles
" See https://github.com/junegunn/vim-plug
call plug#begin('~/.vim/plugged')
Plug 'tpope/vim-abolish'
Plug 'tpope/vim-fugitive'
Plug 'ctrlpvim/ctrlp.vim'
Plug 'tpope/vim-cucumber'
Plug 'editorconfig/editorconfig-vim'
Plug 'elixir-lang/vim-elixir'
Plug 'gitgutter/Vim'
Plug 'fatih/vim-go'
Plug 'hallison/vim-markdown'
Plug 'ReekenX/vim-rename2'
Plug 'vim-ruby/vim-ruby'
Plug 'nanki/treetop.vim'
Plug 'vim-scripts/VimClojure'
Plug 'sirtaj/vim-openscad'
Plug 'sersorrel/vim-lilypond'
Plug 'kburdett/vim-nuuid'
Plug 'tidalcycles/vim-tidal'
Plug 'junegunn/vim-easy-align'
Plug 'vim-test/vim-test'
Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'}
Plug 'stevearc/aerial.nvim'
call plug#end()
" --- COMMON CONFIGURATION ---
set nocompatible
filetype on
filetype plugin on
syntax on " Syntax highlighting
set ai " Auto-indent
set et " Expand tabs to spaces
set ts=2
set sw=2
set nu " Line numbers on
set backspace=2 " Fully-functional interactive backspace
set isk+=_ " Not word dividers
set wildmenu " : Auto completion
set showcmd " show current command in status bar
set showmatch " show matching parenthesis etc.
set hidden
set ruler
set scrolloff=3
if exists("&colorcolumn")
set colorcolumn=80
end
set encoding=utf-8
set fileencoding=utf-8
set incsearch " Show first match when typing a search
autocmd VimEnter * set vb t_vb= " No more bell!
set statusline=%<%f\ %h%m%r\ %y\ %{FugitiveStatusline()}%=\ %-14.(%l/%L\ %c%V\ U+%04B%)\ %P
" Don't make the entire file unreadable when there's a syntax error
hi Error NONE
" Don't clutter working directory
set undodir=~/.cache/vim/
set backupdir=~/.cache/vim/
set directory=~/.cache/vim/
let g:gutentags_cache_dir = $HOME .'/.cache/guten_tags'
" --- KEYBOARD ---
" Use , instead of \ as the user modifier. Easier to reach.
let mapleader = ","
let maplocalleader = ","
" X11 copy/paste integration
map <leader>pc :w !xclip -selection clipboard -i<CR><CR>
nmap <leader>pv :r!xclip -selection clipboard -o<CR>
" ,c runs makeprg
nmap <leader>c :w<CR>:make %<CR><CR>:copen<CR>
" Use Esc to exit terminal-mode
tnoremap <Esc> <C-\><C-n>
" Use Ctrl-J/K to move between tabs
:nmap <C-J> :tabprevious<cr>
:nmap <C-K> :tabnext<cr>
:map <C-J> :tabprevious<cr>
:map <C-K> :tabnext<cr>
:imap <C-J> <ESC>:tabprevious<cr>i
:imap <C-K> <ESC>:tabnext<cr>i
" Use Ctrl-X to close a tab
:map <C-X> :bd<CR>
" Use Ctrl-N for :cnext
:nmap <C-N> :cnext<CR>
:map <C-N> :cnext<CR>
" Use Alt-H/J/K/L to move between windows
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
inoremap <A-h> <C-\><C-N><C-w>h
inoremap <A-j> <C-\><C-N><C-w>j
inoremap <A-k> <C-\><C-N><C-w>k
inoremap <A-l> <C-\><C-N><C-w>l
nnoremap <A-h> <C-w>h
nnoremap <A-j> <C-w>j
nnoremap <A-k> <C-w>k
nnoremap <A-l> <C-w>l
" -- NETRW BROWSER ---
" Invoke with :Vex
let g:netrw_liststyle = 3 " tree-style listing
let g:netrw_browse_split = 4 " open files in previous window to right
let g:netrw_winsize = 25 " limit to 25% width
let g:netrw_banner = 0 " no banner
let g:netrw_list_hide = &wildignore " hide files matching wildignore
" --- CTRLP ---
let g:ctrlp_user_command = {
\ 'types': {
\ 1: ['.git', 'cd %s && git ls-files'],
\ 2: ['.hg', 'hg --cwd %s locate -I .'],
\ },
\ 'fallback': 'find %s -type f'
\ }
" --- FUGITIVE ---
command! -nargs=+ -complete=file GG silent Ggrep! <args> | copen
" --- VIM-TEST ---
let test#strategy = "neovim"
" Use normal terminal window that doesn't disappear on a keypress
let g:test#neovim#start_normal = 1
nmap <silent> <leader>T :TestNearest<CR>
nmap <silent> <leader>t :TestFile<CR>
" --- COPILOT ---
let g:copilot_filetypes = {
\ 'text': v:false,
\ 'markdown': v:false,
\ }
let g:copilot_node_command = "~/.asdf/installs/nodejs/16.15.0/bin/node"
" --- TREESITTER ---
lua <<LUA
require'nvim-treesitter.configs'.setup {
-- A list of parser names, or "all"
ensure_installed = {
"c", "cpp", "css", "html", "javascript", "json", "latex", "ruby", "scss",
"sql"
},
-- Install parsers synchronously (only applied to `ensure_installed`)
sync_install = false,
-- Automatically install missing parsers when entering buffer
auto_install = true,
highlight = {
-- `false` will disable the whole extension
enable = true,
-- Setting this to true will run `:h syntax` and tree-sitter at the same time.
-- Set this to `true` if you depend on 'syntax' being enabled (like for indentation).
-- Using this option may slow down your editor, and you may see some duplicate highlights.
-- Instead of true it can also be a list of languages
additional_vim_regex_highlighting = false,
},
}
LUA
" --- AERIAL ---
lua <<LUA
require('aerial').setup({
default_direction = "prefer_left",
width = 0.25,
})
LUA
" --- FILETYPE-SPECIFIC CONFIGURATION ---
autocmd BufNewFile,BufReadPost *_spec.rb setl filetype=rspec syntax=ruby
autocmd BufNewFile,BufReadPost *.make setl filetype=make syntax=make
" Makefiles
autocmd FileType make setl noet | setl ts=8 | setl sw=8
" Python
autocmd FileType python
\ setl ts=4 | setl sw=4 " PEP8
" Keywords
autocmd FileType css,scss,clojure,scheme setl isk+=-
" Ruby
autocmd FileType ruby
\ setl makeprg=ruby\ -cw|
\ setl isk+=\?,!
" Javascript
autocmd FileType javascript
\ setl makeprg=jshint
" Shell scripts
autocmd FileType sh
\ setl makeprg=shellcheck
" Go
autocmd FileType go
\ setl noet | setl ts=4 | setl sw=4 |
\ autocmd BufWritePre <buffer> Fmt
" --- BUFFERS ---
command! -nargs=* CloseHiddenBuffers call CloseHiddenBuffers()
function! CloseHiddenBuffers()
" figure out which buffers are visible in any tab
let visible = {}
for t in range(1, tabpagenr('$'))
for b in tabpagebuflist(t)
let visible[b] = 1
endfor
endfor
" close any buffers that are loaded and not visible
let l:tally = 0
for b in range(1, bufnr('$'))
if bufloaded(b) && !has_key(visible, b)
let l:tally += 1
exe 'bw ' . b
endif
endfor
echon "Closed " . l:tally . " hidden buffers"
endfun
" --- SESSION ---
" Save the current session iff there's an existing session file, i.e. I have to
" type :mks! at least once to indicate that I care about this project.
function! SaveSession()
if filereadable(getcwd() . "/Session.vim")
" Clear out hidden buffers before saving
CloseHiddenBuffers()
execute 'mksession! ' . getcwd() . '/Session.vim'
endif
endfunction
function! RestoreSession()
if filereadable(getcwd() . '/Session.vim') && bufname() !~ '\.git/'
execute 'source ' . getcwd() . '/Session.vim'
if bufexists(1)
for l in range(1, bufnr('$'))
if bufwinnr(l) == -1
exec 'sbuffer ' . l
endif
endfor
endif
endif
endfunction
autocmd VimLeave * call SaveSession()
autocmd VimEnter * nested call RestoreSession()
" --- LOCAL CONFIG
if filereadable($HOME."/.vimrc.local") && (expand($HOME) != getcwd())
source ~/.vimrc.local
endif