-
Notifications
You must be signed in to change notification settings - Fork 1
/
vimrc
163 lines (163 loc) · 4.77 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
" vimrc General vim behavior and mappings
"{{{
" basic settings
set nocompatible
set backspace=indent,eol,start
set termguicolors
" push more characters through to the terminal per cycle
set ttyfast
" don't update the screen during commands
set lazyredraw
" auto-update if changes are detected
set autoread
" colors!
set background=dark
colorscheme onedark
" disable mouse
set mouse=""
" disable intro text
set shortmess+=I
" make command/keycode timeouts behave reasonably
set notimeout
set ttimeout
set ttimeoutlen=10
" assume s/../../g
set gdefault
" so much more convenient
let mapleader = ","
" don't leave a mess
set backup
set backupdir=~/.vim/backup
set noswapfile
set backupskip=/tmp/*
" hidden tags file
set tags+=.tags;expand('~');/
" U is a reasonable inverse of u
nnoremap U <C-R>
" <count><C-e> moves the content <count> lines up
" so <count><C-d> can move it down
noremap <C-d> <C-y>
" make Y behave like other linewise operations
nnoremap Y y$
" I never use Ex mode, so re-run macros instead
nnoremap Q @@
" behavior for line numbers and current line
set rnu
set number
" sane movement through wrapping lines
noremap j gj
noremap k gk
" shortcut to CamelCase a word
" capitalizes the letter under the cursor, and the first letter
noremap cc vUbvU
" Exiting
noremap <leader>q :wq<cr>
" sometimes I get off the shift key too slowly
command W w
command Q q
command Wq wq
command WQ wq
if filereadable(expand('~/.vim/vimrc.d/vimrc_custom_basic'))
runtime vimrc.d/vimrc_custom_basic
endif
"}}}
" General (Settings, Folding, Autocmd)
"{{{
" - Settings
"{{{
" + to write out buffers and run make
nnoremap + :wa<bar>:make<bar><cr>
" Show matching brackets
set showmatch
" Matching settings
set ignorecase
set smartcase
set incsearch
" Indentation and other settings for common languages/formats
set shiftwidth=2
set tabstop=2
set smartindent
set smarttab
set expandtab
set breakindent
set foldmethod=indent
" don't highlight long lines
set synmaxcol=1024
"}}}
" - Folding
"{{{
" space bar toggles fold open/closed
nnoremap <silent> <Space> @=(foldlevel('.')?'za':"\<Space>")<cr>
vnoremap <Space> zf
" style folded sections
function! MyFoldText()
let line = getline(v:foldstart)
let nucolwidth = &fdc + &number * &numberwidth
let windowwidth = winwidth(0) - nucolwidth - 3
let foldedlinecount = v:foldend - v:foldstart
let line = strpart(line, 0, windowwidth - 2 -len(foldedlinecount))
let fillcharcount = windowwidth - strdisplaywidth(line) - len(foldedlinecount)
return line . '…' . repeat(" ",fillcharcount) . foldedlinecount . '…' . ' '
endfunction
set foldtext=MyFoldText()
highlight Folded ctermfg=darkgrey ctermbg=NONE
" start with folding off unless it has been manually toggled in this buffer
setlocal nofoldenable
autocmd BufEnter * if !exists('b:foldmanual') | setlocal nofoldenable | endif
" toggle folding and remember that we took manual control in this buffer
noremap <leader>ff :set foldenable! <bar> :let b:foldmanual=1<cr>
" save/restore manual folds
noremap <leader>fs :mkview<cr>
noremap <leader>fl :loadview<cr>
"}}}
" - Autocmd
"{{{
" File type configurations
autocmd FileType py,python,hs setlocal shiftwidth=4 tabstop=4
autocmd FileType c,h,java,cpp,hpp,rust,sh,css,js,go setlocal shiftwidth=3 tabstop=3
autocmd FileType rust nnoremap <buffer> + :wa<bar>:!cargo build<cr>
autocmd FileType html,xml,markdown,md,txt,text setlocal shiftwidth=2 tabstop=2
autocmd FileType markdown,md,txt,text setlocal nofoldenable spell spelllang=en_us
autocmd FileType gitcommit setlocal shiftwidth=2 tabstop=2 colorcolumn=73 nofoldenable spell spelllang=en_us
autocmd FileType gitconfig setlocal shiftwidth=4 tabstop=4
autocmd FileType git setlocal nomodeline
autocmd FileType vim setlocal shiftwidth=4 tabstop=4 foldmethod=marker foldmarker=\"{{{,\"}}}
autocmd FileType zsh setlocal nofoldenable
autocmd FileType tex,plaintex setlocal foldmethod=marker foldmarker=%{{{,%}}} spell spelllang=en_us
autocmd FileType ale-preview setlocal nofoldenable
autocmd FileType make setlocal shiftwidth=8 tabstop=8
filetype plugin indent on
"}}}
"}}}
" Splits
"{{{
" super speedy splits
noremap <leader>v :vnew<cr>
noremap <leader>V :vsplit<cr>
noremap <leader><cr> :new<cr>
noremap <leader>x :BD<cr>
" Navigate splits quickly
noremap <LEFT> <C-w>h
noremap <DOWN> <C-w>j
noremap <UP> <C-w>k
noremap <RIGHT> <C-w>l
" open without replacing current view
set splitright
set splitbelow
if filereadable(expand('~/.vim/vimrc.d/vimrc_custom_splits'))
runtime vimrc.d/vimrc_custom_splits
endif
"}}}
" Epilogue
"{{{
" Load plugins and generate help tags for everything - must be at end
if filereadable(expand('~/.vim/vimrc.d/vimrc_custom_plugins'))
runtime vimrc.d/vimrc_custom_plugins
endif
packloadall
silent! helptags ALL
set secure
if filereadable(expand('~/.vim/vimrc.d/vimrc_custom_postrc'))
runtime vimrc.d/vimrc_custom_postrc
endif
"}}}