-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvimrc.funcs
More file actions
171 lines (151 loc) · 3.71 KB
/
vimrc.funcs
File metadata and controls
171 lines (151 loc) · 3.71 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
function! Build()
" build has a funtion to map custom files to build
if (&ft=='go') " to build work correctly is necessary the plugin fatih/vim-go
if(match(expand('%:t'), '_test\.go') > 0)
:GoTestCompile <CR>
else
:GoBuild <CR>
endif
endif
endfunction
command! Build call Build()
map <Leader>B :call Build() <CR>
command! W w | Build " map W to save and build file
function! TabToSpace()
:s/\t/ /g
endfunction
command! TabToSpace call TabToSpace()
function! RangeTabToSpace() range
:'<,'>s/\t/ /g
endfunction
command! RangeTabToSpace call RangeTabToSpace()
function! Space4ToTab()
:s/ /\t/g
endfunction
command! Space4ToTab call Space4ToTab()
" run :GoBuild or :GoTestCompile based on the go file
function! s:build_go_files()
let l:file = expand('%')
if l:file =~# '^\f\+_test\.go$'
call go#cmd#Test(0, 1)
elseif l:file =~# '^\f\+\.go$'
call go#cmd#Build(0)
endif
endfunction
function! ToggleCursor()
let g:cursor_on = exists('g:cursor_on') ? !g:cursor_on : 1
if g:cursor_on
set cursorcolumn
set cursorline
else
set nocursorcolumn
set nocursorline
endif
endfunction
map <Leader>tc :call ToggleCursor() <CR>
function! ToggleErrors()
if empty(filter(tabpagebuflist(), 'getbufvar(v:val, "&buftype") is# "quickfix"'))
" No location/quickfix list shown, open syntastic error location panel
Errors
else
lclose
endif
endfunction
map <Leader>te :call ToggleErrors() <CR>
function! ToggleHidden()
set listchars=eol:↵,extends:>,precedes:<,nbsp:·,tab:»\ \,trail:~
"Toggle the flag (or set it if it doesn't yet exist)...
let g:list_on = exists('g:list_on') ? !g:list_on : 1
if g:list_on
set list
else
set nolist
endif
endfunction
map <Leader>th :call ToggleHidden() <CR>
function! FormatJSON()
%!python3 -m json.tool
endfunction
command! FormatJSON call FormatJSON()
function! FormatXML()
%!xmllint -encode utf8 -format -
endfunction
command! FormatXML call FormatXML()
function! FormatSH()
%!shfmt
endfunction
command! FormatSH call FormatSH()
function! URLDecode()
%!python3 -c "import sys, urllib as ul; print ul.unquote_plus(sys.stdin.read())"
endfunction
command! URLDecode call URLDecode()
function! URLEncode()
%!python3 -c "import sys, urllib as ul; print ul.quote_plus(sys.stdin.read())"
endfunction
command! URLEncode call URLEncode()
function! CloseHelpWindows()
:pclose
:cclose " close the quickfix window
:lclose
endfunction
map <F6> :call CloseHelpWindows()<CR>
function! TrimWhiteSpace()
":%s/\s\+$//e
%s/\s*$//
''
endfunction
command! TrimWhiteSpace call TrimWhiteSpace()
function! RunNode()
:%y"
call TempWindow("Node", 1, 's')
:put
execute 'silent %!node'
endfunction
function! Table(...)
let a:delimiter = get(a:, 1, 0)
if a:delimiter == "0"
let a:delimiter=','
endif
:%y"
call TempWindow("Table", 1, 's')
:put
execute 'silent %!column -t -s"' . a:delimiter . '"'
endfunction
command! Table call Table()
function! Execute(c)
:%y"
call TempWindow("Execute", 1, 'v')
:put
execute 'silent %!' . a:c
endfunction
command! Execute -nargs=1 Execute call Execute(<f-args>)
" Disposable temporary window
" TODO bug janela não atulizar se rodar mais de uma vez
function! TempWindow(name, clear, mode) abort
let name = substitute(a:name, "[^a-zA-Z0-9]", "_", "g")
let bn = bufnr(name)
if bn == -1
exe "new " . name
let bn = bufnr(name)
setlocal buftype=nofile
setlocal bufhidden=hide
setlocal noswapfile
setlocal buflisted
else
let wn = bufwinnr(bn)
if wn != -1
exe wn . "wincmd w"
else
exe "split +buffer" . bn
endif
endif
if a:clear
normal gg
normal dG
endif
if a:mode == 'v'
wincmd L
else
wincmd J
endif
endfunction