comparison .chezmoitemplates/config.vim @ 574:8b04d5ffd210

Clean up unused functions and mappings
author zegervdv <zegervdv@me.com>
date Fri, 04 Mar 2022 10:35:44 +0100
parents 21745760a5dc
children 23426c0f0e58
comparison
equal deleted inserted replaced
573:eb6ebdacf201 574:8b04d5ffd210
40 " Mappings 40 " Mappings
41 41
42 " Highlight VCS conflict markers 42 " Highlight VCS conflict markers
43 match ErrorMsg '^\(<\|=\|>\)\{7\}\([^=].\+\)\?$' 43 match ErrorMsg '^\(<\|=\|>\)\{7\}\([^=].\+\)\?$'
44 44
45 " Do not move on *
46 nnoremap <silent> * :let stay_star_view = winsaveview()<cr>*:call winrestview(stay_star_view)<cr>
47 45
48 " Search for selected text, forwards or backwards. 46 " Search for selected text, forwards or backwards.
49 vnoremap <silent> * :<C-U> 47 vnoremap <silent> * :<C-U>
50 \let old_reg=getreg('"')<Bar>let old_regtype=getregtype('"')<CR> 48 \let old_reg=getreg('"')<Bar>let old_regtype=getregtype('"')<CR>
51 \gvy/<C-R><C-R>=substitute( 49 \gvy/<C-R><C-R>=substitute(
57 \escape(@", '?\.*$^~['), '\_s\+', '\\_s\\+', 'g')<CR><CR> 55 \escape(@", '?\.*$^~['), '\_s\+', '\\_s\\+', 'g')<CR><CR>
58 \gV:call setreg('"', old_reg, old_regtype)<CR> 56 \gV:call setreg('"', old_reg, old_regtype)<CR>
59 57
60 xnoremap <silent> p p:if v:register == '"'<Bar>let @@=@0<Bar>endif<CR> 58 xnoremap <silent> p p:if v:register == '"'<Bar>let @@=@0<Bar>endif<CR>
61 59
62 " Error navigation
63 nnoremap <UP> :cprev<CR>
64 nnoremap <DOWN> :cnext<CR>
65 nnoremap <RIGHT> :cnf<CR>
66 nnoremap <LEFT> :cpf<CR>
67
68 nnoremap <leader>y :ptjump <c-r><c-w><CR>
69 60
70 if has('nvim') 61 if has('nvim')
71 tnoremap <C-h> <C-\><C-n><C-w>h 62 tnoremap <C-h> <C-\><C-n><C-w>h
72 tnoremap <C-j> <C-\><C-n><C-w>j 63 tnoremap <C-j> <C-\><C-n><C-w>j
73 tnoremap <C-k> <C-\><C-n><C-w>k 64 tnoremap <C-k> <C-\><C-n><C-w>k
111 elseif b:countCheck >= 200 || &filetype != "" 102 elseif b:countCheck >= 200 || &filetype != ""
112 autocmd! newFileDetection 103 autocmd! newFileDetection
113 endif 104 endif
114 endfunction 105 endfunction
115 " 106 "
116
117 " Convert hex <-> decimal
118 command! -nargs=? -range Dec2hex call s:Dec2hex(<line1>, <line2>, '<args>')
119 function! s:Dec2hex(line1, line2, arg) range
120 if empty(a:arg)
121 if histget(':', -1) =~# "^'<,'>" && visualmode() !=# 'V'
122 let cmd = 's/\%V\<\d\+\>/\=printf("0x%x",submatch(0)+0)/g'
123 else
124 let cmd = 's/\<\d\+\>/\=printf("0x%x",submatch(0)+0)/g'
125 endif
126 try
127 execute a:line1 . ',' . a:line2 . cmd
128 catch
129 echo 'Error: No decimal number found'
130 endtry
131 else
132 echo printf('%x', a:arg + 0)
133 endif
134 endfunction
135
136 command! -nargs=? -range Hex2dec call s:Hex2dec(<line1>, <line2>, '<args>')
137 function! s:Hex2dec(line1, line2, arg) range
138 if empty(a:arg)
139 if histget(':', -1) =~# "^'<,'>" && visualmode() !=# 'V'
140 let cmd = 's/\%V0x\x\+/\=submatch(0)+0/g'
141 else
142 let cmd = 's/0x\x\+/\=submatch(0)+0/g'
143 endif
144 try
145 execute a:line1 . ',' . a:line2 . cmd
146 catch
147 echo 'Error: No hex number starting "0x" found'
148 endtry
149 else
150 echo (a:arg =~? '^0x') ? a:arg + 0 : ('0x'.a:arg) + 0
151 endif
152 endfunction
153 "
154
155 " Recognize filetype for dup files
156 autocmd! BufRead *.dup call DupSetSyntax(@%)
157
158 function! DupSetSyntax(name)
159 let extension = matchlist(a:name, '\v.+.\.([^\.]+).dup')[1]
160 if extension == "vhd"
161 setlocal filetype=vhdl
162 elseif extension == "v"
163 setlocal filetype=verilog
164 elseif extension == "sv"
165 setlocal filetype=verilog
166 else
167 echo "Unknown filetype"
168 endif
169 endfunction
170 "
171
172 " Create arguments list from files in quickfix list
173 " Allows to Grep for a pattern and apply an argdo command on each of the
174 " matching files
175 command! -nargs=0 -bar Qargs execute 'args' QuickfixFilenames()
176 function! QuickfixFilenames()
177 " Building a hash ensures we get each buffer only once
178 let buffer_numbers = {}
179 for quickfix_item in getqflist()
180 let buffer_numbers[quickfix_item['bufnr']] = bufname(quickfix_item['bufnr'])
181 endfor
182 return join(map(values(buffer_numbers), 'fnameescape(v:val)'))
183 endfunction
184 "
185
186 augroup mark_files
187 au!
188 au BufLeave test.tcl mark T
189 au BufLeave case.do mark C
190 au BufLeave drv_*.tcl mark D
191 au BufLeave *.rtl.vhd mark R
192 augroup END
193
194
195 " Toggle between opening/closing the quickfix window
196 function! GetBufferList()
197 redir =>buflist
198 silent! ls!
199 redir END
200 return buflist
201 endfunction
202
203 function! ToggleList(bufname, pfx)
204 let buflist = GetBufferList()
205 for bufnum in map(filter(split(buflist, '\n'), 'v:val =~ "'.a:bufname.'"'), 'str2nr(matchstr(v:val, "\\d\\+"))')
206 if bufwinnr(bufnum) != -1
207 exec(a:pfx.'close')
208 return
209 endif
210 endfor
211 if a:pfx == 'l' && len(getloclist(0)) == 0
212 echohl ErrorMsg
213 echo "Location List is Empty."
214 return
215 endif
216 let winnr = winnr()
217 exec('botright '.a:pfx.'open')
218 if winnr() != winnr
219 wincmd p
220 endif
221 endfunction
222
223 nnoremap <silent> <F10> :call ToggleList("Quickfix List", 'c')<CR>
224 "
225
226 107
227 " Make list-like commands more intuitive 108 " Make list-like commands more intuitive
228 " Copied from https://gist.github.com/romainl/047aca21e338df7ccf771f96858edb86 109 " Copied from https://gist.github.com/romainl/047aca21e338df7ccf771f96858edb86
229 function! CCR() 110 function! CCR()
230 let cmdline = getcmdline() 111 let cmdline = getcmdline()