-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path.vimrc
281 lines (226 loc) · 9.03 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
" Use Vim settings, rather then Vi settings (much better!).
" This must be first, because it changes other options as a side effect.
set nocompatible
" source ~/.vimrc.before if it exists.
if filereadable(expand("~/.vimrc.before"))
source ~/.vimrc.before
endif
" Install vim-plug if not installed
if empty(glob('~/.vim/autoload/plug.vim'))
silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs
\ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
endif
call plug#begin('~/.vim/plugged')
Plug 'hwartig/vim-seeing-is-believing' " get the result of ruby code
Plug 'ervandew/supertab'
Plug 'kchmck/vim-coffee-script'
Plug 'skwp/greplace.vim'
Plug 'tomtom/tcomment_vim' " Toggle comments easily
Plug 'thoughtbot/vim-rspec'
Plug 'Townk/vim-autoclose' " Insert matching pair () {} []
Plug 'tpope/vim-bundler'
Plug 'tpope/vim-dispatch' " Run commands in tmux pane
Plug 'tpope/vim-endwise' " Add end after ruby blocks
Plug 'tpope/vim-fugitive' " Git wrapper
Plug 'tpope/vim-rails' " Rails support
Plug 'tpope/vim-repeat'
Plug 'tpope/vim-surround' " Easily change quotes/bracket pairs
Plug 'tpope/vim-unimpaired' " Misc mappings like ]<space> or ]c
Plug 'vim-ruby/vim-ruby' " support for ruby
Plug 'ctrlpvim/ctrlp.vim' " searching in vim
Plug 'rizzatti/dash.vim' " support for dash
Plug 'mileszs/ack.vim' " Use Ag for search
Plug 'terryma/vim-multiple-cursors' " Sublime text style multiple cursors
Plug 'nanotech/jellybeans.vim' " vim color scheme
Plug 'dyng/ctrlsf.vim' " Find in multiple files
Plug 'tpope/vim-haml'
Plug 'scrooloose/nerdtree' " Nerd Tree plugin for navigation
call plug#end() " All of your Plugins must be added before the following line
" ================ General Config ====================
colorscheme jellybeans
set number relativenumber "Line numbers are good
set backspace=indent,eol,start "Allow backspace in insert mode
set history=1000 "Store lots of :cmdline history
set showcmd "Show incomplete cmds down the bottom
set showmode "Show current mode down the bottom
set gcr=a:blinkon0 "Disable cursor blink
set visualbell "No sounds
set autoread "Reload files changed outside vim
" This makes vim act like all other editors, buffers can
" exist in the background without being in a window.
" http://items.sjbach.com/319/configuring-vim-right
set hidden
"turn on syntax highlighting
syntax on
" Change leader to a comma because the backslash is too far away
" That means all \x commands turn into ,x
" The mapleader has to be set before vundle starts loading all
" the plugins.
let mapleader=","
set timeout timeoutlen=1500
" ================ Turn Off Swap Files ==============
set noswapfile
set nobackup
set nowb
" ================ Persistent Undo ==================
" Keep undo history across sessions, by storing in file.
" Only works all the time.
if has('persistent_undo') && !isdirectory(expand('~').'/.vim/backups')
silent !mkdir ~/.vim/backups > /dev/null 2>&1
set undodir=~/.vim/backups
set undofile
endif
" ================ Folds ============================
set foldmethod=indent "fold based on indent
set foldnestmax=3 "deepest fold is 3 levels
set nofoldenable "dont fold by default
"
" ================ Scrolling ========================
set scrolloff=8 "Start scrolling when we're 8 lines away from margins
set sidescrolloff=15
set sidescroll=1
" ================ Search ===========================
set incsearch " Find the next match as we type the search
set hlsearch " Highlight searches by default
set ignorecase " Ignore case when searching...
set smartcase " ...unless we type a capital
" ================ Indentation ======================
set autoindent
set smartindent
set smarttab
set shiftwidth=2
set softtabstop=2
set tabstop=2
set expandtab
filetype plugin on
filetype indent on
" Display tabs and trailing spaces visually
set list listchars=tab:\ \ ,trail:·
set linebreak "Wrap lines at convenient points
" ================ Custom Settings ========================
" Window pane resizing
nnoremap <silent> <Leader>[ :exe "resize " . (winheight(0) * 3/2)<CR>
nnoremap <silent> <Leader>] :exe "resize " . (winheight(0) * 2/3)<CR>
" ===== Seeing Is Believing =====
" " Assumes you have a Ruby with SiB available in the PATH
" " If it doesn't work, you may need to `gem install seeing_is_believing -v
" 3.0.0.beta.6`
" " ...yeah, current release is a beta, which won't auto-install
"
" " Annotate every line
"
nmap <leader>b :%!seeing_is_believing --timeout 12 --line-length 500 --number-of-captures 300 --alignment-strategy chunk<CR>;
"
" " Annotate marked lines
"
nmap <leader>n :%.!seeing_is_believing --timeout 12 --line-length 500 --number-of-captures 300 --alignment-strategy chunk --xmpfilter-style<CR>;
"
" " Remove annotations
"
nmap <leader>c :%.!seeing_is_believing --clean<CR>;
"
" " Mark the current line for annotation
"
nmap <leader>m A # => <Esc>
"
" " Mark the highlighted lines for annotation
"
vmap <leader>m :norm A # => <Esc>
autocmd StdinReadPre * let s:std_in=1
map <Leader>y "+y
map <Leader>d "+d
let g:tmux_navigator_no_mappings = 1
nnoremap <silent> {Left-mapping} :TmuxNavigateLeft<cr>
nnoremap <silent> {Down-Mapping} :TmuxNavigateDown<cr>
nnoremap <silent> {Up-Mapping} :TmuxNavigateUp<cr>
nnoremap <silent> {Right-Mapping} :TmuxNavigateRight<cr>
nnoremap <silent> {Previous-Mapping} :TmuxNavigatePrevious<cr>
let g:spec_runner_dispatcher = "VtrSendCommand! {command}"
" RSpec.vim mappings
map <Leader>t :call RunCurrentSpecFile()<CR>
map <Leader>s :call RunNearestSpec()<CR>
map <Leader>l :call RunLastSpec()<CR>
map <Leader>a :call RunAllSpecs()<CR>
nnoremap <leader>irb :VtrOpenRunner {'orientation': 'h', 'percentage': 50, 'cmd': 'irb'}<cr>
" For ruby block selections
runtime macros/matchit.vim
" For Running plain Ruby test scripts
nnoremap <leader>r :RunSpec<CR>
nnoremap <leader>l :RunSpecLine<CR>
nnoremap <leader>e :RunSpecLastRun<CR>
nnoremap <leader>cr :RunSpecCloseResult<CR>
" ================ My own customization ==============
set lazyredraw " Don't redraw screen when running macros.
function! RenameFile()
let old_name = expand('%')
let new_name = input('New file name: ', expand('%'), 'file')
if new_name != '' && new_name != old_name
exec ':saveas ' . new_name
exec ':silent !rm ' . old_name
redraw!
endif
endfunction
map <leader>dd :Dash<cr>
map <leader>mv :call RenameFile()<cr>
map <leader>rm :!rm %
map <Leader>e :e <C-R>=escape(expand("%:p:h"),' ') . '/'<CR>
map <Leader>s :split <C-R>=escape(expand("%:p:h"), ' ') . '/'<CR>
map <Leader>v :vnew <C-R>=escape(expand("%:p:h"), ' ') . '/'<CR>
map <Leader>ac :sp app/controllers/application_controller.rb<cr>
map <Leader>bb :!bundle install<cr>
map <Leader>d orequire 'byebug'<cr>byebug<esc>:w<cr>
map <Leader>l oRails.logger.info "DEBUG: "
map <Leader>sc :sp db/schema.rb<cr>
map <Leader>F :CtrlSF -R "<C-R><C-W>"
nnoremap K :grep! "\b<C-R><C-W>\b"<CR>:cw<CR>
map <Leader>n :NERDTreeToggle<CR>
augroup myfiletypes
" Clear old autocmds in group
autocmd!
" autoindent with two spaces, always expand tabs
autocmd FileType ruby,eruby,yaml setlocal ai sw=2 sts=2 et
autocmd FileType ruby,eruby,yaml setlocal path+=lib
autocmd FileType ruby,eruby,yaml setlocal colorcolumn=80
" Make ?s part of words
autocmd FileType ruby,eruby,yaml setlocal iskeyword+=?
augroup END
" Set the tag file search order
set tags=./tags;
" Use Silver Searcher instead of grep
if executable('ag')
" Use ag over grep
set grepprg=ag\ --nogroup\ --nocolor
" Use ag in CtrlP for listing files. Lightning fast and respects .gitignore
let g:ctrlp_user_command = ['ag %s --files-with-matches -g ""']
let g:ctrlp_user_command += ['.git/', 'git --git-dir=%s/.git ls-files -oc --exclude-standard']
" ag is fast enough that CtrlP doesn't need to cache
let g:ctrlp_switch_buffer = 0
let g:ctrlp_use_caching = 0
let g:ctrlp_max_files=0
let g:ctrlp_max_depth=100
let g:ctrlp_working_path_mode = 'ra'
endif
" Make the omnicomplete text readable
highlight PmenuSel ctermfg=black
" Ignore stuff that can't be opened
set wildignore+=tmp/**
" Highlight the status line
highlight StatusLine ctermfg=blue ctermbg=yellow
" Format xml files
au FileType xml exe ":silent 1,$!xmllint --format --recover - 2>/dev/null"
" Use ag for text search
let g:ackprg = 'ag --vimgrep'
" Better? completion on command line
set wildmenu
" What to do when I press 'wildchar'. Worth tweaking to see what feels right.
set wildmode=list:full
set backupdir=~/.tmp
set directory=~/.tmp " Don't clutter my dirs up with swp and tmp file
let g:ctrlsf_ackprg = 'ag'
let g:ctrlsf_position = 'bottom'
let g:multi_cursor_use_default_mapping=0
let g:multi_cursor_next_key='<C-n>'
let g:multi_cursor_prev_key='<C-p>'
let g:multi_cursor_skip_key='<C-x>'
let g:multi_cursor_quit_key='<C-d>'