-
Notifications
You must be signed in to change notification settings - Fork 1
/
.vimrc
289 lines (252 loc) · 9.56 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
" Jezen Thomas’ .vimrc
" jezen@jezenthomas.com
" jezenthomas.com
" Init & Plugins ----------------------------------------------------------- {{{
set nocompatible
filetype off
call plug#begin('~/.vim/plugged')
" Gary Bernhardt’s colour scheme
Plug 'quanganhdo/grb256'
set t_Co=256
colorscheme grb256
" Pimp my editor
Plug 'godlygeek/tabular'
Plug 'https://github.com/chrisbra/unicode.vim'
Plug 'https://github.com/mileszs/ack.vim'
Plug 'itchyny/calendar.vim'
Plug 'jamessan/vim-gnupg'
Plug 'janko-m/vim-test'
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
Plug 'junegunn/fzf.vim'
Plug 'junegunn/vim-easy-align'
Plug 'majutsushi/tagbar'
Plug 'scrooloose/nerdcommenter'
Plug 'tpope/vim-abolish'
Plug 'tpope/vim-dispatch'
Plug 'tpope/vim-fugitive'
Plug 'tpope/vim-rhubarb'
Plug 'tpope/vim-surround'
Plug 'w0rp/ale'
" Language specific
Plug 'rstacruz/sparkup', {'rtp': 'vim/'}
Plug 'pbrisbin/vim-syntax-shakespeare'
Plug 'pangloss/vim-javascript'
Plug 'elmcast/elm-vim'
Plug 'chrisbra/csv.vim'
Plug 'LnL7/vim-nix'
call plug#end()
filetype plugin indent on
" }}}
" Basic config ------------------------------------------------------------- {{{
set lazyredraw
set autoread
set hidden
set noesckeys
"set cryptmethod=blowfish2 " https://dgl.cx/2014/10/vim-blowfish
set exrc " Enable use of project-specific .vimrc
set secure " Only run autocommands owned by me
" }}}
" Calendar ----------------------------------------------------------------- {{{
" https://github.com/itchyny/calendar.vim
let g:calendar_google_calendar=1
let g:calendar_date_month_name=1
let g:calendar_week_number=1
" }}}
" Linting ------------------------------------------------------------------ {{{
let g:ale_set_highlights = 0
let g:ale_lint_on_text_changed = 'never'
let g:ale_lint_on_enter = 0
let g:ale_linters = {
\ 'haskell': ['hlint -i "Reduce duplication"','ghc-mod','hdevtools'],
\}
" }}}
" UI ----------------------------------------------------------------------- {{{
syntax on " Enable syntax highlighting
set ruler " Show current position in status bar
set synmaxcol=80 " Don’t highlight lines longer than 80 chars
set wrap " Soft-wrap long lines
set linebreak
set showbreak=↪ " Prefix linebreaks with this fancy arrow
set scrolloff=5 " Keep at least 5 lines above/below
set title " Change terminal title
set showmode " Always show current mode
set laststatus=2 " Make sure airline isn’t hidden
set shortmess=atI " Hide intro message
set showcmd " Show command as it’s being typed
set list " Show invisible characters
set noerrorbells " Disable bells
set wildmenu " Enhance command-line completion
" Default netrw to tree mode
let g:netrw_liststyle=3
" Highlight VCS conflict markers
match ErrorMsg '^\(<\|=\|>\)\{7\}\([^=].\+\)\?$'
" }}}
" Editing ------------------------------------------------------------------ {{{
set clipboard=unnamed " Use the system clipboard
set et " Pressing TAB creates spaces instead
set tabstop=2
set shiftwidth=2
set backspace=indent,eol,start " Allow backspace in insert mode
set lcs=tab:▸\ ,extends:❯,precedes:❮,nbsp:.,trail:·,eol:¬
set nobackup " Disable backups
set nowb " Disable write backups
set noswapfile " Disable swap files
set completeopt-=preview " Disable scratch preview buffer
set ttyfast
set encoding=utf-8 nobomb " Use UTF-8 without BOM
set nojoinspaces " Don’t double space after join
set splitbelow " I always thought vim opened splits backwards
set splitright
set diffopt+=vertical " Split vertically when doing Gdiff
" }}}
" Convenience mappings ----------------------------------------------------- {{{
" Please, do not use comma for leader. You need the comma for moving to a
" previous match from a linewise character search.
let mapleader="\<space>"
" Clean trailing whitespace
nnoremap <leader>w mz:%s/\s\+$//<cr>:let @/=''<cr>`z
" Fast saving
nnoremap <leader>s :w!<cr>
" Save as super user
noremap <leader>S :w !sudo tee % > /dev/null<CR>
" Fast quit
nmap <leader>q :q<cr>
" Jump to first character or column
noremap <silent> H :call FirstCharOrFirstCol()<cr>
" Jump to end of line
noremap L $
function! FirstCharOrFirstCol()
let current_col = virtcol('.')
normal ^
let first_char = virtcol('.')
if current_col <= first_char
normal 0
endif
endfunction
" Toggle alternate buffer
nnoremap <leader><leader> <c-^>
iabbrev ldis ಠ_ಠ
iabbrev lsir ಠ_ರೃ
iabbrev lhap ツ
iabbrev fliptable (╯°□°)╯ ┻━┻
iabbrev *shrug* ¯\_(ツ)_/¯
iabbrev herewego ᕕ( ᐛ )ᕗ
iabbrev dealwithit (⌐■_■)
iabbrev lenny ( ͡° ͜ʖ ͡°)
iabbrev yeahdawg
\<cr>▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
\<cr>░░░░░ ░░░░▀█▄▀▄▀██████░▀█▄▀▄▀████▀
\<cr>░░░░ ░░░░░░░▀█▄█▄███▀░░░▀██▄█▄█▀
nnoremap <leader>v :vsplit<cr>
nnoremap <leader>h :split<cr>
" }}}
" Searching ---------------------------------------------------------------- {{{
set showmatch " Show matching bracket when under cursor
set hlsearch " Highlight search results
set ignorecase " Ignore case when searching
set smartcase " Case-sensitive if pattern includes uppercase
set incsearch " Highlight dynamically while typing
" Clear the higlighted search results
nnoremap <silent> <C-l> :<C-u>nohlsearch<CR><C-l>
" Keep search matches in middle of window
nnoremap n nzzzv
nnoremap N Nzzzv
" Same when jumping
nnoremap <c-o> <c-o>zz
" Don't move on *
nnoremap * *<c-o>
set wildignore+=*.jpg,*.png,*.gif,*.aux
set wildignore+=*.o,*.hi
" FZF (replaces Ctrl-P, FuzzyFinder and Command-T)
nmap <leader>r :Tags<cr>
nmap <leader>t :Files<cr>
nmap <leader>a :Rg<cr>
" Open a quickfix window for last search
nnoremap <silent> <leader>/ :execute 'vimgrep /'.@/.'/g %'<CR>:copen<CR>
" Run word under cursor through ripgrep
nnoremap ° :Rg <c-r><c-w><cr>
" Prefer rg > ag > ack
" https://hackercodex.com/guide/vim-search-find-in-project/
let g:ackprg = 'rg -S --no-heading --vimgrep'
" }}}
" Folding ------------------------------------------------------------------ {{{
set foldlevelstart=0
set foldmethod=marker " Use three curly braces
" Toggle folds with minus
nnoremap - za
vnoremap - za
" Focus current fold
nnoremap <leader>z zMzvzz
function! MyFoldText()
let line = getline(v:foldstart)
let nucolwidth = &fdc + &number * &numberwidth
let windowwidth = winwidth(0) - nucolwidth - 3
let foldedlinecount = v:foldend - v:foldstart
" expand tabs into spaces
let onetab = strpart(' ', 0, &tabstop)
let line = substitute(line, '\t', onetab, 'g')
let line = strpart(line, 0, windowwidth - 2 -len(foldedlinecount))
let fillcharcount = windowwidth - len(line) - len(foldedlinecount)
return line . '…' . repeat(" ",fillcharcount) . foldedlinecount . '…' . ' '
endfunction
set foldtext=MyFoldText()
" }}}
" Automatic commands ------------------------------------------------------- {{{
if has("autocmd")
" Enable file type detection
filetype on
" Treat .json files as .js
au BufNewFile,BufRead *.json setfiletype json syntax=javascript
au BufNewFile,BufRead *.cap setfiletype cap syntax=ruby
au BufNewFile,BufRead *.thor set filetype=ruby
au BufNewFile,BufRead *.msg call FoldParagraphs()
" https://codeyarns.com/2015/02/02/cannot-close-buffer-of-netrw-in-vim/
au FileType netrw setl bufhidden=wipe
" Automatically open quickfix window when calling :make, or close the
" quickfix window if there are no errors to report
au QuickFixCmdPost [^l]* nested cwindow
au QuickFixCmdPost l* nested lwindow
au FileType markdown vmap <Leader><Bslash> :EasyAlign*<Bar><Enter>
endif
function! FoldParagraphs()
set foldmethod=expr
set foldexpr=getline(v:lnum)=~'^\\s*$'&&getline(v:lnum+1)=~'\\S'?'<1':1
endfunction
" Make sure Vim returns to the same line when reopening a file
augroup line_return
au!
autocmd BufReadPost *
\ if line("'\"") >= 1 && line("'\"") <= line("$") && &ft !~# 'commit'
\ | exe "normal! g`\""
\ | endif
augroup END
" Automatically insert trailing white space for email
augroup mail_trailing_whitespace " {
au!
au FileType mail setlocal formatoptions+=w
augroup END " }
" Only show cursorline in the current window and in normal mode.
augroup cline
au!
au WinLeave,InsertEnter * set nocursorline
au WinEnter,InsertLeave * set cursorline
augroup END
" }}}
" Haskell ------------------------------------------------------------------ {{{
au FileType haskell set kp=hoogle
let g:haskell_tabular = 1
vmap a= :Tabularize /=<cr>
vmap a: :Tabularize /::<cr>
vmap a- :Tabularize /-><cr>
vmap a< :Tabularize /<-<cr>
vmap a( :Tabularize /(<cr>
vmap a\| :Tabularize /\|<cr>
vmap a. :Tabularize /\.<cr>
nnoremap <leader>gr :Dispatch! tmux send-keys -t left C-e C-u C-l ':serve' C-m<cr>
nnoremap <leader>gt :Dispatch! tmux send-keys -t left C-e C-u C-l ':test' C-m<cr>
nnoremap <leader>gl :Dispatch! tmux send-keys -t left C-e C-u C-l ':hlint' C-m<cr>
nnoremap <leader>gs ma:%!stylish-haskell<cr>`azz
"}}}
" Elm ---------------------------------------------------------------------- {{{
let g:elm_format_autosave = 0
"}}}