summaryrefslogtreecommitdiff
path: root/.vim/vimrc
blob: ee6ed25abe977a689e40936d893cedc893796911 (plain)
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
"
" .vimrc VIM Preferences File
" by Mike Crute (mcrute@gmail.com)
"
"
" Syntax Highlighting {{{
" Always use 256-color mode
set t_Co=256

syntax on

" MacVim gets its transparency settings all horked up if we don't
" set this before we do GUI initialization stuff.
set nocompatible
colorscheme PaperColor

" Try to use the best background for the running terminal
if $TERM_BG_SHADE == "light"
    set background=light
else
    set background=dark
end

" Do colors different things if this is a GUI vs a 256 color terminal
if has("gui_macvim") && has("gui_running")
    set guifont=Monaco:h14.00
    set lines=50
    set columns=100
    set background=light
    colorscheme hemisu
end

" Monospace 8 is a pretty nice font if we're running under GVIM.
" The columns/lines in this setting fits just perfectly on my
" Linux desktop at work at highest resolution.
if has("gui_gtk") && has("gui_running")
    set lines=75
    set columns=238
    set guifont=Monospace\ 8
endif

if has("gui_running")
    set guioptions=aegimtc
    set showtabline=1
else
    set showtabline=2
endif
" }}}
" General Settings {{{
set backspace=indent,eol,start
set browsedir=buffer
set fileformat=unix
set hidden
set history=1000
set modeline
set title
set nojoinspaces
set directory=~/.cache/vim//,~/tmp//,/var/tmp//,/tmp//
set viminfo='100,<50,s10,h,n$HOME/.cache/viminfo
set switchbuf=useopen
set tabpagemax=50
set vb t_vb=

" Defaults to ignore case on MacOS (vim 8+)
if exists("&fileignorecase")
    set nofileignorecase
end

if v:version > 703 || v:version == 703 && has("patch541")
  set formatoptions+=j " Delete comment character when joining commented lines
endif
"let mapleader=","

" Really large Go files in Kubernetes exceed the maximum pattern memory space
set maxmempattern=10000
" }}}
" Search Settings {{{
set hlsearch
set incsearch
set showmatch
set smartcase
" }}}
" Tab Settings {{{
"set autoindent
set expandtab
"set smarttab
set shiftwidth=4
set softtabstop=4
set tabstop=4
" }}}
" Visual Display {{{
set laststatus=2
set noequalalways
set nowrap
set number
set ruler
set scrolloff=4
set showcmd
set splitbelow
set splitright
set virtualedit=all
set wildmenu
set nospell
" }}}
" Vim Plugins {{{
filetype plugin indent on

" Some sane defaults for the explorer
let g:VCSCommandUseFirstMatch=1
let g:explVertical=1
let g:explHideFiles='^\.,.*\.sw[po]$,.*\.pyc$'
let g:explDetailedHelp=0

" Prefer brew installed ctags because system ctags on mac os sucks
if executable("/usr/local/bin/ctags")
    let g:Tlist_Ctags_Cmd="/usr/local/bin/ctags"
endif

" Allow other languages in fenced Markdown blocks
let g:markdown_fenced_languages = ['python=python', 'c++=cpp', 'viml=vim', 'bash=sh', 'ini=dosini']

" This is really slow on large code-bases
" let g:go_fmt_command = "goimports"

" Use vim ctags mappings instead of GoDef mappings because guru is really
" really slow, especially on huge code-bases like Kubernetes
" let g:go_def_mapping_enabled = 0

" Show errors in go code
let g:go_diagnostics_level = 2
" }}}
" Custom Commands {{{
" Cleanup windows crap from line endings
command! TrimSpaces %s/\s\+$//e
command! FixLineEnd %s/
//gi
command! ReIndent !reindent %
command! -bar -nargs=0 SudoW :setl nomod|silent exe 'write !sudo tee % >/dev/null'|let &mod = v:shell_error
"command! W write
"command! Q qa!
" }}}
" Folding Settings {{{
set foldenable
set foldcolumn=3
set foldmethod=marker
" }}}
" {{{ Line and Column Highlighting
function! SetColumnHighlighting(set_on)
    if $TERM_PROGRAM == "Apple_Terminal" || version < 700
        " Apple's Terminal.app is more than slightly retarded when it comes
        " to colors and term compatibility so don't do this stuff on a Mac.
        return
    endif

    if (!&readonly && a:set_on) && &filetype != "text"
        setlocal cursorline
        setlocal cursorcolumn
    else
        setlocal nocursorline
        setlocal nocursorcolumn
    endif
endfunction
" }}}
" Key Bindings {{{
" Copy and Paste to X11 Clipboard
"
" This is required because the terminal version of VIM often isn't compiled
" with support for the xterm clipboard and I don't typically use an xterm
" compatible terminal anyhow. Will read and write the X11 clipboard (C-c, C-v)
" using the xclip command instead.
if executable("xclip")
    nnoremap <silent> <leader>cp :read !xclip -o -selection CLIPBOARD<CR>
    vnoremap <silent> <leader>cc :'<,'>w !xclip -selection clipboard -i<CR><CR>
endif

" Tab Key Bindings
nnoremap tm :tabmove<CR>
nnoremap tc :tabclose<CR>

" Buffer Key Bindings
nnoremap <leader>bn :bnext<CR>
nnoremap <leader>bp :bprev<CR>

" Plugin Key Bindings
nnoremap <leader>fe :Vexplore<CR>

" Convenience Key Bindings
" cs: clears search buffer
nnoremap <silent> cs :let @/=""<CR>
nnoremap sp :set spell!<CR>

" Remap cw so it doesn't clobber the " register
nnoremap cw "_cw

" Expand current file's directory in command mode
cnoremap %% <C-R>=expand('%:h').'/'<CR>
cnoremap %- !mkdir -p <C-R>=expand('%:h').'/'<CR>

" Turns selected camelCase into camel_case
vnoremap <leader>dc :s/\v\C(([a-z]+)([A-Z]))/\2_\l\3/g<CR>

" Forward search for visual selection
vnoremap <expr> // 'y/\V'.escape(@",'\/').'<CR>'

" Easily show/hide undotree
nnoremap <Leader>uu :UndotreeToggle<CR>
" }}}
" {{{ Workarounds For Broken Shit
" These have to be set otherwise you can't write-back
" a modified crontab on Mac OS X. I think it has to do
" with the fact that writing files causes a new file
" handle to be created or somesuch nonsense. Should be
" duplicated in the system vimrc too but here because
" old versions of Mac OS didn't set it properly.
autocmd BufEnter /private/tmp/crontab* setlocal backupcopy=yes
autocmd BufEnter /tmp/crontab* setlocal backupcopy=yes
autocmd BufEnter /private/etc/pw* setlocal backupcopy=yes
autocmd BufEnter $HOME/mail/tmp/mutt-* setlocal backupcopy=yes

" Mac OS X defaults this to 0 in the system vimrc as
" it may have some security implications with nasty
" commands in modelines. Seems that this has been
" patched so probably safe now. CVE-2007-2438
set modelines=5
" }}}
" {{{ Better Grep Settings
if &grepprg ==# 'grep -n $* /dev/null'
  set grepprg=grep\ -rnH\ --exclude='.*.swp'\ --exclude='*~'\ --exclude='*.log'\ --exclude=tags\ $*\ /dev/null
endif
" }}}
" {{{ Better Formatter Settings
if executable("par")
    set formatprg=par
endif
" }}}
" vim:foldenable:foldmethod=marker: