-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvimrc
325 lines (264 loc) · 9.37 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
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
" requires pathogen to be installed, which is taken care of by vim-setup.sh
filetype off
execute pathogen#infect()
syntax enable
filetype plugin indent on
set nocompatible
set modelines=0
set ruler
set wrap
set textwidth=79
set colorcolumn=85
set formatoptions=qrn1
set encoding=utf-8
set background=dark
let g:solarized_termcolors=256
colorscheme solarized
highlight LineNr ctermfg=red
" vim-indent-guides setup
let g:indent_guides_auto_colors = 0
autocmd VimEnter,Colorscheme * :hi IndentGuidesOdd guibg=red ctermbg=3
autocmd VimEnter,Colorscheme * :hi IndentGuidesEven guibg=green ctermbg=4
" vim-airline setup
set backupdir=$HOME/.vim/backup "could get rid of this I guess
set nobackup
set noswapfile
set nolazyredraw
set ch=2
set report=0
set autoread
set mouse=a
set mousefocus
set mousemodel=extend
set selectmode=mouse
set title
set shortmess=atI
set showmatch
set clipboard=unnamed
"set paste "this is the preferred behaviour when actually pasting into vim,
"preventing all of those extraneous and incorrect newlines, buy it'd
"not helpful in other contexts.
set backspace=indent,eol,start
set hlsearch
set incsearch
set ignorecase "case insensitive searching
set magic "TODO: I'm not sure what this does, but it sounds like a good thing
set smartcase "however, if I *do* include a capital letter, search is case sensitive
set nojoinspaces " use one space, not two, after punctuation
set smartindent
set formatoptions+=n
set tabstop=2
set softtabstop=2
set shiftwidth=2
set expandtab
set relativenumber
set number
set scrolloff=10
set cursorline
au WinLeave * setlocal nocursorline "maybe I like this, maybe I don't
au WinEnter * setlocal cursorline
set cursorcolumn
"auto commands? That is interesting. Could use those for window resizing?
"au WinLeave * set nocursorline nocursorcolumn
"au WinEnter * set cursorline cursorcolumn
set autoindent
set copyindent
set visualbell
set noerrorbells
set showmode
set showcmd
set hidden
set wildmode=longest,list,full
set wildmenu
set laststatus=2
" i think the visual selection mode keys are backwards
noremap v V
noremap V v
" split resizing is a pain, let's try this out
noremap < <C-w><
noremap > <C-w>>
" sane tab behaviour when in normal mode
nnoremap <S-Tab> v<<Esc>
nnoremap <Tab> v><Esc>
" while in visual mode, make it easy to indent stuff
vnoremap <Tab> >gv
vnoremap <S-Tab> <gv
" pressing enter should be different from navigating up/down;
" just add the damn newline on the line that i'm on, shifting things down
nnoremap <CR> ^i<Cr><Esc>
" of course, maybe you mean to put the newline below the current line. I can't
" read your mind
" this needs to be fixed, it doesn't maintain the tab indent level of the line
" below
nnoremap <S-CR> gj$i<Cr><Esc>
" defaults for start and end of a line are stupid and so far from homerow keys
noremap H ^
noremap L $
" it's way more common that I'm deleting an entire word
" than deleting from my current cursor position to the end of the word
noremap dw daw
noremap daw dw
"TODO: allow for command delete, like mac os x
" which would delete an entire line
" and option-delete which would delete up to the beginning of the current
" word, including spaces between the cursor and the word
" get 'normal' outcome from pressing the backspace key in normal mode
noremap <BS> hx
" look into https://github.com/haya14busa/incsearch.vim for improved searching
" if i'm working with long lines (don't do it!) this moves based on displayed lines,
" not 'physical' lines
noremap j gj
noremap k gk
noremap gj j
noremap gk k
" no need for awkward shift key pressing to enter commands
nnoremap ; :
" Space is the easiest key to reach by both hands, and allows for way more interesting keybindings
let mapleader="\<Space>"
" quick common actions
noremap <leader>w :w<Cr>
noremap <leader>W :w!<Cr>
noremap <leader>e :e<Space>
" would be really cool to have this do something smart based on file context
noremap <leader>q :q<cr>
noremap <leader>Q :q!<cr>
noremap qq :q<cr>
noremap Q :q!<cr>
noremap <leader>z <C-z>
" page up/down is obnoxious with standard keys; may use the leader?
noremap <leader>k <C-b>
noremap <leader>j <C-d>
" easier redo, though I was thinking about making it shift-u, like with tabbing
noremap <leader>r <C-r>
" faster search and replace
noremap <leader>f :s/
noremap <leader>F :%s/
nmap <silent> <leader>/ :nohlsearch<cr>
" stop that stupid window from popping up
map q: :q
" force myself to use the hjkl keys for navigation
nnoremap <up> <C-w>+
nnoremap <down> <C-W>-
nnoremap <left> <C-w><
nnoremap <right> <C-w>>
inoremap <up> <nop>
inoremap <down> <nop>
inoremap <left> <nop>
inoremap <right> <nop>
set splitbelow
set splitright
" faster nav between splits
nnoremap <leader><leader>h <C-W><C-H>
nnoremap <leader><leader>j <C-W><C-J>
nnoremap <leader><leader>k <C-W><C-K>
nnoremap <leader><leader>l <C-W><C-L>
" faster movement between tabs
nnoremap tt gt
nnoremap TT gT
" move the line below the current line down, but return to the current position
" on the current line
"inoremap <S-Enter> :$<Cr>
" while in insert mode, jk is a quick way to back out
inoremap jk <Esc>
inoremap jj <Esc>
inoremap kj <Esc>
" I like how shift+tab does the opposite of tab, so it makes sense to do the same for moving between words
noremap W b
" toggle invisible chars and show them textmate style
nmap <leader>l :set list!<Cr>
set listchars=tab:▸\ ,eol:¬
" quickly toggle between two files in a split
nnoremap <leader><leader>e <c-^>
" check syntax of coffeescript
" maybe change this to make it a more general purpose syntax aware linter?
" so when a file is opened an autocommand runs and sets up a key mapping for
" the linter/compiler/whatever tool is appropriate for that lang?
autocmd FileType coffee nnoremap <leader><leader>C :!coffee %<Cr>
" find all lines that have been marked debugger and comment them out
" it would be nice to have a way to toggle debugger calls with a single command
"autocmd FileType coffee nnoremap <leader><leader>dd :%s/debugger/#debugger/gi<cr>
autocmd FileType coffee nnoremap <leader><leader>dd :call ToggleJSDebugging()<cr>
"TODO: broken
autocmd FileType coffee nnoremap <leader><leader># :call CommentLines()<cr>
function CommentLines()
echo "Called CommentLines()"
normal gv"xy
let result = getreg("x")
echo result
endfunction
"TODO: fill this in so it works!
function ToggleJSDebugging()
echo "Called ToggleJSDebugging()"
"find all instances of "debugger" and set to "#debugger"
"find all instances of "#debugger" and set to "debugger"
endfunction
" easy open/close of NERDTree
nnoremap <leader>n :NERDTree<Cr>
nnoremap <leader><leader>n :NERDTreeClose<Cr>
"let NERDTreeShowHidden=1 "do you need to see hidden files all the time? It's a single "I" away from being visible at any point.
"nnoremap <leader>n :E<Cr> "I'm undecided whether I like having nerdtree stay
"open or not.
" easy add to git
nnoremap <leader><leader>ga :!git add -p<Cr>
nnoremap <leader><leader>gc :!git commit<Cr>
nnoremap <leader><leader>gd :!git diff<Cr>
nnoremap <leader><leader>gdh :!git diff HEAD<Cr>
nnoremap <leader><leader>gl :!git l<Cr>
nnoremap <leader><leader>glp :!git log -p<Cr>
nnoremap <leader><leader>gpp :!git push<Cr>
"copy to shared clipboard; maybe remap the default y/p?
nnoremap <leader>y +y
nnoremap <leader>p "*y
vnoremap <leader>y "*y
vnoremap <leader>p "*p
nnoremap <leader><leader>p :call TogglePaste()<cr>
function TogglePaste()
if &paste
set nopaste
else
set paste
endif
endfunction
"an example of how autocommands can work
"use it to set tabstop and other whitespace prefs on a per language basis
"or to set up a linting/compiling shortcut key that will be language specific
"au Filetype ruby call SetRubyOptions()
"function SetRubyOptions()
" echo "You're working on a Ruby file!"
"endfunction
autocmd BufNewFile,BufRead Gemfile*,Guardfile* set filetype=ruby
"autocmd BufNewFile,BufRead *.slim set filetype=slim
if executable('ag')
set grepprg=ag\ --nogroup\ --column\ --smart-case\ --nocolor\ --follow
set grepformat=%f:%l:%c:%m
" Use ag in CtrlP for listing files.
let g:ctrlp_user_command = 'ag %s -l --nocolor -g ""'
" ag is fast enough that CtrlP doesn't need to cache
let g:ctrlp_use_caching = 0
endif
" bind K to grep word under cursor
"nnoremap K :grep! "\b,C-R><C-W>\b"<CR>:cw<CR>
"nmap <silent> <leader><leader>s :set spell!<CR>"not sure if I want spellcheck
"on always, or toggled, so leave this here to decide on later
set spelllang=en_ca
autocmd Filetype gitcommit setlocal spell textwidth=72
autocmd BufRead,BufNewFile *.md set filetype=markdown
autocmd Filetype markdown setlocal spell
" here is where I make poor decisions and hardcode my less/css lint preferences
" into shortcuts, which is probably the exact opposite of what I should be
" doing
" Find all class selectors that have attributes on a single line
" Will also match on multiple attributes on one line
autocmd Filetype less nnoremap <leader><leader>M :%s/{\n\?[0-9a-zA-Z:. -@]\+;\n\?}//gn<Cr>
" convert file to binary/hex format
noremap <leader>hh :% ! xxd<Cr>
noremap <leader>HH :% ! xxd -r<Cr>"
" protect against lazy writing and anti-inclusive language
" courtesy of Jess Telford @jesstelford
highlight badWords ctermbg=red ctermfg=white
fun! HiBadWords()
match badWords /\c\<\(obviously\|basically\|simply\|of\scourse\|clearly\|just\|everyone\sknows\|however\|so,\|easy\)\>/
endfun
" This may be useful files other than markdown.
autocmd InsertEnter *.md call HiBadWords()
autocmd InsertLeave *.md call HiBadWords()