-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvimrc
306 lines (249 loc) · 8.04 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
let mapleader = "\<Space>"
" Load matchit.vim, but only if the user hasn't installed a newer version.
if !exists('g:loaded_matchit') && findfile('plugin/matchit.vim', &rtp) ==# ''
runtime! macros/matchit.vim
endif
syntax on
filetype plugin indent on
" When the type of shell script is /bin/sh, assume a POSIX-compatible
" shell for syntax highlighting purposes.
let g:is_posix = 1
" Softtabs, 2 spaces
set tabstop=2
set shiftwidth=2
set shiftround
set expandtab
" Display extra whitespace
set list listchars=tab:»·,trail:·,nbsp:·
" Use one space, not two, after punctuation.
set nojoinspaces
if executable('rg')
set grepprg=rg\ --glob=!.git\ --hidden\ --vimgrep\ --smart-case\ $*
set grepformat=%f:%l:%c:%m
endif
set number
" Open new split panes to right and bottom, which feels more natural
set splitbelow
set splitright
if filereadable(expand("~/.vimrc.bundles"))
source ~/.vimrc.bundles
endif
" Core {{{
" Allow project specific vimrc
set exrc
" Optimize for fast terminal connections
set ttyfast
" Use UTF-8 without BOM
set encoding=utf-8 nobomb
" Respect modeline in files
set modeline
set modelines=4
" Don’t reset cursor to start of line when moving around.
set nostartofline
" UI
set autoread
set colorcolumn=81
set cursorline
set hidden
set textwidth=0
set backspace=2 " Backspace deletes like most programs in insert mode
set nobackup
set nowritebackup
set noswapfile " http://robots.thoughtbot.com/post/18739402579/global-gitignore#comment-458413287
set history=50
set ruler " show the cursor position all the time
set showcmd " display incomplete commands
set incsearch " do incremental searching
set laststatus=2 " Always display the status line
set autowrite " Automatically :write before running commands
set smartindent
set breakindent
let &showbreak = '→ '
set linebreak
set hlsearch
set ignorecase " searches are case insensitive...
set smartcase " ... unless they contain at least one capital letter
set infercase " Use the correct case when autocompleting
set mouse=a " Enable mouse in all modes
set updatetime=100
set fillchars=eob:\ ,stl:─,vert:│
" fix & command to preserve flags
nnoremap & :&&<CR>
xnoremap & :&&<CR>
" Expand %% to current directory
cnoremap %% <C-R>=fnameescape(expand('%:h')).'/'<cr>
" automatically rebalance windows on vim resize
autocmd VimResized * wincmd =
set nofoldenable " don't fold by default
" Persistent undo
let undodir = expand('~/.vim/undo')
if !isdirectory(undodir)
call mkdir(undodir)
endif
set undodir=~/.vim/undo
set undofile
nnoremap \ :grep<SPACE>
nnoremap gr :grep! "\b<cword>\b"<CR>:cw<CR><CR>
augroup quickfix
autocmd!
autocmd QuickFixCmdPost [^l]* cwindow
autocmd QuickFixCmdPost l* lwindow
augroup END
hi VertSplit guibg=NONE
highlight htmlArg cterm=italic gui=italic
highlight Comment cterm=italic gui=italic
highlight Type cterm=italic gui=italic
let theme_script_path = expand("~/.local/share/tinted-theming/tinty/base16-vim-colors-file.vim")
function! FileExists(file_path)
return filereadable(a:file_path) == 1
endfunction
function! HandleFocusGained()
if FileExists(g:theme_script_path)
execute 'source ' . g:theme_script_path
endif
endfunction
if FileExists(theme_script_path)
set termguicolors
let g:tinted_colorspace = 256
execute 'source ' . theme_script_path
" TODO: tmux isn't handling this correctly
" autocmd FocusGained * call HandleFocusGained()
endif
" }}}
" Mappings {{{
" Originally from vim-sensible, but <C-L> is used for TmuxNavigate
" Use <leader><C-L> to clear the highlighting of :set hlsearch.
nnoremap <silent> <leader><C-L> :nohlsearch<C-R>=has('diff')?'<Bar>diffupdate':''<CR><CR><C-L>
nnoremap <silent><Leader>] <C-w><C-]><C-w>T
vnoremap <Leader>y "+y
vnoremap <Leader>p "+p
nnoremap <Leader>y "+y
nnoremap <Leader>p "+p
nnoremap <Leader>P "+P
" EasyAlign
" Start interactive EasyAlign in visual mode (e.g. vipga)
xmap ga <Plug>(EasyAlign)
" Start interactive EasyAlign for a motion/text object (e.g. gaip)
nmap ga <Plug>(EasyAlign)
" }}}
" Plugins {{{
" airline
let g:airline_theme = 'base16_eighties'
let g:airline#extensions#scrollbar#enabled = 1
let g:airline#extensions#tabline#enabled = 1
let g:airline#extensions#tabline#show_buffers = 0
let g:airline#extensions#tabline#show_tab_type = 0
let g:airline#extensions#tabline#show_close_button = 0
let g:airline_powerline_fonts = 1
" ale
let g:ale_completion_autoimport = 1
let g:ale_completion_enabled = 1
let g:ale_echo_msg_error_str = ''
let g:ale_echo_msg_format = '[%linter%] %s [%severity%]'
let g:ale_echo_msg_warning_str = ''
let g:ale_floating_preview = 1
let g:ale_floating_window_border = ['│', '─', '╭', '╮', '╯', '╰']
let g:ale_hover_cursor = 0
let g:ale_linters_explicit = 1
let g:ale_ruby_sorbet_enable_watchman = 1
let g:ale_vim_vimls_use_global = 1
highlight link ALEError Error
nnoremap <Leader>af :ALEFix<CR>
function ALETagFunc(pattern, flags, info) abort
if a:flags != "c"
return v:null
endif
let l:current_tag = expand("<cWORD>")
" execute("call CocAction('jumpDefinition')")
" let filename = expand('%:p')
" let cursor_pos = getpos(".")
" let cmd = '/\%'.cursor_pos[1].'l\%'.cursor_pos[2].'c/'
" execute("normal \<C-o>")
" return [ { 'name': name, 'filename': filename, 'cmd': cmd } ]
return []
endfunction
" function! s:gotoDefinition() abort
" let l:current_tag = expand('<cWORD>')
"
" let l:current_position = getcurpos()
" let l:current_position[0] = bufnr()
"
" let l:current_tag_stack = gettagstack()
" let l:current_tag_index = l:current_tag_stack['curidx']
" let l:current_tag_items = l:current_tag_stack['items']
"
" if CocAction('jumpDefinition')
" let l:new_tag_index = l:current_tag_index + 1
" let l:new_tag_item = [#{tagname: l:current_tag, from: l:current_position}]
" let l:new_tag_items = l:current_tag_items[:]
" if l:current_tag_index <= len(l:current_tag_items)
" call remove(l:new_tag_items, l:current_tag_index - 1, -1)
" endif
" let l:new_tag_items += l:new_tag_item
"
" call settagstack(winnr(), #{curidx: l:new_tag_index, items: l:new_tag_items}, 'r')
" endif
" endfunction
" function! ErlangTag(pattern, flags, info)
" let l:funcname = expand("<cword>")
" let l:line = getline(".")
" let l:match_res = matchlist(line, "[a-zA-Z0-9'_]*:" . l:funcname)
" if len(l:match_res) > 0
" let [l:mod, l:fun] = split(l:match_res[0], ":")
" return filter(taglist(a:pattern), 'get(v:val, "module", "") ==# l:mod')
" else
" return taglist(a:pattern)
" endif
" endfunction
function! OnALELSPStarted() abort
setlocal omnifunc=ale#completion#OmniFunc
setlocal signcolumn=yes
if exists('+tagfunc') | setlocal tagfunc=ALETagFunc | endif
nmap <buffer> gd <plug>(ale_go_to_definition)
nmap <buffer><silent> gs :ALESymbolSearch <cword><CR>
nmap <buffer> gr <plug>(ale_find_references)
nmap <buffer> gi <plug>(ale_go_to_implementation)
" nmap <buffer> gt <plug>(ale_go_to_type_definition)
nmap <buffer> <leader>rn :ALERename<CR>
nmap <buffer> K <plug>(ale_hover)
endfunction
augroup ale
autocmd!
autocmd User ALELSPStarted call OnALELSPStarted()
augroup END
let g:ale_linters = {
\ 'go': ['gobuild', 'gofmt'],
\ 'proto': ['protolint'],
\ 'ruby': ['standardrb', 'sorbet'],
\ 'vim': ['vimls'],
\}
let g:ale_fixers = {
\ 'go': ['gofmt', 'goimports'],
\ 'proto': ['protolint'],
\ 'ruby': ['standardrb', 'sorbet'],
\}
" fugitive
autocmd BufReadPost fugitive://* set bufhidden=delete
" fzf
nnoremap <silent> <C-p> :FZF<CR>
" goyo
nnoremap <leader>w :Goyo<CR>
" markdown
let g:markdown_fenced_languages = ['c', 'erb=eruby', 'diff', 'go', 'ruby', 'sh', 'sql']
" netrw
let g:netrw_bufsettings = 'noma nomod nu nobl nowrap ro'
augroup netrw
autocmd!
autocmd FileType netrw set colorcolumn=""
augroup END
" vim-test
let g:test#strategy = 'dispatch'
nmap <silent> <leader>tn :TestNearest<CR>
nmap <silent> <leader>tf :TestFile<CR>
nmap <silent> <leader>ts :TestSuite<CR>
nmap <silent> <leader>tl :TestLast<CR>
nmap <silent> <leader>tg :TestVisit<CR>
" }}}
" disable unsafe commands in exrc files
set secure
" vim: set foldmethod=marker: