-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.vimrc-docker-ruby
More file actions
330 lines (291 loc) · 10.8 KB
/
.vimrc-docker-ruby
File metadata and controls
330 lines (291 loc) · 10.8 KB
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
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 'ctrlpvim/ctrlp.vim'
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=2
set shiftwidth=2
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
" 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
nnoremap <C-u> gUiw
inoremap <C-u> <esc>gUiwea
"Change caps to lowercase
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
" Source a global configuration file if available
if filereadable("/etc/vim/vimrc.local")
source /etc/vim/vimrc.local
endif
"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
" """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 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\|_steps.rb\)$') != -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$', '_steps.rb', '')
let new_file = substitute(new_file, 'features/', 'features/step_definitions/', '')
else
let new_file = substitute(new_file, '_steps\.rb$', '.feature', '')
let new_file = substitute(new_file, 'features/step_definitions/', '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, '^app/', '', '')
endif
let new_file = substitute(new_file, '\.e\?rb$', '_spec.rb', '')
let new_file = substitute(new_file, 'lib/', 'spec/', '')
else
let new_file = substitute(new_file, '_spec\.rb$', '.rb', '')
let new_file = substitute(new_file, 'spec/', 'lib/', '')
if in_app
let new_file = substitute(new_file, 'lib/', '', '')
let new_file = 'app/' . 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("%"), '\(feature\|_spec.rb\)$') != -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 password-container bash -c '
let g:rootPathToRunTests = matchstr(expand("%:p"), '\(.*\)\/work\/.\{-}\/')
"Save the file and run tests
if expand("%") != ""
:w
endif
if match(a:filename, '\(feature\)$') != -1
exec g:docker_command . "\"cd " . g:rootPathToRunTests . " && cucumber --color " . a:filename . "\""
else
exec g:docker_command . "\"cd " . g:rootPathToRunTests . " && rspec --color " . a:filename . "\""
endif
endfunction
"remove .netrwhist
"au VimLeave * if filereadable("[path here]/.netrwhist")|call
"delete("[path here]/.netrwhist")|endif