-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.vimrc
229 lines (172 loc) · 6.42 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
" set tabstops/shift widths
se ts=4
se sw=4
syntax on
" dont indent code on paste
se paste
" not case sensitive in searches
se ignorecase
" When editing a file, always jump to the last known cursor position.
" Don't do it when the position is invalid or when inside an event handler
" (happens when dropping a file on gvim).
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal g`\"" |
\ endif
"folding settings: za=fold, zM=fold all, zR=unfold all
"set foldmethod=indent "fold based on indent
"set foldnestmax=10 "deepest fold is 10 levels
"set nofoldenable "dont fold by default
"set foldlevel=1 "this is just what i use
map ,v :sp ~/.vimrc<CR><C-W>_
map <silent> ,V :source $VIMRC<CR>:filetype detect<CR>:exe ":echo 'vimrc reloaded'"<CR>
" set the status line to look like 'ruler', plus buffer number at the end
set statusline=%<%f%h%m%r%w%y%=%l/%L,%c\ %P\ \|\ %n
" show matching parens
set showmatch
" MACROS {{{
" c - javadoc style comment
" cc- large comment section header
" bc- bash comment 1 line
" v - immediately after c, tab the block out one time
" e - error_log
" r - errorlog with print_r, for variable mapping
" tr - add a try() catch
" .r' - replace quoted $var as ?
" .ri - replace quoted int $var
" .re - replace quoted int $var at end of line
map .q' f$<LEFT>_W<LEFT>vF$di?<ESC><RIGHT>
map .qr f$i?<ESC><RIGHT>vf <LEFT>d
map .ql f$i?<ESC><RIGHT>vf;<LEFT><LEFT>d
" '$asdf' , '$asdf', '$asdf'
"Comment out a line
map .c I/*<ESC>A*/<ESC>
"Uncomment a line
map .u 0f/<DEL><DEL><ESC>A<BACKSPACE><BACKSPACE><ESC>
"HTML comment out a line
map .hc I<!--<ESC>A--><ESC>
"HTML uncommenout out a line
map .hu 0f!<LEFT><DEL><DEL><DEL><DEL><ESC>A<BACKSPACE><BACKSPACE><BACKSPACE><ESC>
map _c o/**<CR> * <CR> * <CR> * @param <CR> * @param <CR> * @return <CR> */<UP><UP><UP><UP><UP>
map _bc 0i#<DOWN><ESC>
map _cc o/**<CR> * -------------------------------------------------------------------------<CR> * <CR> * -------------------------------------------------------------------------<CR> */<UP><UP><RIGHT><RIGHT>
map _f o<CR>/**<CR> * <CR> * <CR> * @param <CR> * @param <CR> * @return <CR> */<CR>function ()<CR>{<CR><CR>}<CR><UP><UP><UP><UP><UP><UP><UP><UP><UP><UP><RIGHT><RIGHT><RIGHT>
map _v <ESC><UP>v<DOWN><DOWN><DOWN><DOWN><DOWN><DOWN><S->><DOWN><RIGHT>
map _e oerror_log(" ");<LEFT><LEFT><LEFT><LEFT>
map _r oerror_log(print_r( ,true));<LEFT><LEFT><LEFT><LEFT><LEFT><LEFT><LEFT><LEFT><LEFT><LEFT>
map _d odbg(" ");<LEFT><LEFT><LEFT><LEFT>
map _dd odbd( );<LEFT><LEFT><LEFT><LEFT>
map _tr <UP>A<CR>try{<ESC><DOWN>A<CR>}catch(Exception $e){error_log($e->getMessage();}
let mapleader='_'
" This allows me to quickly wrap any selection with some usual characters
" (quotes, angle quotes, parentheses, etc)
vnoremap <silent> <Leader>" :<C-u>call <SID>RD_wrapper('"')<CR>
vnoremap <silent> <Leader>' :<C-u>call <SID>RD_wrapper("'")<CR>
vnoremap <silent> <Leader>` :<C-u>call <SID>RD_wrapper('`')<CR>
vnoremap <silent> <Leader>{ :<C-u>call <SID>RD_wrapper('{')<CR>
vnoremap <silent> <Leader>( :<C-u>call <SID>RD_wrapper('(')<CR>
vnoremap <silent> <Leader>[ :<C-u>call <SID>RD_wrapper('[')<CR>
vnoremap <silent> <Leader>< :<C-u>call <SID>RD_wrapper('<')<CR>
vnoremap <silent> <Leader>t :<C-u>call <SID>RD_wrapper('t')<CR>
vnoremap <silent> <Leader>c :<C-u>call <SID>RD_wrapper('c')<CR>
nnoremap <silent> <Leader>W :call <SID>RD_unwrapper()<CR>
nnoremap <silent> <Leader>T :call <SID>RD_unwrap_tag()<CR>
" FUNCTIONS ------------------------------------------------------
" This function nicely wraps a selection within quotes, curly braces, square
" brackets, angle brackets, tags and more.
function s:RD_wrapper (str) range
let l:allowed_strs = {
\ '"' : ['"', '"'],
\ "'" : ["'", "'"],
\ '{' : ['{', '}'],
\ '(' : ['(', ')'],
\ '[' : ['[', ']'],
\ '`' : ['`', '`'],
\ '<' : ['<', '>'],
\ 't' : ['', ''],
\ 'c' : ['/*', '*/']
\ }
if has_key(l:allowed_strs, a:str) != 1
echohl ErrorMsg
echo 'Unknown wrapper: "' . a:str . '".'
echohl None
return 0
endif
" Wrap the selection with a tag.
if a:str == 't'
let l:tname = inputdialog('Tag name: ')
if strlen(l:tname) < 1
return 0
endif
let l:allowed_strs[a:str][0] = '<' . l:tname . '>'
let l:allowed_strs[a:str][1] = '</' . l:tname . '>'
endif
let l:prefix = l:allowed_strs[a:str][0]
let l:suffix = l:allowed_strs[a:str][1]
let l:lenp = strlen(l:prefix)
let l:old_x = @x
let l:old_reg = @"
let @x = l:prefix
normal `<"xP
let l:line1 = line('.')
normal `>
let l:line2 = line('.')
if l:line1 == l:line2
exe 'normal ' . lenp . 'l'
endif
let @x = l:suffix
normal "xp
" If we are wrapping the selection with a tag, lets put the cursor exactly
" where the user can just press 'i' to start writing the attributes.
if a:str == 't'
normal h%h%
endif
let @x = l:old_x
let @" = l:old_reg
return 1
endfunction
" Similar to the RD_wrapper function, this one removes the quotes, curly
" braces, etc.
function s:RD_unwrapper () range
let l:allowed_strs = ['"', "'", '{', '}', '(', ')', '[', ']', '`', '<', '>']
let l:xml_types = ['xhtml', 'html', 'xml']
let l:str = strpart(getline('.'), col('.') - 1, 1)
if index(l:allowed_strs, l:str) == -1
" If this is a known XML/SGML file type, then try to strip the current
" tag
if index(l:xml_types, &filetype) != -1
return <SID>RD_unwrap_tag()
endif
echohl ErrorMsg
echo 'The character under the cursor was not recognized: "' . l:str . '"'
echohl None
return 0
endif
let l:old_x = @x
let l:old_reg = @"
exe 'normal vi' . l:str . 'v'
normal `<X
let l:line1 = line('.')
normal `>
let l:line2 = line('.')
if(l:line1 != l:line2)
normal l
endif
normal x
let @x = l:old_x
let @" = l:old_reg
return 1
endfunction
set diffexpr=MyDiff()
function MyDiff()
let opt = ""
if &diffopt =~ "icase"
let opt = opt . "-i "
endif
if &diffopt =~ "iwhite"
let opt = opt . "-w "
endif
silent execute "!diff -a --binary -w " . opt . v:fname_in . " " . v:fname_new .
\ " > " . v:fname_out
endfunction
se so=6