/
vimrc
161 lines (135 loc) · 3.89 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
if &compatible
set nocompatible
endif
let mapleader = ","
" Plugins
packadd! matchit
source ~/.vim/packages.vim
source ~/.vim/options.vim
source ~/.vim/mappings.vim
" Disable netrw banner
let g:netrw_banner = 0
" Switch windows with Ctrl + a movement key
nnoremap <C-h> <C-w>h
nnoremap <C-j> <C-w>j
nnoremap <C-k> <C-w>k
nnoremap <C-l> <C-w>l
" Automatically equalize splits when window is resized
if has("autocmd")
autocmd VimResized * wincmd =
endif
" Use %% for current filename in : commands
cnoremap <expr> %% getcmdtype() == ':' ? expand('%:h').'/' : '%%'
" Replace silversearcher with Ripgrep
cnoreabbrev Ag Rg
""" Make it easy to modify vim settings on the fly.
""
" From http://vimcasts.org/episodes/updating-your-vimrc-file-on-the-fly/
" Quickly open the vim config file in a new tab.
nnoremap <leader>ve :split $MYVIMRC<cr>
nnoremap <leader>vs :source $MYVIMRC<cr>
" Show whitespace
set listchars=tab:>-,trail:·,eol:$,extends:#,nbsp:·
nmap <silent> <leader>s :set nolist!<CR>
nmap <LEADER>y :YRShow<CR>
" Text bubbling (http://vimcasts.org/episodes/bubbling-text/)
nmap <C-Up> [e
nmap <C-Down> ]e
vmap <C-Up> [egv
vmap <C-Down> ]egv
if has("autocmd")
filetype plugin indent on " enable filetype detection
endif
" Editing mail
if has("autocmd")
autocmd FileType mail setlocal wrap
autocmd FileType mail setlocal linebreak " wrap on word boundaries
autocmd FileType mail setlocal nojs
autocmd FileType mail setlocal nosmartindent
autocmd FileType mail match Visual '\s\+$'
endif
" Indentation
if has("autocmd")
autocmd FileType sh setlocal shiftwidth=4
autocmd FileType css setlocal shiftwidth=2
autocmd FileType elm setlocal shiftwidth=4
endif
" Git
if has("autocmd")
" don't jump to last position within .git/COMMIT_EDITMSG files
autocmd FileType gitcommit call setpos('.', [0, 1, 1, 0])
endif
" Make files
if has("autocmd")
autocmd FileType make set tabstop=8
autocmd FileType make setlocal shiftwidth=8
endif
" Markdown
if has("autocmd")
autocmd FileType markdown set wrap
autocmd FileType markdown set linebreak
endif
let g:markdown_enable_spell_checking = 0
" Python
if has("autocmd")
autocmd FileType python setlocal shiftwidth=4
autocmd FileType python setlocal softtabstop=4
autocmd FileType python setlocal tabstop=4
autocmd FileType python setlocal textwidth=0
autocmd FileType python setlocal wrapmargin=0
if filereadable(".use-black")
autocmd BufWritePre */Code/*/*.py execute ':Black'
endif
if filereadable(".use-blue")
autocmd BufWritePre */Code/*/*.py
\ silent write
\ | call system('blue '..expand('<afile>:p:S'))
\ | edit!
endif
endif
nnoremap <F9> :Black<CR>
let g:black_linelength = 80
" Ruby
if has("autocmd")
autocmd FileType ruby setlocal wrapmargin=0
end
set completefunc=syntaxcomplete#Complete " for vim-ruby-minitest
set tags+=gems.tags
" Parse Rails deprecation warnings from logs
" (load them into quickfix window with `vi -q log`)
set errorformat+=DEPRECATION\ WARNING:\ %m\ \(called\ %.%\\+\ %f:%l\)
" Sysadmin
if has("autocmd")
autocmd FileType tf set nowrap " Terraform
endif
" Web
if has("autocmd")
autocmd FileType haml set nowrap
autocmd FileType sass set textwidth=0
endif
" Useful for running vi within irb
" From http://vimcasts.org/episodes/running-vim-within-irb/
if has("autocmd")
" Restore cursor position
"autocmd BufReadPost *
" \ if line("'\"") > 1 && line("'\"") <= line("$") |
" \ exe "normal! g`\"" |
" \ endif
endif
if &t_Co > 2 || has("gui_running")
syntax on
endif
" Functions and commands
command! TagFiles :call EchoTags()
function! EchoTags()
echo join(split(&tags, ","), "\n")
endfunction
" Automation
if has("autocmd")
autocmd BufWritePost */suckless/*/config.h !make && sudo make install
endif
" Host specific config
let hostfile = $HOME . '/.vim/vimrc-' . substitute(hostname(), "\\..*", "", "")
if filereadable(hostfile)
exe 'source ' . hostfile
endif