-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvimrc_plain
109 lines (95 loc) · 3.7 KB
/
vimrc_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
""" Like my regular vimrc, but with no plugins
""" General options
" colorscheme ron - commented b/c I prefer 'default' these days
set smartindent
set ai
set tabstop=2
set shiftwidth=2
set number
set ruler
set relativenumber
set mmp=10000 " Avoids bug where syntax highlighting large go files can fail
" Replace tabs with spaces -- not always necessary
set expandtab
set incsearch
set nojoinspaces " Only put one space after '.' when joining lines.
syntax on
" Create undodir & configure vim to use it
silent exec "! test -d ${HOME}/.vim/undodir || mkdir -p ${HOME}/.vim/undodir"
set undodir=~/.vim/undodir
" Don't unindent comments in python
" TODO: install pep8 indentation rules for python
" See https://stackoverflow.com/questions/2360249/vim-automatically-removes-indentation-on-python-comments#comment12772473_2360284
au Filetype python inoremap # X<BS>#
" Set indent to 2 spaces in python
au Filetype python setlocal expandtab shiftwidth=2 tabstop=2 softtabstop=2
" Add C-k shortcut for vim-matchup, to show which conditional block you're in
" in heavily-nested code
nnoremap <c-k> :<c-u>MatchupWhereAmI?<cr>
""" Autocommands and autogroups
augroup format_on_write
" au is just short form for autocmd. Like :w and :write. :au! clears other
" autocommands in this autogroup, so that :source-ing my vimrc doesn't
" cause autocommands to stack
au!
" Commands executed before writing a buffer to a file.
" Clean up all trailing whitespace
" Note: trailing whitespace is meaningful in markdown
au BufWritePre .bashrc,*.cc,*.h,*.java,*.py,*.sh,*.json,*.proto,*.js silent! %s/[ ]\+$//g
" This is a good place to put autoformatting
" For example: `au FileType markdown AutoFormatBuffer mdformat`
augroup END
augroup set_colorcolumn_on_filetype
au!
" Run `:set filetype?` to see the filetype for the current file
au Filetype java set colorcolumn=101,102 | set textwidth=100
au Filetype cpp,python,go,proto,rust set colorcolumn=81,82 | set textwidth=80
au Filetype sh set colorcolumn=81,82 " Don't set textwidth--bash is harder to wrap
augroup END
augroup set_soft_wrap_on_markdown
au!
au Filetype markdown set wrap linebreak nolist
augroup END
augroup relative_number_in_normal_mode
au!
au InsertEnter * :set number
au InsertLeave * :set relativenumber
augroup END
" This is a function I added specifically to help when working on Pachyderm
" tests. Clients have a context, and often in tests I have to call
" alice.DoSomething(alice.Ctx(), ...). A common mistake I make in tests is:
" alice.DoSomething(bob.Ctx(), ...) (typically a copy/paste error). This
" autocommand catches those types of errors
function! Highlight_silly_ctx_error()
hi Error ctermbg=Red
match Error /\(\<[a-z]\w\+\)\.[A-Z]\w\+(\(\1\)\@!\w\+\.Ctx()/
endfunction
augroup pachyderm_go_autocmds
au!
au BufRead /home/mjs/code/**.go
\ call Highlight_silly_ctx_error()
augroup END
function! Highlight_pc_kc()
hi Error ctermbg=Red
match Error /pc\|kc/
endfunction
augroup catch_abbrevs_bash
au!
au Filetype sh call Highlight_pc_kc()
augroup END
hi ColorColumn ctermbg=Gray ctermfg=Black guibg=gray9
" Fix syntastic coloring that blends in with my highlight
" http://stackoverflow.com/questions/17677441/changing-error-highlight-color-used-by-syntasti
hi SpellBad ctermfg=Black ctermbg=Red
hi SpellCap ctermfg=Black ctermbg=Yellow
" highlight all occurrences of a match (like emacs)
hi Search ctermbg=DarkYellow
" Search terms stay highlighted after search is done, until I move the cursor
set hlsearch
" Type <space> to clear search highlighting
nnoremap <silent> <Space> :nohlsearch<Bar>:echo<CR>
" Search is case-insensitive, unless it contains uppercase letters
set ignorecase
set smartcase
" Highlight trailing whitespace
match Search /\s\+$/