-
Notifications
You must be signed in to change notification settings - Fork 0
/
.vimrc
281 lines (228 loc) · 10.5 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
set encoding=utf-8 "Enable utf-8 support
scriptencoding utf-8
filetype plugin indent on " required!
" Switch syntax highlighting on, when the terminal has colors
" Also switch on highlighting the last used search pattern.
if (&t_Co > 2 || has("gui_running")) && !exists("syntax_on")
syntax on
endif
if has('gui_running')
set guioptions-=T "no toolbars
set guioptions-=m "or menu
set guioptions-=r "or scrollbars
set guioptions-=l
set guioptions-=R
set guioptions-=L
set guioptions-=b
set guioptions-=h
set guioptions-=e "I dont like the gui tabs, use ascii
set guioptions+=c "dont use gui modal dialogs
"set guifont=Ubuntu\ Mono\ 12
"set guifont=Source\ Code\ Pro\ Medium\ 12
set guifont=JetBrainsMonoNL\ Nerd\ Font\ 12
elseif has('termguicolors')
" Use fg/bg colors from terminal (compatible terminals only)
set termguicolors
endif
function! s:CreateDir(name)
" Create a given directory if it does not exist.
if !isdirectory(a:name)
echo 'creating '.a:name
call mkdir(a:name, 'p')
endif
endfunction
" Tame backup/undo/swap/info file management
set undodir=$HOME/.vim/undo " centralize files working directory
call s:CreateDir(expand(&undodir)) " create the directory if needed
set backupdir=/tmp// " backup files should be kept out of the working dir
set directory=/tmp// " store swap files in a centralized place, not in working dir
set hidden " dont delete buffers, just hide them
set undofile " save undo tree when file is closed
set undolevels=1000 " many levels of undo
set backup " record backup files for crashes
set history=1000 " Remember a ton of commands
set viminfo+=n~/.vim/viminofo
" Tame searching
set smartcase " ignore case in a search until there is some capitalization
set ignorecase " smartcase cant do its job unless this is set
set gdefault " assume 'g' on s///g
set incsearch " Jump to the first instance as you type the search term
set showmatch " always show matching ()'s
set hlsearch " highlight all of the search terms
" Whitespace and indentation
set tabstop=4 " a tab is four spaces.
set shiftwidth=4 " four spaces for auto-indenting
set softtabstop=4
set expandtab " insert spaces instead of tabs
set smartindent " follow c-like indentation guidelines
set list " show whitespace as defined by listchars
set listchars=tab:»·,trail:·,extends:…
set showbreak=\ \ …\
set autoindent " copy indent from current line when starting a new line
set shiftround " round to shiftwidth instead of inserting tabstop characters
" Line wrapping, cursors, cursor lines
set nowrap " dont display long-lines as wrapped
set textwidth=119 " automatically try to break long lines as they are typed
set scrolloff=15 " always show lines of code above/below cursor
set sidescroll=5 " always show extra context characters horizontally
set colorcolumn=120 " show a column indicating max line length
" Tame auto formatting, see :h fo-table
set formatoptions=
set formatoptions+=c " auto-wrap comments using textwidth
set formatoptions+=r " insert current comment leader when hitting <enter>
set formatoptions+=q " allow reformatting of comments with gq
set formatoptions+=n " when formatting text, recognize numbered lists
set formatoptions+=1 " break long lines before single char words instead of after
" User interface
set spell " enable spelling by default
set spelllang=en_us " when spelling is enabled, use US English dictionary
set title "set xterm title to vim title
set titleold=""
set wildmenu " improve auto complete menu
set wildmode=longest:full,full " when tab is pressed, show a list similar to ls
set wildignore+=*.pyc,*.o,*.zwc " hide certain files form wildmenu
set nofoldenable "I dont like folding text, so disable it everywhere
set diffopt=filler,context:1000000 " filler is default and inserts empty lines for sync
set backspace=indent,eol,start " Backspace over everything
set laststatus=2 " always show status bar
set noshowmode " dont display addition '-- INSERT --' below airline
set number " display line numbers
set ruler " display cursor location, only applies when no airline plugin
set mouse=a " mouse can be used to move and select windows, select text
set ttymouse=sgr " use sgr mode for mouse for xterm controls + more columns
set ttimeoutlen=10 " decrease timeout for terminal keycodes for faster insert exits
set ttyfast " it is fast, this aint no modem
set clipboard=unnamedplus " use the clipboard as the unnamed register
set cmdheight=1 " better display of messages
set updatetime=1000 " one second
set belloff=all " disable the bell for everything
set completeopt=menuone,noinsert
set showcmd " display an active vim sequence if there is one
set notimeout " a vim command in-progress will not expire, <esc> to exit
set splitbelow " open new hsplits to the bottom
set splitright " open new vsplits to the right
"-------
"Keymaps
"-------
"
" change leader to space, nicer to type. You lose some sort of 'move to next char' command.
let g:mapleader = "\<Space>"
" toggle spelling quickly
nnoremap <silent> <leader>os :set spell! spell?<CR>
" toggle line numbers
nnoremap <silent> <leader>on :set number! number?<CR>
" toggle relative number
nnoremap <silent> <leader>or :set relativenumber! relativenumber?<CR>
" navigate through quickfix and locationlists
nnoremap <silent> <leader>q :cnext<CR>
nnoremap <silent> <leader>Q :cprevious<CR>
nnoremap <silent> <leader>l :lnext<CR>
nnoremap <silent> <leader>L :lprevious<CR>
nnoremap <silent> <leader>w :w<CR>
" use leader {y|d|p} for interacting with the system clipboard
vnoremap <Leader>y "+y
nnoremap <Leader>p "+p
nnoremap <Leader>P "+P
vnoremap <Leader>p "+p
vnoremap <Leader>P "+P
" Switch between the last two files
nnoremap <Leader>a <C-^>
" Spell check the last error.
" <ctrl-g>u create undo marker (before fix) so we can undo/redo this
" change. Otherwise vim treats the spelling correction as the
" same change as our edit.
" esc enter normal mode
" [s jump back to previous spelling mistake
" 1z= take the first correction
" `] jump back
" a continue editing
" <ctrl-g>u create another undo marker
inoremap <C-l> <c-g>u<Esc>[s1z=`]a<c-g>u
" Begin a word search and replace
nnoremap <leader>R :%s/\<<C-r><C-w>\>//c<Left><Left>
" Keymaps that alter default behavior
" -----------------------------------
" Dont clobber the yank register when replacing text by pasting on top of a visual selection
xnoremap <silent> p p:let @+=@0<CR>:let @"=@0<CR>
" Advance to next misspelling after adding a word to the spellfile.
noremap zg zg]s
" typing jj in insert mode gets you out.
inoremap jj <Esc>
" vim training wheels: dont allow arrow keys!
nnoremap <up> <nop>
nnoremap <down> <nop>
nnoremap <left> <nop>
nnoremap <right> <nop>
" fix direction keys for line wrap, other wise they jump over wrapped lines
nnoremap j gj
nnoremap k gk
"remap f1. I'll type :help when I want it
noremap <F1> <ESC>
inoremap <F1> <ESC>
" I have never intentionally entered the mode that q: gives.
noremap q: :q
nnoremap Q <nop>
"Use a simpler keymapping for the menu:
"hitting enter on a selection accepts the selection and closes the menu.
inoremap <expr> <CR> pumvisible() ? "\<C-y>" : "\<C-g>u\<CR>"
"hitting escape rejects the completion, reverts the texts, and closes the menu.
"inoremap <expr> <esc> pumvisible() ? "\<C-e>" : "<Esc>"
"pressing up and down select the next or previous menu selection.
inoremap <expr> <Down> pumvisible() ? "\<C-n>" : "\<Down>"
inoremap <expr> <Up> pumvisible() ? "\<C-p>" : "\<Up>"
"ctrl-j and ctrl-k can be used in place of up and down.
inoremap <expr> <C-j> pumvisible() ? "\<C-n>" : "\<C-j>"
inoremap <expr> <C-k> pumvisible() ? "\<C-p>" : "\<C-k>"
" Indent in visual and select mode automatically re-selects.
vnoremap > >gv
vnoremap < <gv
" command mode replacements
" -------------------------
" :wq when I meant :w. Nudges towards using :x
cabbrev wq w
" :W isnt a command, and I usually intend on :w
cabbrev W w
" :X is a strange crypto thing that I dont care about, intention is :x
cabbrev X x
" :Q enters modal ex mode, I'm happy with just ex command line. Generally mistyped :q
cabbrev Q q
" Similar to above, I generally mean :qa
cabbrev Qa qa
" Tabnew -> tabnew
cabbrev Tabnew tabnew
" Allow saving of files as sudo when I forgot to start vim using sudo.
command Sudow :execute ':silent w !sudo tee % > /dev/null' | :edit!
" Close all but the current buffer (or any that arent yet saved)
command! BufOnly silent! execute "%bd|e#|bd#"
augroup allfiles
"Wipe out the allfiles group for when we reload the vimrc. Otherwise we just keep reattaching commands
autocmd!
"autowrap text when working in markdown files
autocmd FileType markdown setlocal formatoptions+=t
"consider '-' as part of the same word
autocmd FileType markdown setlocal iskeyword+=-
"Spell checking when working with markdown
autocmd FileType markdown setlocal spell
"Set indentation and line width for markdown
autocmd FileType markdown setlocal textwidth=79 colorcolumn=80 sw=2 sts=2 et
"Spell checking during gitcommit.
autocmd FileType gitcommit setlocal spell
"Customize python settings
autocmd FileType python setlocal textwidth=99 colorcolumn=100 sw=4 sts=4 et
"Customize vimL settings
autocmd FileType vim setlocal textwidth=99 colorcolumn=100 sw=2 sts=2 et
"Change lua tabstops to be more lua-esque
autocmd FileType lua setlocal sw=2 sts=2 et
"Close the preview window if it is open
autocmd InsertLeave * pclose
augroup END
if filereadable(expand($HOME.'/.vimrc.plugins'))
source $HOME/.vimrc.plugins
set background=dark
colorscheme onedarkhc
endif
" Always use undercurl for spelling mistakes
let &t_Cs = "\e[4:3m"
let &t_Ce = "\e[4:0m"
highlight SpellBad cterm=undercurl
highlight SpellBad gui=undercurl