/
vimrc.symlink
303 lines (241 loc) · 7.55 KB
/
vimrc.symlink
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
set nocompatible
call pathogen#infect()
call pathogen#helptags()
filetype plugin indent on
syntax on
" Current line highlight
set cursorline
set colorcolumn=81
" Enabling mouse
set mouse=a
" Enabling clipboard
set clipboard=unnamed
" Set encoding
set encoding=utf-8
set statusline=%<%f\ %h%m%r%=%-20.(line=%l,col=%c%V,totlin=%L%)\%h%m%r%=%-40(,%n%Y%)\%P%*
set laststatus=2 " Always show status line.
" Line numbers
set number
set background=light
color spike
color solarized
" Search settings
set hlsearch
set incsearch
set ignorecase
set smartcase
set visualbell
set mousehide
set cf " Enable error files & error jumping.
set autowrite " Writes on make/shell commands
set ruler
set nowrap
set timeoutlen=500
set history=50
" Tab completion
set wildmode=list:longest,list:full
set wildignore+=*.o,*.obj,.git,*.rbc,*.class,.svn
let mapleader = ","
set tabstop=2
set smarttab
set shiftwidth=2
set autoindent
set expandtab
set list listchars=tab:\ \ ,trail:·
set backspace=start,indent,eol
autocmd FileType make set noexpandtab
" Thorfile, Rakefile, Vagrantfile and Gemfile are Ruby
au BufRead,BufNewFile {Gemfile,Rakefile,Vagrantfile,Thorfile,config.ru} set ft=ruby
" add json syntax highlighting
au BufNewFile,BufRead *.json set ft=javascript
" javaScript autocomplition
autocmd FileType javascript set omnifunc=javascriptcomplete#CompleteJS
" ruby autocompletion
autocmd FileType ruby,eruby set omnifunc=rubycomplete#Complete
autocmd FileType ruby,eruby let g:rubycomplete_buffer_loading = 1
autocmd FileType ruby,eruby let g:rubycomplete_rails = 1
autocmd FileType ruby,eruby let g:rubycomplete_classes_in_global = 1
" No bloody backups anymore!
set nobackup
set nowritebackup
set noswapfile
" NERDTree hidden files filter
let NERDTreeIgnore=['\.pyc$', '\.rbc$', '\~$', '\.DS_Store', '\.sass-cache', '\.svn', '\.idea', '\.gitkeep']
let NERDTreeShowHidden = 1
" Highlight trailing whitespace
highlight RedundantSpaces term=standout ctermbg=red guibg=red
match RedundantSpaces /\s\+$\| \+\ze\t/ "\ze sets end of match so only spaces highlighted
" ,h to toggle search result highlighting
map <silent> <leader>h :set hls!<CR>
" BufExplorer
map <silent> <unique> <Leader>. :BufExplorerHorizontalSplit<CR>
" delete buffer :bd
map <Leader>w :bd<CR>
" next buffer
map <Leader>n :bn<CR>
" prev buffer
map <Leader>m :bp<CR>
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" A whole bunch of NERDTree configuration stolen from carlhuda's janus
autocmd VimEnter * call s:NERDTreeIfDirectory(expand("<amatch>"))
autocmd VimEnter * wincmd p
autocmd VimEnter * call s:CdIfDirectory(expand("<amatch>"))
autocmd WinEnter * call s:CloseIfOnlyNerdTreeLeft()
"Disable netrw's autocmd, since we're ALWAYS using NERDTree
runtime plugin/netRwPlugin.vim
augroup FileExplorer
au!
augroup END
let g:NERDTreeHijackNetrw = 0
" Close all open buffers on entering a window if the only
" buffer that's left is the NERDTree buffer
function s:CloseIfOnlyNerdTreeLeft()
if exists("t:NERDTreeBufName")
if bufwinnr(t:NERDTreeBufName) != -1
if winnr("$") == 1
q
endif
endif
endif
endfunction
" If the parameter is a directory (including implicit '.'), open NERDTree
function s:NERDTreeIfDirectory(directory)
if isdirectory(a:directory) || a:directory == ""
NERDTree
endif
endfunction
" If the parameter is a directory, cd into it
function s:CdIfDirectory(directory)
if isdirectory(a:directory)
call ChangeDirectory(a:directory)
endif
endfunction
" NERDTree utility function
function s:UpdateNERDTree(stay)
if exists("t:NERDTreeBufName")
if bufwinnr(t:NERDTreeBufName) != -1
NERDTree
if !a:stay
wincmd p
end
endif
endif
endfunction
" Utility functions to create file commands
function s:CommandCabbr(abbreviation, expansion)
execute 'cabbrev ' . a:abbreviation . ' <c-r>=getcmdpos() == 1 && getcmdtype() == ":" ? "' . a:expansion . '" : "' . a:abbreviation . '"<CR>'
endfunction
function s:FileCommand(name, ...)
if exists("a:1")
let funcname = a:1
else
let funcname = a:name
endif
execute 'command -nargs=1 -complete=file ' . a:name . ' :call ' . funcname . '(<f-args>)'
endfunction
function s:DefineCommand(name, destination)
call s:FileCommand(a:destination)
call s:CommandCabbr(a:name, a:destination)
endfunction
" Public NERDTree-aware versions of builtin functions
function ChangeDirectory(dir, ...)
execute "cd " . a:dir
let stay = exists("a:1") ? a:1 : 1
call s:UpdateNERDTree(stay)
endfunction
function Touch(file)
execute "!touch " . a:file
call s:UpdateNERDTree(1)
endfunction
function Remove(file)
let current_path = expand("%")
let removed_path = fnamemodify(a:file, ":p")
if (current_path == removed_path) && (getbufvar("%", "&modified"))
echo "You are trying to remove the file you are editing. Please close the buffer first."
else
execute "!rm " . a:file
endif
endfunction
function Edit(file)
if exists("b:NERDTreeRoot")
wincmd p
endif
execute "e " . a:file
ruby << RUBY
destination = File.expand_path(VIM.evaluate(%{system("dirname " . a:file)}))
pwd = File.expand_path(Dir.pwd)
home = pwd == File.expand_path("~")
if home || Regexp.new("^" + Regexp.escape(pwd)) !~ destination
VIM.command(%{call ChangeDirectory(system("dirname " . a:file), 0)})
end
RUBY
endfunction
" Define the NERDTree-aware aliases
call s:DefineCommand("cd", "ChangeDirectory")
call s:DefineCommand("touch", "Touch")
call s:DefineCommand("rm", "Remove")
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" end of the NERDTree configuration
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Folding settings
set foldmethod=indent "fold based on indent
set foldnestmax=3 "deepest fold is 3 levels
set nofoldenable
" Jump to last cursor position when opening a file
" Don't do it when writing a commit log entry
autocmd BufReadPost * call SetCursorPosition()
function! SetCursorPosition()
if &filetype !~ 'commit\c'
if line("'\"") > 0 && line("'\"") <= line("$")
exe "normal g`\""
endif
end
endfunction
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" RSpec running functions
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Execute open rspec buffer
" Thanks to Ian Smith-Heisters
function! RunSpec(args)
if exists("b:rails_root") && filereadable(b:rails_root . "/script/spec")
let spec = b:rails_root . "/script/spec"
else
let spec = "rspec"
end
let cmd = ":! bundle exec " . spec . " % -cfn " . a:args
execute cmd
endfunction
" Mappings
" run one rspec example or describe block based on cursor position
map !s :call RunSpec("-l " . <C-r>=line('.')<CR>)
" run full rspec file
map !S :call RunSpec("")
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" end of the spec running config
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" fugutive status
map <Leader>fs :Gstatus<CR>
" fugititve commit
map <Leader>fc :Gcommit<CR>
" Switch on/off automatic code alignin on paste
set pastetoggle=<F2>
" strip trailing whitespace<foo&bar>
function! StripTrailingWhitespace()
normal mz
normal Hmy
exec '%s/\s*$//g'
normal 'yz<cr>
normal `z
endfunction
nmap <silent> <Leader>sw :call StripTrailingWhitespace()<CR>
" use ,F to jump to tag in a horizontal split
nnoremap <silent> ,F :let word=expand("<cword>")<CR>:sp<CR>:wincmd w<cr>:exec("tag ". word)<cr>
" It's not like :W is bound to anything anyway.
command! W :w
command! Q :q
inoremap <Tab> <C-X><C-n>
inoremap <leader><Tab> <C-X><C-]>
" Source a local configuration file if available.
if filereadable(expand("~/.vimrc.local"))
source ~/.vimrc.local
endif