-
Notifications
You must be signed in to change notification settings - Fork 7
/
swvimrc
376 lines (295 loc) · 9.26 KB
/
swvimrc
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
set shell=/bin/sh
set nocompatible
call plug#begin('~/.vim/plugged')
" vim plugins
Plug 'tomtom/tlib_vim'
Plug 'MarcWeber/vim-addon-mw-utils'
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
Plug 'junegunn/fzf.vim'
Plug 'tpope/vim-rails'
Plug 'vim-ruby/vim-ruby'
Plug 'jonathanfilip/vim-lucius'
Plug 'tpope/vim-git'
Plug 'tpope/vim-fugitive'
Plug 'tpope/vim-commentary'
Plug 'pangloss/vim-javascript'
Plug 'garbas/vim-snipmate'
Plug 'honza/vim-snippets'
Plug 'kchmck/vim-coffee-script'
Plug 'nono/vim-handlebars'
Plug 'groenewege/vim-less'
Plug 'tpope/vim-surround'
Plug 'digitaltoad/vim-pug'
Plug 'xolox/vim-notes'
Plug 'xolox/vim-misc'
Plug 'elixir-lang/vim-elixir'
Plug 'tpope/vim-endwise'
Plug 'jiangmiao/auto-pairs'
Plug 'scrooloose/syntastic'
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
Plug 'ngmy/vim-rubocop'
Plug 'thoughtbot/vim-rspec'
Plug 'tpope/vim-dispatch'
Plug 'freitass/todo.txt-vim'
call plug#end()
" Set solarized-colors
set t_Co=256
syntax enable
set background=dark
colorscheme lucius
set term=screen-256color
set t_ut=
let g:solarized_termcolors=256
" let g:solarized_termcolors=256
" Leader setting
let mapleader = ","
let maplocalleader = "\\"
set relativenumber
set number
set ruler
set autoindent
" Set encoding
set encoding=utf-8
" Whitespace stuff
set nowrap
set tabstop=2
set shiftwidth=2
set softtabstop=2
set expandtab
set list listchars=tab:\ \ ,trail:·
" Searching
set hlsearch
set incsearch
set ignorecase
set smartcase
map <leader>/ :noh<CR>
" Tab completion
set wildmode=list:longest,list:full
" Tweak netrw
let g:netrw_banner=0 " disable banner
let g:netrw_browsesplit=4 " open in prior window
let g:netrw_altv=1 " open splits to the right
let g:netrw_liststyle=3 " tree view
let g:netrw_list_hide=netrw_gitignore#Hide()
let g:netrw_list_hide.=',\(^\|\s\s\)\zs\.\S\+'
" More mappings under |netrw-browse-maps|
" Setup syntastic
set statusline+=%#warningmsg#
set statusline+=%{SyntasticStatuslineFlag()}
set statusline+=%*
let g:syntastic_always_populate_loc_list = 1
let g:syntastic_auto_loc_list = 1
let g:syntastic_check_on_open = 1
let g:syntastic_check_on_wq = 0
let g:airline_powerline_fonts = 1
" Annoying ERB warning silent
let g:syntastic_eruby_ruby_quiet_messages =
\ {'regex': 'possibly useless use .* void context'}
" Show airline without splits, as well
set laststatus=2
" Setup FZF
let g:fzf_action = {
\ 'ctrl-t': 'tab split',
\ 'ctrl-x': 'split',
\ 'ctrl-v': 'vsplit' }
" Default fzf layout
" - down / up / left / right
let g:fzf_layout = { 'down': '~40%' }
" Jump to existing buffers
let g:fzf_buffers_jump = 1
" [Tags] Command to generate tags file
let g:fzf_tags_command = 'ctags -R'
" Customize fzf colors to match your color scheme
let g:fzf_colors =
\ { 'fg': ['fg', 'Normal'],
\ 'bg': ['bg', 'Normal'],
\ 'hl': ['fg', 'Comment'],
\ 'fg+': ['fg', 'CursorLine', 'CursorColumn', 'Normal'],
\ 'bg+': ['bg', 'CursorLine', 'CursorColumn'],
\ 'hl+': ['fg', 'Statement'],
\ 'info': ['fg', 'PreProc'],
\ 'prompt': ['fg', 'Conditional'],
\ 'pointer': ['fg', 'Exception'],
\ 'marker': ['fg', 'Keyword'],
\ 'spinner': ['fg', 'Label'],
\ 'header': ['fg', 'Comment'] }
" Open files with <leader>f
map <leader>f :Files<cr>
" Open tags with <leader>t
map <leader>t :Tags<cr>
" Open marks with <leader>m
map <leader>m :Marks<cr>
" Open files in buffer with <leader>b
map <leader>b :Buffers<cr>
" Open files, limited to the directory of the current file, with <leader>gf
" This requires the %% mapping found below.
map <leader>gf :Files %%<cr>
" Open files limited to a specific rails-path
map <leader>gv :Files app/views<cr>
map <leader>gc :Files app/controllers<cr>
map <leader>gm :Files app/models<cr>
map <leader>gh :Files app/helpers<cr>
map <leader>gl :Files lib<cr>
map <leader>gp :Files public<cr>
map <leader>gs :Files spec<cr>
" Disable output and VCS files
set wildignore+=*.o,*.out,*.obj,.git,*.rbc,*.rbo,*.class,.svn,*.gem
" Ignore images and log files
set wildignore+=*.gif,*.jpg,*.png,*.log
" Disable archive files
set wildignore+=*.zip,*.tar.gz,*.tar.bz2,*.rar,*.tar.xz
" Ignore bundler and sass cache
set wildignore+=*/vendor/gems/*,*/vendor/cache/*,*/.bundle/*,*/.sass-cache/*
" Ignore rails temporary asset caches
set wildignore+=*/tmp/cache/assets/*/sprockets/*,*/tmp/cache/assets/*/sass/*
" Ignore custom folders
" set wildignore+=*/resources/*
" Ignore node modules
set wildignore+=node_modules/*
set wildignore+=/node_modules/*
" Disable temp and backup files
set wildignore+=*.swp,*~,._*
" Disable osx index files
set wildignore+=.DS_Store
" Remember last location in file
if has("autocmd")
au BufReadPost * if line("'\"") > 0 && line("'\"") <= line("$")
\| exe "normal g'\"" | endif
endif
function s:setupWrapping()
set wrap
set wrapmargin=2
set textwidth=72
endfunction
function s:setupMarkup()
call s:setupWrapping()
map <buffer> <Leader>p :Hammer<CR>
endfunction
" Thorfile, Rakefile, Vagrantfile and Gemfile are Ruby
au BufRead,BufNewFile {Gemfile,Rakefile,Vagrantfile,Thorfile,config.ru} set ft=ruby
" md, markdown, and mk are markdown and define buffer-local preview
au BufRead,BufNewFile *.{md,markdown,mdown,mkd,mkdn} call s:setupMarkup()
" add json syntax highlighting
au BufNewFile,BufRead *.json set ft=javascript
au BufRead,BufNewFile *.txt call s:setupWrapping()
" allow backspacing over everything in insert mode
set backspace=indent,eol,start
" load the plugin and indent settings for the detected filetype
filetype plugin indent on
" Opens an edit command with the path of the currently edited file filled in
" Normal mode: <Leader>e
map <Leader>e :e <C-R>=expand("%:p:h") . "/" <CR>
" Opens a tab edit command with the path of the currently edited file filled in
" Normal mode: <Leader>t
map <Leader>te :tabe <C-R>=expand("%:p:h") . "/" <CR>
" Inserts the path of the currently edited file into a command
" Command mode: Ctrl+P
cmap <C-P> <C-R>=expand("%:p:h") . "/" <CR>
" Use modeline overrides
set modeline
set modelines=10
" Directories for swp files
set backupdir=~/.vim/backup
set directory=~/.vim/backup
" % to bounce from do to end etc.
runtime! macros/matchit.vim
" Show (partial) command in the status line
set showcmd
" Switch between the last two files
nnoremap <leader><leader> <c-^>
" Add the currents files directory in command with %%
cnoremap %% <C-R>=expand('%:h').'/'<cr>
set winwidth=84
" Make the current window big, but leave others context
set winwidth=84
" We have to have a winheight bigger than we want to set winminheight. But if
" we set winheight to be huge before winminheight, the winminheight set will fail.
set winheight=5
set winminheight=5
set winheight=999
" Jumping between windows
map <C-H> <C-W><C-H>
map <C-L> <C-W><C-L>
map <C-J> <C-W><C-J>
map <C-K> <C-W><C-K>
" Move blocks in visual mode
vnoremap J :m '>+1<CR>gv=gv
vnoremap K :m '<-2<CR>gv=gv
" Go next in bufferlist
map <leader>d :cn<cr>
" Vertical split right and split below
set splitright
set splitbelow
" Commentary
map <leader>c :Commentary<cr>
" Setup snipmate parser
let g:snipMate = { 'snippet_version' : 1 }
" ctags tags file generation for the current directory
map <F8> :!ctags -R .<CR>
function ToggleBackground ()
if &background == 'light'
colorscheme lucius
set background=dark
else
colorscheme lucius
set background=light
endif
endfunction
map <leader>z :call ToggleBackground()<cr>
" Copy the current line into the clipboard
" Normal mode: <leader>t
map <C-C> "+yy
" Copy the current selection into the clipboard
" Visual mode: v
vmap <C-C> "+y
" Paste from the clipboard (normal and visual)
map <leader>v "+p
vmap <leader>v "+p
" Change Rubys :symbol => 'aaaa' to symbol: 'aaaa'
map <leader>s xea:<esc>ldf>
"""""""""""""""""""""
" TODOS
"""""""""""""""""""""
map <Leader>T :call ToDoSwitch()<CR>
map <LocalLeader>t :call ToDoSwitch()<CR>
function! ToDoSwitch()
let in_todo_file = match(expand("%"), 'todo.txt') != -1
:w
if in_todo_file
:normal ,,
else
:e todo.txt
endif
endfunction
"""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Trailblazer related
"""""""""""""""""""""""""""""""""""""""""""""""""""""""
map <Leader>tc :call ToggleCellAndView()<CR>
" Toggle between cell and view
function! ToggleCellAndView()
let in_cell = match(expand("%"), '/cell/') != -1
if in_cell
let file_destination = substitute(expand('%'), 'cell', 'view', '')
let file_destination = substitute(file_destination, '.rb', '.erb', '')
else
let file_destination = substitute(expand('%'), 'view', 'cell', '')
let file_destination = substitute(file_destination, '.erb', '.rb', '')
endif
:execute 'edit' file_destination
endfunction
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" RUNNING TESTS
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
map <Leader>rr :call RunCurrentSpecFile()<CR>
map <Leader>rR :call RunNearestSpec()<CR>
map <Leader>rl :call RunLastSpec()<CR>
map <Leader>ra :call RunAllSpecs()<CR>
map <Leader>rf :Dispatch script/test --only-failures %<CR>
map <Leader>rF :Dispatch script/test --only-failures spec<CR>
map <Leader>rn :Dispatch script/test --next-failure %<CR>
map <Leader>rN :Dispatch script/test --next-failure spec<CR>
" Include user's local vim config
if filereadable(expand("~/.vimrc.local"))
source ~/.vimrc.local
endif