-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode_vimrc.vim
More file actions
180 lines (168 loc) · 6.91 KB
/
code_vimrc.vim
File metadata and controls
180 lines (168 loc) · 6.91 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
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Functions and Commands "
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" This is for automatically aligning tables using the tabular plugin
" Taken from a Tim Pope gist, see https://gist.github.com/tpope/287147
function! s:align()
let p = '^\s*|\s.*\s|\s*$'
if exists(':Tabularize') && getline('.') =~# '^\s*|' && (getline(line('.')-1) =~# p || getline(line('.')+1) =~# p)
let column = strlen(substitute(getline('.')[0:col('.')],'[^|]','','g'))
let position = strlen(matchstr(getline('.')[0:col('.')],'.*|\s*\zs.*'))
Tabularize/|/l1
normal! 0
call search(repeat('[^|]*|',column).'\s\{-\}'.repeat('.',position),'ce',line('.'))
endif
endfunction
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Convert a visually selected trace into a Sequence Diagram "
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
if has("win32")
function! s:call_trace_to_sequence_diagram(file_in_which_to_write_trace, diagram_output_file_name)
let s:path_to_sequence = 'C:/github/sequence/sequence.rb'
normal mz
let diagram_output_file_name = a:diagram_output_file_name
let diagram_input_file_name = a:file_in_which_to_write_trace
call s:write_visual_selection_to_file(diagram_input_file_name)
" write the trace to file
call system("ruby " . s:path_to_sequence . " -i ".diagram_input_file_name. " -o " .diagram_output_file_name )
" write the trace to the @t register
let @t = system("ruby ". s:path_to_sequence . " -i ".diagram_input_file_name )
" remove our input and output files
call delete(diagram_input_file_name)
call delete(diagram_output_file_name)
" put the @t register into our buffer at the bottom of the selection
normal `>
normal o
put! t
normal `z
" place the cursor at the first '?' so that we can start over-writing
" our '?' characters with numbers
call search( "?")
normal zt
return 0
endfunction
else
function! s:call_trace_to_sequence_diagram(file_in_which_to_write_trace, diagram_output_file_name)
normal mz
let diagram_output_file_name = a:diagram_output_file_name
let diagram_input_file_name = a:file_in_which_to_write_trace
call s:write_visual_selection_to_file(diagram_input_file_name)
" write the trace to file
call system("ruby ~/.vim/.ruby/sequence.rb -i ".diagram_input_file_name. " -o " .diagram_output_file_name )
" write the trace to the @t register
let @t = system("ruby ~/.vim/.ruby/sequence.rb -i ".diagram_input_file_name )
normal `>
normal o
put! t
normal `z
call search( "?")
normal zt
return 0
endfunction
endif
command! -range TraceToSequenceDiagram call s:call_trace_to_sequence_diagram("__trace.txt__","__sequence_diagram.txt__")
function! GetRefactorProgramPath()
let s:this_path = fnamemodify($MYVIMRC, ":h")
let s:script_path = s:this_path . "/bundle/recurse/refactor.rb"
return s:script_path
endfunction
function! GetYamlRefactorFileName()
let s:this_path = fnamemodify($MYVIMRC, ":h")
let s:script_path = s:this_path . "/bundle/recurse/refactor.rb"
let s:cmd = "ruby ". "'" . s:script_path . "'" . " -f"
let s:output = system( s:cmd )
return s:output
endfunction
function! YamlForRefactor()
"let s:this_path = fnamemodify($MYVIMRC, ":h")
let s:script_path = GetRefactorProgramPath()
let s:current_directory = expand("%:p:h")
let s:cmd = "ruby " . "'" . s:script_path . "'" . " -e " . "'" . s:current_directory . "'"
execute "!" . s:cmd
let s:yaml_file_name = GetYamlRefactorFileName()
let s:yaml_file_path = s:current_directory . "/" . s:yaml_file_name
execute "vsplit " . s:yaml_file_path
"let @a = s:cmd
endfunction
function! Refactor()
let s:script_path = GetRefactorProgramPath()
let s:yaml_file_name = GetYamlRefactorFileName()
let s:current_directory = expand("%:p:h")
let s:yaml_file_path = s:current_directory . "/" . s:yaml_file_name
let s:cmd = "ruby " . "'" . s:script_path . "'"
let s:cmd = s:cmd . " -d " . "'" . s:current_directory . "'"
let s:cmd = s:cmd . " -y " . "'" . s:yaml_file_path . "'"
let @a = s:cmd
execute "!" . s:cmd
endfunction
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Determine the comment token character "
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
function! s:GetToken()
let token = "#"
let file_name = expand("%:t:r")
let file_ext = expand("%:e")
if file_name ==? ".vimrc"
let token = "\""
elseif file_ext ==? "vim"
let token = "\""
endif
if file_ext ==? "c" || file_ext ==? "h"
let token = "*"
endif
return token
endfunction
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Center and Box Some Text In a file specific token "
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
function! s:BoxitFunction()
let token = s:GetToken()
" remove space before and after the words
execute "silent! normal 0,$"
execute "silent! normal 0d\/w"
center
" insert the top bar of tokens
execute "silent! normal! O\e80i".token
" add a bunch of spaces after your centered word
execute "silent! normal! jA \e40i "
" inset the bottom bar of tokens
execute "silent! normal! o\e81i".token
" place the first and the last token at 0 and the 80th column of the same
" row as the centered word(s)
execute "silent! normal! 0dt".token
execute "silent! normal! k0i".token."\el\ex"
execute "silent! normal! 80|lD"
execute "silent! normal! r".token
execute "silent! normal! k0"
" for the * token, add some additional decoration
" and for any token ensure we try to move to the line below the boxed
" content
if token == "*"
silent! normal r/
silent! normal jj$r/
silent! normal j
else
silent! normal 3j
endif
endfunction
command! Boxit call s:BoxitFunction()
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Lifted from Tim Pope "
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
function! OpenURL(url)
if has("win32")
exe "!start cmd /cstart /b ".a:url.""
elseif $DISPLAY !~ '^\w'
exe "silent !tpope open \"".a:url."\""
elseif exists(':Start')
exe "Start tpope open -T \"".a:url."\""
else
endif
redraw!
endfunction
command! -nargs=1 OpenURL :call OpenURL(<q-args>)
" open URL under cursor in browser
nnoremap gb :OpenURL <cfile><CR>
nnoremap gA :OpenURL http://www.answers.com/<cword><CR>
nnoremap gG :OpenURL http://www.google.com/search?q=<cword><CR>
nnoremap gW :OpenURL http://en.wikipedia.org/wiki/Special:Search?search=<cword><CR>