This repository has been archived by the owner on May 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
vimrc
258 lines (192 loc) · 6.85 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
""""""""""
" Pathogen:
" Manage plugins in separate directories by manipulating runtimepath.
" https://github.com/tpope/vim-pathogen
runtime bundle/pathogen/autoload/pathogen.vim
execute pathogen#infect()
filetype plugin indent on
""""""""""
" Color scheme
set background=dark
colorscheme jellybeans_pda
syntax enable
""""""""""
" Settings
" Indicator after 80 characters.
set colorcolumn=81
" vi is dead, long live vim
set nocompatible
" Show line numbers
set number
" Smart indenting when starting new line
set smartindent
" Indent with two spaces
set expandtab
set tabstop=2
set softtabstop=2
set shiftwidth=2
" (1s: indent 1 * shiftwidth within parentheses; default 2 * shiftwidth.
" m1: closing parenthesis on new line matches indentation of opening line.
set cinoptions=(1s,m1
" Allow backspacing over indents and start of insertion point.
set backspace=indent,start
" Highlight trailing whitespace etc
highlight ExtraWhitespace ctermbg=darkgreen guibg=darkgreen
autocmd ColorScheme * highlight ExtraWhitespace ctermbg=red guibg=red
match ExtraWhitespace /\s\+\%#\@<!$/
" Make tabs and trailing spaces visible when `list` is set.
set listchars=tab:>-,trail:-
" Allow unsaved buffers to be hidden (backgrounded).
set hidden
" Jump to matching HTML tag, if/else/endif etc using "%"
runtime macros/matchit.vim
" Navigatable tab completion from Vim command line
set wildmenu
set wildmode=list:longest
" Ignore case in searches, unless search contains upper case
set ignorecase
set smartcase
" Minimum number of lines to keep above/below cursor when scolling
set scrolloff=3
" Swap files in a central location, no swap files amongst project.
" Can be a bad idea when editing several files of the same name.
set backupdir=~/.vim/swap
set directory=~/.vim/swap
" Show line and column number, relative scroll position etc.
set ruler
" Use visual bell instead of beeping.
set visualbell
" short info tokens, short command line messages, no intro.
set shortmess=atI
" Number of commands remembered.
set history=1000
" Default to Unicode/UTF-8 rather than latin1
set encoding=utf-8
" Highlight the screen line of the cursor, easier to find the cursor.
set cursorline
" Terminals are plenty fast these days.
set ttyfast
" The last window will have a status line: always.
set laststatus=2
" Mouse for scrolling etc in console.
" a = normal + visual + insert + command-line + help files
set mouse=a
" Resize split panes with mouse within tmux.
" Also get live-updated text selection with mouse drag.
" sgr: backwards compatible with xterm2 mode but works beyond 223 columns.
set ttymouse=sgr
" Mapping and escape timeouts.
set timeout
set timeoutlen=1000 " mapped sequences
set ttimeoutlen=10 " escape sequence delay
" Link vim's default delete/yank register to the system clipboard.
" unnamed = "* = PRIMARY buffer in X.
" unnamedplus = "+ = CLIPBOARD buffer in X.
set clipboard=unnamed
""""""""""
" File types
" Front-end whitespace: four space indentation
autocmd FileType javascript setlocal sts=4 ts=4 sw=4 expandtab
autocmd FileType scss setlocal sts=4 ts=4 sw=4 expandtab
" PHP whitespace: four space indentation
" https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md
autocmd FileType php setlocal sts=4 ts=4 sw=4 expandtab
" Python whitespace: four space indentation.
" http://legacy.python.org/dev/peps/pep-0008/#tabs-or-spaces
autocmd FileType python setlocal sts=4 ts=4 sw=4 expandtab
" Ruby ERB template whitespace: four space indentation
" (99designs style guide)
autocmd FileType eruby setlocal sts=4 ts=4 sw=4 expandtab
" Flex: lex-style syntax, indentation as 4 spaces.
autocmd BufRead,BufNewFile *.flex setlocal ft=lex sts=4 ts=4 sw=4 expandtab
" Shell scripts are posix (same as ksh mode, similar to bash mode)
" Fixes some syntx highlighting errors like A=$(subcommand)
" See: https://github.com/b4winckler/vim/blob/9592d73105979470e22662bc21fe7433f13626c0/runtime/syntax/sh.vim#L269-L274
let g:is_posix=1
""""""""""
" Keyboard and Shortcuts
" Leader of '\' is too far from home row.
let mapleader = ";"
let g:mapleader = ";"
" Unbind the cursor keys in insert, normal and visual modes.
for prefix in ['n', 'v']
for key in ['<Up>', '<Down>', '<Left>', '<Right>']
exe prefix . "noremap " . key . " <Nop>"
endfor
endfor
" Arrow keys navigate split windows!
nmap <Up> <C-W><Up>
nmap <Down> <C-W><Down>
nmap <Left> <C-W><Left>
nmap <Right> <C-W><Right>
" Show hidden chars as specified by listchars (e.g. tabs, trailing space)
nmap <silent> <leader>s :set list!<CR>
" Strip trailing whitespace
nnoremap <leader>W :%s/\s\+$//<cr>:let @/=''<CR>
" Quick-edit .vimrc
nnoremap <leader>ev <C-w><C-v><C-l>:e $MYVIMRC<cr>
" Convert to Ruby 1.9 hash syntax
noremap <leader>9 :s/:\(\S\+\)\s\+=>\s\+/\1: /g<cr>
" Convert Ruby hash from Symbol keys to String keys
noremap <leader>hs :s/\([A-Za-z0-9_]\+\):\(\s\+\)/"\1" =>\2/g<cr>
" Convert CSS `squished:rule; ` into `nice: rule;`
noremap <leader>c :s/^\(\s*\)\([a-z-]\+\):\([^ \t].*\);\s*$/\1\2: \3;/<cr>
" Send "!!" to tmux, to repeat last shell command.
map <leader>!! :wall \| call Send_to_Tmux("!!\n")<cr>
map <leader>m :wall \| :call Send_to_Tmux("make\n")<CR>
" Set a current spec file with R, execute it via tmux with r.
map <leader>R :let g:specFile = @% \| echo "RSpec file: " . g:specFile<CR>
map <leader>r :wall \| :call Send_to_Tmux("time rspec -f d " . g:specFile . "\n")<CR>
" Reselect visual block after indent (thanks @twe4ked)
vnoremap < <gv
vnoremap > >gv
""""""""""
" Abbreviations
abbreviate goerr if err != nil {return err}
abbreviate pry! require "pry"; binding.pry
""""""""""
" Plugins
" ctrlp.vim
let g:ctrlp_arg_map = 1 " prompt for open mode
let g:ctrlp_max_height = 16
let g:ctrlp_custom_ignore = ''
let g:ctrlp_custom_ignore .= '/\..*/\|'
let g:ctrlp_custom_ignore .= '/tmp/\|'
let g:ctrlp_custom_ignore .= '/assets/\|'
let g:ctrlp_custom_ignore .= '/node_modules/\|'
let g:ctrlp_custom_ignore .= 'REGEX_TERMINATOR'
nnoremap <leader>ga :CtrlP app/<cr>
nnoremap <leader>gs :CtrlP spec/<cr>
nnoremap <leader>gm :CtrlP app/models/<cr>
nnoremap <leader>gv :CtrlP app/views/<cr>
nnoremap <leader>gc :CtrlP app/controllers/<cr>
" NERDTree
nmap <silent> <leader>n :NERDTreeToggle<CR>
" checksyntax: auto-check Ruby files on save.
if !exists('g:checksyntax')
let g:checksyntax = {}
let g:checksyntax['ruby'] = {'auto': 1, 'prepare': 'compiler ruby', 'cmd': 'ruby -c', 'okrx': 'Syntax OK\|No Errors'}
endif
" Airline
" https://github.com/bling/vim-airline
" https://github.com/bling/vim-airline/blob/master/doc/airline.txt
let g:airline_left_sep = '▚'
let g:airline_right_sep = '▞'
let g:airline_mode_map = {
\ 'n' : 'N',
\ 'i' : 'I',
\ 'R' : 'REPLACE',
\ 'v' : 'VISUAL',
\ 'V' : 'V-LINE',
\ 'c' : 'CMD ',
\ '': 'V-BLCK',
\ }
" vim-json
" Disable crazy quote concealing. Show the actual file.
let g:vim_json_syntax_conceal = 0
" vim-go
if executable("goimports")
let g:go_fmt_command = "goimports"
endif