-
Notifications
You must be signed in to change notification settings - Fork 0
/
vimrc
400 lines (312 loc) · 12.9 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
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
" K. McCULLOCH VIMRC
" vim: foldmethod=marker
" PLUGINS ================================================================== {{{
" Overview of plugin structure from Learn Vimscript the Hard Way:
" http://learnvimscriptthehardway.stevelosh.com/chapters/42.html
" The two common plugin installers are Pathogen and Vundle. I use Vundle.
" Vundle works by adding all of the installed plugins to the runtimepath.
" The order of directories in the path determines the order in which scripts
" are loaded and applied.
" You can inspect the path using:
" :set runtimepath?
" The general execution order is:
" ~/.vim
" ~/.vim/bundle/{bundles_in_order_of_addition}
" $VIM/vimfiles
" $VIM/vimfiles/after
" ~/.vim/after
" ~/.vim/bundle/{bundles_in_order_of_addition}/after
" The after/ directory is a convention for overriding vim defaults and other
" plugins. If a plugin includes its own after/ directory it gets the last
" word, but this is rare.
" Initialize Vundle.
set nocompatible "use Vim (not Vi) option defaults
filetype off "required to initialize Vundle
" Set proper path to vim bundles, depending on environment
if !empty($KM_VIM)
set rtp+=$KM_VIM/vim/bundle/Vundle.vim
call vundle#begin($KM_VIM . '/vim/bundle')
else
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
endif
" Let vundle manage itself (required).
Plugin 'VundleVim/Vundle.vim'
" Essential plugins from scrooloose.
Plugin 'scrooloose/nerdcommenter'
Plugin 'scrooloose/nerdtree'
Plugin 'scrooloose/syntastic'
" Add git status to NERDTree
Plugin 'Xuyuanp/nerdtree-git-plugin'
" Help syntastic to use the project-local version of eslint.
Plugin 'mtscout6/syntastic-local-eslint.vim'
" React js syntax
Plugin 'pangloss/vim-javascript'
Plugin 'mxw/vim-jsx'
" Typescript js syntax
Plugin 'leafgarland/typescript-vim'
" Handlebars js syntax
Plugin 'mustache/vim-mustache-handlebars'
" Other window-related plugins.
Plugin 'vim-airline/vim-airline'
" The old showmarks script is now throwing a 'not possible to change sign'
" error on every buffer, so let's try the newer vim-signature plugin.
"Plugin 'zakj/vim-showmarks'
Plugin 'kshenoy/vim-signature'
" Colorscheme plugins.
Plugin 'altercation/vim-colors-solarized'
Plugin 'morhetz/gruvbox'
Plugin 'arcticicestudio/nord-vim'
" Drupal.
" This will clone down the entire vimrc repo, which includes some top-level
" documentation.
" The plugin itself will wind up in bundle/vimrc/bundle/vim-plugin-for-drupal.
Plugin 'https://git.drupalcode.org/project/vimrc.git', {'rtp': 'bundle/vim-plugin-for-drupal'}
" My personal libraries.
Plugin 'kmcculloch/vim-cabbrevplus'
Plugin 'kmcculloch/vim-fancy-layout'
call vundle#end()
" }}}
" FILETYPE ================================================================= {{{
" See :help filetype
" There are several discreet operations involved in filetype handling.
"
" The first is filetype detection. This is handled via filetype.vim files and
" files inside ftdetect/ directories.
" Vim will look inside its runtimepath for filetype.vim files.
" Next, it will look for ftdetect/ directories and run all of the files
" it finds.
" Note that it's also possible to do manually tweak the filetype using
" commands in files inside plugin/ directories which are always run when
" vim loads. The vimrc bundle for Drupal does this to append .drupal to
" certain files.
filetype on
" The next thing that happens is that vim sources ftplugin/ files whose names
" match the detected filetype. These set local buffer options.
filetype plugin on
" Next are indentation settings. These are files inside indent/ folders.
filetype indent on
" Very few filetypes have specialized indent files. Generally, indentation
" is based on general vim options.
" Here are the options for tabs:
set tabstop=2 "change the width of the tab character to x spaces
set expandtab "tell vim to insert spaces whenever the tab key is pressed
set softtabstop=2 "indicate how many spaces to use in lieu of a tab character
" Here are the options for autoindenting. Note that smartindent can interfere
" with file-specific indentation settings. The vimrc plugin always turns it
" on for .drupal files, but it interferes with scss indentation so I have
" disabled it in the after/ directory.
set shiftwidth=2 "indicate the number of characters used in autoindent
set autoindent "copy indent from current line when starting a new line
set nosmartindent "add an extra level of indentation for C-like files
set nocindent "more advanced C-like indentation
" Finally, vim loads files from the syntax/ directory to enable syntax
" highlighting.
syntax on
" }}}
" OPTIONS ================================================================== {{{
set nobackup "do not make a backup before overwriting a file
set noswapfile "do not use a swapfile for the buffer
set shortmess=atI "shorten various system messages
set visualbell "use the visual bell instead of beeping
set history=1000 "increase command-line history from 20 to 1000
set scrolloff=3 "scrolling offset of 3 lines at top/bottom
set timeout timeoutlen=3000 "set timeout gap for multi-key operations to 3 sec
set showcmd "show partial command in last line of the screen
" ignore search case when typing a lower-case search string
" note: This causes vimscript code to evaluate "foo" == "Foo" as true!
" http: //learnvimscriptthehardway.stevelosh.com/chapters/22.html
set ignorecase "causes foo to match foo, Foo, FOO
set smartcase "causes Foo only to match Foo
set incsearch "see results while typing
set hlsearch "search matches are highlighted
set nowrapscan "keep searches from wrapping around the end of the file
"set hidden "keep buffers loaded when they are abandoned
set nohidden
set confirm "prompt for save before unloading a modified buffer
set laststatus=2 "always show the status line
set statusline=%n: "buffer number
"set statusline+=%f "path to file, relative to directory where vim was launched
set statusline+=%t "filename only
set statusline+=%m "modified flag
set statusline+=\ %y "filetype in brackets
set statusline+=%= "right justify rest of status line
set statusline+=%l/%L "current line/total lines
set statusline+=\ %c "column number
set noruler "statusline takes precedence over ruler
set notitle "prefer to have username@hostname in bash window title per default
set number "turn on left-hand numbering
set numberwidth=5 "use 5 spaces for left-hand number column
set linebreak "wrap long lines rather than entering line breaks
" this doesn't seem to work
set switchbuf=useopen "buffer exists in open window, jump there
set modeline
set modelines=5
" to set paste, go into insert mode then use the F2 key
set pastetoggle=<F2>
" }}}
" NORMAL MODE MAPPINGS ===================================================== {{{
" use the space bar as the mapleader key
map <Space> <Leader>
" use the tab key for escape operations, such as cancelling prefix keys
" (eg. # for count)
nnoremap <tab> <Esc>
" make sure marks move us back to the specified location
" let's disable this while we get used to the new vim-signature plugin
"nnoremap ' `
" reverse paste/insert line to default to above for lowercase p/o
nnoremap p P
nnoremap P p
nnoremap o O
nnoremap O o
" keep cursor from jumping over multiline rows
nnoremap j gj
nnoremap k gk
" use the shift key to enhance movement
nnoremap J 5j
nnoremap K 5k
nnoremap H 10h
nnoremap L 10l
" delete movement commands into the null register
nnoremap d "_d
" delete to the end of the line into the null register
nnoremap D "_D
" delete single characters into the null register
nnoremap x v"_d
nnoremap X hv"_d
" move up or down half a page, then center screen
nnoremap <Leader>f 24jzz
nnoremap <Leader>F 24kzz
" require a leader stroke to use J to concatenate lines
nnoremap <Leader>J J
" a leader stroke followed by d/D deletes lines in confusing ways
nnoremap <Leader>d <Nop>
nnoremap <Leader>D <Nop>
" use u/U to make a word lower/upper case
nnoremap <Leader>U vawgU
nnoremap <Leader>u vawgu
" always search in "very magic" mode
nnoremap / /\v
" clear previous search string
nnoremap <Leader><Space> :let<Space>@/<Space>=<Space>""<CR>
" enter insert mode ready to append to the end of a line
nnoremap <Leader>a $a
" enter insert mode ready to prepend to the start of a line
nnoremap <Leader>i ^i
" insert a single character at the cursor point
nnoremap <Leader>r i_<Esc>r
" use the leader to move between windows
nnoremap <Leader>j <C-W><C-J>
nnoremap <Leader>k <C-W><C-K>
nnoremap <Leader>h <C-W><C-H>
nnoremap <Leader>l <C-W><C-L>
" open and edit .vimrc
nnoremap <leader>ev :edit $MYVIMRC<CR>
nnoremap <leader>sv :source $MYVIMRC<CR>
" when cursor is on word, use F10 to get info about syntax highlighting
nnoremap <F9> :echo "hi<" . synIDattr(synID(line("."),col("."),1),"name") . '> trans<' . synIDattr(synID(line("."),col("."),0),"name") . "> lo<" . synIDattr(synIDtrans(synID(line("."),col("."),1)),"name") . ">"<CR>
" Set a given window width to the proper width for code editing
" 87 = 80 chars + 5 for line numbers + 2 for marks
nnoremap <Leader>wf :vertical resize 87<CR>:set winfixwidth<CR>
" Display window width
nnoremap <Leader>wd :echo 'Window width: ' . winwidth(0)<CR>
nnoremap <Leader>wn :echo 'Window number: ' . winnr()<CR>
" Open current file in Chrome
nnoremap <Leader>gc :!open -a 'Google Chrome' %<CR><CR>
nnoremap <Leader>q :bp<bar>sp<bar>bn<bar>bd<CR><CR>
" }}}
" INSERT MODE MAPPINGS ===================================================== {{{
" exit insert mode and restore cursor position (no move left)
inoremap <tab> <Esc>`^
" }}}
" VISUAL MODE MAPPINGS ===================================================== {{{
" in visual mode, cancel any selection (gV prevents automatic reselection)
vnoremap <tab> <Esc>gV
" delete into the null register
vnoremap D "_d
" duplicate normal mode movement commands
vnoremap J 5j
vnoremap K 5k
vnoremap H 10h
vnoremap L 10l
xnoremap <Leader>f 24jzz
xnoremap <Leader>F 24kzz
" }}}
" OPERATOR-PENDING MODE MAPPINGS =========================================== {{{
" cancel any operator-pending command
onoremap <tab> <Esc>
" }}}
" COLORSCHEME ============================================================== {{{
" in general we like a dark background
set background=dark
" be sure we're using all of our terminal's 256 colors
" NOTE: To get the best effect with Gruvbox, run the shell script to
" set the precise 256 color values that Gruvbox likes
set t_Co=256
" GRUVBOX
let g:gruvbox_italic=0
let g:gruvbox_contrast_dark="hard"
" SOLARIZED
let g:solarized_italic=0
let g:solarized_underline=0
" TURN ON COLORSCHEME OF CHOICE
:silent! colorscheme gruvbox
"colorscheme solarized
" }}}
" NERDCOMMENTER============================================================= {{{
let g:NERDCustomDelimiters = {
\ 'php': {'left': '// ', 'leftAlt': '/*', 'rightAlt': '*/' }
\ }
" }}}
" NERDTREE ================================================================= {{{
let NERDTreeShowHidden=1
let NERDTreeShowBookmarks=1
let g:NERDTreeGitStatusShowIgnored=1
" }}}
" AIRLINE ================================================================== {{{
" Turn on airline's tabline extension to use the tabline to display buffers
let g:airline#extensions#tabline#enabled = 1
let g:airline#extensions#tabline#buffer_nr_show = 1
let g:airline#extensions#tabline#fnamemod = ':t'
let g:airline#extensions#tabline#buffer_nr_format = '%s:'
" }}}
" SYNTASTIC ================================================================ {{{
" For debugging
" @see https://medium.com/@hpux/vim-and-eslint-16fa08cc580f
":let g:syntastic_debug=3
":SyntasticCheck eslint
":mes
"let g:syntastic_mode_map = {
"\ "mode": "active",
"\ "passive_filetypes": ["html"] }
"let g:syntastic_php_checkers = ['php', 'phpcs']
"let g:syntastic_javascript_checkers = ['eslint']
" @todo confirm that this respects the .csslintrc directives inside a project.
"let g:syntastic_css_checkers = ['csslint']
"let g:syntastic_sass_checkers = ['sass_lint']
"let g:syntastic_scss_checkers = ['sass_lint']
"let g:syntastic_typescript_checkers = ['tslint']
" }}}
" CABBREV-PLUS ============================================================= {{{
:silent! call cabbrevplus#Cabbrev('nt', 'NERDTree')
:silent! call cabbrevplus#Cabbrev('nb', 'Bookmark')
:silent! call cabbrevplus#Cabbrev('nc', 'ClearBookmarks')
:silent! call cabbrevplus#Cabbrev('fi', 'FancyLayoutInit')
" Use our custom quit routines for all window/buffer delete commands
"call cabbrevplus#Cabbrev('bd', 'FancyLayoutQ')
"call cabbrevplus#Cabbrev('bw', 'FancyLayoutQ')
"call cabbrevplus#Cabbrev('bu', 'FancyLayoutQ')
"call cabbrevplus#Cabbrev('bun', 'FancyLayoutQ')
"call cabbrevplus#Cabbrev('q', 'FancyLayoutQ')
"call cabbrevplus#Cabbrev('wq', 'FancyLayoutWQ')
" }}}
" VIM-JSX ============================================================= {{{
let g:jsx_ext_required = 0
" }}}
" Safely load a .vimrc from the top-level of the current repository
" https://phyks.me/2014/07/specific-vim-config-per-git-repository.html
let git_path = system("git rev-parse --show-toplevel 2>/dev/null")
let git_vimrc = substitute(git_path, '\n', '', '') . "/.vimrc"
if !empty(glob(git_vimrc))
sandbox exec ":source " . git_vimrc
endif