Mercurial > dotfiles
changeset 489:1635e29e0ed4
Move autocmds to init.lua
author | zegervdv <zegervdv@me.com> |
---|---|
date | Sun, 14 Nov 2021 09:34:26 +0100 |
parents | 8edc5f86e9c3 |
children | f49b0b91925c |
files | .chezmoitemplates/au.lua .chezmoitemplates/config.vim .chezmoitemplates/init.lua |
diffstat | 3 files changed, 43 insertions(+), 79 deletions(-) [+] |
line wrap: on
line diff
--- a/.chezmoitemplates/au.lua Sat Nov 13 15:22:08 2021 +0100 +++ b/.chezmoitemplates/au.lua Sun Nov 14 09:34:26 2021 +0100 @@ -11,6 +11,7 @@ action = this.set(action) end local e = type(event) == 'table' and table.concat(event, ',') or event + local pattern = type(pattern) == 'table' and table.concat(pattern, ',') or pattern cmd('autocmd ' .. e .. ' ' .. pattern .. ' ' .. action) end
--- a/.chezmoitemplates/config.vim Sat Nov 13 15:22:08 2021 +0100 +++ b/.chezmoitemplates/config.vim Sun Nov 14 09:34:26 2021 +0100 @@ -22,12 +22,6 @@ " General Settings and options -augroup cline - au! - autocmd WinEnter * setlocal cursorline - autocmd WinLeave * setlocal nocursorline -augroup END - if !s:windows if !isdirectory(expand(&backupdir)) call mkdir(expand(&backupdir), "p") @@ -119,19 +113,6 @@ nnoremap ` ' nnoremap ' ` -" Open vimrc -nnoremap <leader>ve :e $MYVIMRC<CR> -nnoremap <leader>vs :so $MYVIMRC<CR> - -" Open dup in diffmode -nnoremap <leader>d :call OpenDup(@%)<CR> - -function! OpenDup(file) - let l:filename = a:file . ".dup" - execute 'vsplit' l:filename - windo diffthis -endfunction - " Do not move on * nnoremap <silent> * :let stay_star_view = winsaveview()<cr>*:call winrestview(stay_star_view)<cr> @@ -147,8 +128,6 @@ \escape(@", '?\.*$^~['), '\_s\+', '\\_s\\+', 'g')<CR><CR> \gV:call setreg('"', old_reg, old_regtype)<CR> -" nnoremap <F10> :botright copen<CR> - xnoremap <silent> p p:if v:register == '"'<Bar>let @@=@0<Bar>endif<CR> " Error navigation @@ -159,15 +138,6 @@ nnoremap <leader>y :ptjump <c-r><c-w><CR> -function! ToggleDiff() - if &diff == 1 - windo diffoff - else - windo diffthis - endif -endfunction -nnoremap <leader>g :call ToggleDiff()<CR> - if has('nvim') tnoremap <C-h> <C-\><C-n><C-w>h tnoremap <C-j> <C-\><C-n><C-w>j @@ -182,12 +152,6 @@ let $GIT_EDITOR = 'nvr -cc split --remote-wait' endif -" Open buffers, tags... in vertical splits -nnoremap <leader>b :vert sbuffer -nnoremap <leader>t :vert stjump -nnoremap <leader>f :vert sfind - - " " Functions @@ -199,43 +163,6 @@ \ exe "normal g`\"" | \ endif -" Thg mappings -function! s:HGhist(file) - if !empty(a:file) - let path = a:file - else - let path = expand('%') - endif - exec 'silent! !thg filelog ' . path . ' &' -endfunction - -command! -nargs=? -complete=file HGhist call s:HGhist(<q-args>) - -augroup focus_lost - au! - au FocusLost * if !&readonly | :wa | endif -augroup END - -" Resize splits after window resize -augroup vim_resize - au! - au VimResized * exe "normal! \<c-w>=" -augroup END -" - -" Automatically reload vimrc when saving -augroup reload_vim - autocmd! - autocmd BufWritePost $MYVIMRC nested source $MYVIMRC -augroup END -" - -" Reload diffs -augroup diff_files - au! - au BufWritePost * if &diff == 1 | diffupdate | endif -augroup END -" " Detect Filetype from content if file has no extension augroup newFileDetection
--- a/.chezmoitemplates/init.lua Sat Nov 13 15:22:08 2021 +0100 +++ b/.chezmoitemplates/init.lua Sun Nov 14 09:34:26 2021 +0100 @@ -612,6 +612,48 @@ [[substitute(getline(v:foldstart),'\\t',repeat('\ ',&tabstop),'g').'...'.trim(getline(v:foldend)) . ' (' . (v:foldend - v:foldstart + 1) . ' lines)']] opt.foldenable = false +local au = require 'au' + +-- Highlight yanked text +au.TextYankPost = function() + vim.highlight.on_yank { timeout = 120 } +end + +-- Automatic cursorline +au.group('cline', { + { + 'WinEnter', + '*', + function() + vim.opt_local.cursorline = true + end, + }, + { + 'WinLeave', + '*', + function() + vim.opt_local.cursorline = false + end, + }, +}) + +-- Save files on focus lost +au.FocusLost = function() + if not vim.o.readonly and vim.api.nvim_buf_get_name(0) ~= '' then + vim.cmd [[ wa ]] + end +end + +-- Equalize splits after resizing +au.VimResized = [[ exe "normal! \<c-w>=" ]] + +-- Reload diffs after editing +au.BufWritePost = function() + if vim.o.diff then + vim.cmd [[ diffupdate ]] + end +end + -- LSP config local lsp = require 'lspconfig' local null_ls = require 'null-ls' @@ -776,12 +818,6 @@ vim.cmd [[command! LspRename lua LspRename()]] -local au = require 'au' - -au.TextYankPost = function() - vim.highlight.on_yank { timeout = 120 } -end - vim.diagnostic.config { underline = true, update_in_insert = false,