comparison .chezmoitemplates/config.vim @ 489:1635e29e0ed4

Move autocmds to init.lua
author zegervdv <zegervdv@me.com>
date Sun, 14 Nov 2021 09:34:26 +0100
parents 3449f059b93e
children 16cc2c9c3d6b
comparison
equal deleted inserted replaced
488:8edc5f86e9c3 489:1635e29e0ed4
19 let g:python_host_prog=expand('$HOME/.config/virtualenvs/python2/bin/python') 19 let g:python_host_prog=expand('$HOME/.config/virtualenvs/python2/bin/python')
20 endif 20 endif
21 " 21 "
22 22
23 " General Settings and options 23 " General Settings and options
24
25 augroup cline
26 au!
27 autocmd WinEnter * setlocal cursorline
28 autocmd WinLeave * setlocal nocursorline
29 augroup END
30 24
31 if !s:windows 25 if !s:windows
32 if !isdirectory(expand(&backupdir)) 26 if !isdirectory(expand(&backupdir))
33 call mkdir(expand(&backupdir), "p") 27 call mkdir(expand(&backupdir), "p")
34 endif 28 endif
116 endfunction 110 endfunction
117 111
118 " Swap backticks and quotes 112 " Swap backticks and quotes
119 nnoremap ` ' 113 nnoremap ` '
120 nnoremap ' ` 114 nnoremap ' `
121
122 " Open vimrc
123 nnoremap <leader>ve :e $MYVIMRC<CR>
124 nnoremap <leader>vs :so $MYVIMRC<CR>
125
126 " Open dup in diffmode
127 nnoremap <leader>d :call OpenDup(@%)<CR>
128
129 function! OpenDup(file)
130 let l:filename = a:file . ".dup"
131 execute 'vsplit' l:filename
132 windo diffthis
133 endfunction
134 115
135 " Do not move on * 116 " Do not move on *
136 nnoremap <silent> * :let stay_star_view = winsaveview()<cr>*:call winrestview(stay_star_view)<cr> 117 nnoremap <silent> * :let stay_star_view = winsaveview()<cr>*:call winrestview(stay_star_view)<cr>
137 118
138 " Search for selected text, forwards or backwards. 119 " Search for selected text, forwards or backwards.
145 \let old_reg=getreg('"')<Bar>let old_regtype=getregtype('"')<CR> 126 \let old_reg=getreg('"')<Bar>let old_regtype=getregtype('"')<CR>
146 \gvy?<C-R><C-R>=substitute( 127 \gvy?<C-R><C-R>=substitute(
147 \escape(@", '?\.*$^~['), '\_s\+', '\\_s\\+', 'g')<CR><CR> 128 \escape(@", '?\.*$^~['), '\_s\+', '\\_s\\+', 'g')<CR><CR>
148 \gV:call setreg('"', old_reg, old_regtype)<CR> 129 \gV:call setreg('"', old_reg, old_regtype)<CR>
149 130
150 " nnoremap <F10> :botright copen<CR>
151
152 xnoremap <silent> p p:if v:register == '"'<Bar>let @@=@0<Bar>endif<CR> 131 xnoremap <silent> p p:if v:register == '"'<Bar>let @@=@0<Bar>endif<CR>
153 132
154 " Error navigation 133 " Error navigation
155 nnoremap <UP> :cprev<CR> 134 nnoremap <UP> :cprev<CR>
156 nnoremap <DOWN> :cnext<CR> 135 nnoremap <DOWN> :cnext<CR>
157 nnoremap <RIGHT> :cnf<CR> 136 nnoremap <RIGHT> :cnf<CR>
158 nnoremap <LEFT> :cpf<CR> 137 nnoremap <LEFT> :cpf<CR>
159 138
160 nnoremap <leader>y :ptjump <c-r><c-w><CR> 139 nnoremap <leader>y :ptjump <c-r><c-w><CR>
161
162 function! ToggleDiff()
163 if &diff == 1
164 windo diffoff
165 else
166 windo diffthis
167 endif
168 endfunction
169 nnoremap <leader>g :call ToggleDiff()<CR>
170 140
171 if has('nvim') 141 if has('nvim')
172 tnoremap <C-h> <C-\><C-n><C-w>h 142 tnoremap <C-h> <C-\><C-n><C-w>h
173 tnoremap <C-j> <C-\><C-n><C-w>j 143 tnoremap <C-j> <C-\><C-n><C-w>j
174 tnoremap <C-k> <C-\><C-n><C-w>k 144 tnoremap <C-k> <C-\><C-n><C-w>k
180 autocmd BufLeave * if &buftype ==# 'terminal' | :stopinsert! | endif 150 autocmd BufLeave * if &buftype ==# 'terminal' | :stopinsert! | endif
181 augroup END 151 augroup END
182 let $GIT_EDITOR = 'nvr -cc split --remote-wait' 152 let $GIT_EDITOR = 'nvr -cc split --remote-wait'
183 endif 153 endif
184 154
185 " Open buffers, tags... in vertical splits
186 nnoremap <leader>b :vert sbuffer
187 nnoremap <leader>t :vert stjump
188 nnoremap <leader>f :vert sfind
189
190
191 " 155 "
192 156
193 " Functions 157 " Functions
194 " When editing a file, always jump to the last known cursor position. 158 " When editing a file, always jump to the last known cursor position.
195 " Don't do it for commit messages, when the position is invalid, or when 159 " Don't do it for commit messages, when the position is invalid, or when
197 autocmd BufReadPost * 161 autocmd BufReadPost *
198 \ if &ft != 'gitcommit' && line("'\"") > 0 && line("'\"") <= line("$") | 162 \ if &ft != 'gitcommit' && line("'\"") > 0 && line("'\"") <= line("$") |
199 \ exe "normal g`\"" | 163 \ exe "normal g`\"" |
200 \ endif 164 \ endif
201 165
202 " Thg mappings
203 function! s:HGhist(file)
204 if !empty(a:file)
205 let path = a:file
206 else
207 let path = expand('%')
208 endif
209 exec 'silent! !thg filelog ' . path . ' &'
210 endfunction
211
212 command! -nargs=? -complete=file HGhist call s:HGhist(<q-args>)
213
214 augroup focus_lost
215 au!
216 au FocusLost * if !&readonly | :wa | endif
217 augroup END
218
219 " Resize splits after window resize
220 augroup vim_resize
221 au!
222 au VimResized * exe "normal! \<c-w>="
223 augroup END
224 "
225
226 " Automatically reload vimrc when saving
227 augroup reload_vim
228 autocmd!
229 autocmd BufWritePost $MYVIMRC nested source $MYVIMRC
230 augroup END
231 "
232
233 " Reload diffs
234 augroup diff_files
235 au!
236 au BufWritePost * if &diff == 1 | diffupdate | endif
237 augroup END
238 "
239 166
240 " Detect Filetype from content if file has no extension 167 " Detect Filetype from content if file has no extension
241 augroup newFileDetection 168 augroup newFileDetection
242 au! 169 au!
243 autocmd CursorMovedI * call CheckFileType() 170 autocmd CursorMovedI * call CheckFileType()