-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.vimrc
390 lines (348 loc) · 15.7 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
set nocompatible
filetype off
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Bundle 'VundleVim/Vundle.vim'
Bundle 'altercation/vim-colors-solarized.git'
Bundle 'romainl/apprentice'
Bundle 'tpope/vim-surround'
Bundle 'tpope/vim-fugitive'
Bundle 'tpope/vim-unimpaired'
Bundle 'ctrlpvim/ctrlp.vim'
Bundle 'elixir-lang/vim-elixir'
Bundle 'danielfoxp2/vim-multipurposetabkey'
Bundle 'danielfoxp2/vim-automakedir'
Bundle 'danielfoxp2/vim-renamecurrentfile'
Bundle 'danielfoxp2/vim-runtestsindockercontainer'
call vundle#end()
set runtimepath^=~/.vim/bundle/ctrlp.vim
set t_Co=256
set t_ut=
let g:solarized_termcolors=256
syntax enable
set background=dark
"colorscheme solarized
color xoria256
"color iceberg
"colorscheme apprentice
" Vim5 and later versions support syntax highlighting. Uncommenting the next
" line enables syntax highlighting by default.
if has("syntax")
syntax on
endif
" Uncomment the following to have Vim jump to the last position when
" reopening a file
if has("autocmd")
au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
endif
" Uncomment the following to have Vim load indentation rules and plugins
" according to the detected filetype.
"if has("autocmd")
" filetype plugin indent on
"endif
" The following are commented out as they cause vim to behave a lot
" differently from regular Vi. They are highly recommended though.
set encoding=utf-8
set showcmd " Show (partial) command in status line.
set showmatch " Show matching brackets.
set ignorecase " Do case insensitive matching
set smartcase " Do smart case matching
set incsearch " Incremental search
set hidden " Hide buffers when they are abandoned
set number " Show line numbers
set relativenumber " Show relative line numbers where cursor is
set history=10000
set expandtab
set tabstop=4
set shiftwidth=4
set autoindent
set laststatus=2
set hlsearch
set ignorecase
set smartcase
set cursorline
set cmdheight:1
set switchbuf=useopen
set showtabline=2
set winwidth=79
set shell=bash
"set t_ti= t_te=
set scrolloff=3 "Seems to be the way to show lines above/below the cursor
set nobackup
set autoread "Reload a file without asking when it is changed outside vim.
set nowritebackup
set backupdir=~/.vim-tmp,~/.tmp,~/tmp,/var/tmp,/tmp
set directory=~/.vim-tmp,~/.tmp,~/tmp,/var/tmp,/tmp
set backspace=indent,eol,start
filetype plugin indent on
set wildmode=longest,list
"set wildmenu
set timeout timeoutlen=1000 ttimeoutlen=100
"au FocusLost * :wa "Save automatically when focus is lost
let g:airline_powerline_fonts = 1
let g:airline#extensions#tabline#enabled = 1
let g:airline#extensions#tabline#fnamemod=':t'
let g:bufferline_echo=0
"""""""""""""""Status Line """"""""""""""""""""""""""""""""""""""""""""""""""""""
" File name with path from current dir till file
" Buffer number
" Git branch - thanks Fugitive
" File git status**
" If file was modified and not saved yet
" Separation between left and right
" Line and Column number - And the virtual column number
" Number of lines
" **Don't fully works, but it is a step forward (see the comments on g:gitstatus declaration)...
set statusline=%<%f[%n]%{fugitive#statusline()}[%{g:gitstatus}]%(%m%)%=%-19(%3l,%02c%03V%)[%L]
" Mapping jj to ESC to go back to normal mode
inoremap jj <Esc>
"nnoremap <tab> % map tab to match S-%
"vnoremap <tab> %
let mapleader=","
nnoremap <up> <nop>
nnoremap <down> <nop>
nnoremap <left> <nop>
nnoremap <right> <nop>
inoremap <up> <nop>
inoremap <left> <ESC>
inoremap <down> <nop>
inoremap <right> <nop>
nnoremap ; :
nnoremap <leader>ev <C-w><C-v><C-w><C-w><cr>
"Change caps to UPPERCASE in NORMAL and INSERT mode
nnoremap <C-u> gUiw
inoremap <C-u> <esc>gUiwea
"Change caps to lowercase in NORMAL and INSERT mode
nnoremap <C-l> guiw
inoremap <C-l> <esc>guiwea
"When search and move around results, show them in the center of window
nnoremap n nzzzv
nnoremap N Nzzzv
"To take off the highlited results of search
nnoremap <BS> :nohlsearch<cr>
"To fast switch between previous and current file
nnoremap <leader><leader> <c-^>
" Remap F5 to change fast between listed buffers
nnoremap <F5> :buffers<CR>:buffer<space>
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Set .feature files as cucumber filetype then set standard
" indentation for cucumber filetype
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
autocmd BufnewFile,BufReadPost *.feature set filetype=cucumber
autocmd FileType cucumber set ai sw=2 sts=2 et
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Everytime vim is entered the vundle plugins are installed
autocmd VimEnter * call InstallVundlePlugins()
function! InstallVundlePlugins()
:PluginInstall
:q
endfunction
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" AUTO CREATION OF NON-EXISTENT DIRECTORIES
" Found at http://www.ibm.com/developerworks/library/l-vim-script-5/
" Everytime that a file is edited, if its path contains directories
" inexistent, vim will create those dirs, avoinding the horrible
" E212 - Can't open file for writing.
" If the directory does not exist it will ask if you want to create it
" Very nice...
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"augroup AutoMkdir
" autocmd!
" autocmd BufNewFile * :call EnsureDirExists()
"augroup END
"function! EnsureDirExists()
" let required_dir = expand("%:h")
" if !isdirectory(required_dir)
" call AskQuit("Directory '" . required_dir . "' doesn't exist.", "&Create it?")
" try
" call mkdir(required_dir, 'p')
" catch
" call AskQuit("Can't create '" . required_dir . "'", "&Continue anyway?")
" endtry
" endif
"endfunction
"function! AskQuit(msg, proposed_action)
" if confirm(a:msg, "&Quit?\n" . a:proposed_action) == 1
" exit
" endif
"endfunction
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" MULTIPURPOSE TAB KEY
" Indent if we are in the begining of a line. Else, do completion.
" I've changed the name of the function which was InsertTabWrapper()
" Stoled from THE GREAT Gary Bernhardt.
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"function! MultiPurposeTab()
" let col = col('.') - 1
" if !col || getline('.')[col -1] !~ '\k'
" return "\<tab>"
" else
" return "\<c-p>"
" endif
"endfunction
"inoremap <tab> <c-r>=MultiPurposeTab()<cr>
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" RENAME CURRENT FILE
" Enables even change file directory while renaming
" Changes vim buffer too
" Stoled from THE GREAT Gary Bernhardt.
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"function! RenameFile()
" let old_name = expand('%')
" let new_dir = expand('%:h')
" let new_name = input('New file name: ', expand('%'))
" if new_name != '' && new_name != old_name
" exec ':saveas ' . new_name
" exec ':silent !rm ' . old_name
" redraw!
" endif
"endfunction
"map <leader>n :call RenameFile()<cr>
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" SWITCH BETWEEN TEST AND PRODUCTION CODE FOR ELIXIR
" Variation of a function from THE GREAT Gary Bernhardt.
" Need improvement yet. Because I don't know how to work with phoenix
" so the in_app logic is not correct
"
" need to make it handle with alternate between acceptance too
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"function! OpenTestAlternate()
" let new_file = AlternateForCurrentFile()
" exec ':e ' . new_file
"endfunction
"function! AlternateForCurrentFile()
" let current_file = expand("%")
" let going_to_acceptance = match(current_file, '\(.feature\|_context.exs\)$') != -1
" if going_to_acceptance
" let new_file = BuildAcceptancePath()
" else
" let new_file = BuildUnitsPath()
" endif
" return new_file
"endfunction
"nnoremap <leader>. :call OpenTestAlternate()<cr>
"function! BuildAcceptancePath()
" let current_file = expand("%")
" let new_file = current_file
" let in_feature = match(current_file, '.feature$') != -1
" if in_feature
" let new_file = substitute(new_file, '\.feature$', '_context.exs', '')
" let new_file = substitute(new_file, 'features/', 'features/contexts/', '')
" else
" let new_file = substitute(new_file, '_context\.exs$', '.feature', '')
" let new_file = substitute(new_file, 'features/contexts/', 'features/', '')
" endif
" return new_file
"endfunction
"function! BuildUnitsPath()
" let current_file = expand("%")
" let new_file = current_file
" let in_spec = match(current_file, '_spec') != -1
" let going_to_spec = !in_spec
" let in_app = match(current_file, '\<controllers\>') != -1 || match(current_file, '\<models\>') != -1 || match(current_file, '\<views\>') != -1
" if going_to_spec
" if in_app
" let new_file = substitute(new_file, '^web/', '', '')
" endif
" let new_file = substitute(new_file, '\.ex$', '_spec.exs', '')
" let new_file = substitute(new_file, 'lib/', 'spec/', '')
" else
" let new_file = substitute(new_file, '_spec\.exs$', '.ex', '')
" let new_file = substitute(new_file, 'spec/', 'lib/', '')
" if in_app
" let new_file = 'web/' . new_file
" endif
" endif
" return new_file
"endfunction
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" RUNNING TESTS IN ANOTHER CONTAINER
" Variation of functions from THE GREAT Gary Bernhardt.
" Further improvements: Run tests for elixir and for Javascript too
" To do this, when call ENTER - for example - do a match to see if
" the called file is an elixir or js file. Then call the right function
" to either case
" Probably I will change the ENTER key to space. Way more confortable
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"function! MapCRtoRunTests()
" nnoremap <cr> :call RunTestFile()<cr>
"endfunction
"call MapCRtoRunTests()
"nnoremap <leader>a :call RunTests('')<cr>
"function! RunTestFile(...)
" if a:0
" let command_suffix = a:1
" else
" let command_suffix = ""
" endif
" call RunTestsForMarkedFile(command_suffix)
"endfunction
"function! RunTestsForMarkedFile(command_suffix)
" let in_test_file = match(expand("%"), '\(_context.exs\|.feature\|_test.exs\|_spec.exs\)$') != -1
" if in_test_file
" call MarkFileAsCurrentTest(a:command_suffix)
" elseif !exists("t:dm_test_file")
" return
" endif
" call RunTests(t:dm_test_file)
"endfunction
"function! MarkFileAsCurrentTest(command_suffix)
" let t:dm_test_file = expand("%:p") . a:command_suffix
"endfunction
"function! RunTests(filename)
" let g:docker_command = ':!docker exec -it elixir bash -c '
" "Save the file and run tests
" if expand("%") != ""
" :w
" endif
" if match(a:filename, '\(_context.exs\|.feature\)$') != -1
" "Como o white_bread tem bastante limitacao entao nao sera possivel
" "executar um unico arquivo feature como pode ser feito em outras
" "implementacoes do cucumber. Portanto, ao identificar os tipos de
" "arquivos acima, sera executada toda suite de features existentes
" let mixPathToRunTests = matchstr(expand("%:p"), '\(.*\)\/apps\/.\{-}\/')
" exec g:docker_command . "\"cd " . mixPathToRunTests . " && mix white_bread.run " . a:filename . "\""
" elseif match(a:filename, '_test.exs')
" let mixPathToRunTests = matchstr(expand("%:p"), '\(.*\)\/apps\/.\{-}\/')
" exec g:docker_command . "\"cd " . mixPathToRunTests . " && elixir " . a:filename . "\""
" else
" let mixPathToRunTests = matchstr(expand("%:p"), '\(.*\)\/work\/.\{-}\/')
" exec g:docker_command . "\"cd " . mixPathToRunTests . " && mix espec " . a:filename . "\""
" endif
"endfunction
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Returns [x] where x is the file status in git
" [?] to untracked
" [M] to modified
" [A] to staged
" It only works when open vim or switch between buffers
" When vim lost focus with Ctrl+z or you change to another tab in your
" terminal it does not work. So, read the status with a grain of salt
function CurrentGitStatus()
let gitoutput = split(system('git status --porcelain -b '.shellescape(expand('%')).' 2>/dev/null'),'\n')
if len(gitoutput) > 0
let stage_status = strpart(get(gitoutput, 1, ' '), 0, 1)
let unstage_status = strpart(get(gitoutput, 1, ' '), 1, 1)
if stage_status != ' '
let g:gitstatus = stage_status
else
let g:gitstatus = unstage_status
endif
else
let g:gitstatus = ''
endif
endfunction
autocmd BufEnter,BufWritePost,FocusGained * call CurrentGitStatus()
" Source a global configuration file if available
if filereadable("/etc/vim/vimrc.local")
source /etc/vim/vimrc.local
endif
"remove .netrwhist
"au VimLeave * if filereadable("[path here]/.netrwhist")|call
"delete("[path here]/.netrwhist")|endif