diff options
author | Squibid <me@zacharyscheiman.com> | 2024-08-09 02:45:31 -0400 |
---|---|---|
committer | Squibid <me@zacharyscheiman.com> | 2024-08-09 02:45:31 -0400 |
commit | c489d393695e90d424f9ae51e35c4d42358e6a71 (patch) | |
tree | 12ea97ec4684fd82cd6b73dd127d0137b115837b /lua/conf/autos.lua | |
parent | ad76983d969c318e6e234bc82384b4b025d70447 (diff) | |
download | nvim-c489d393695e90d424f9ae51e35c4d42358e6a71.tar.gz nvim-c489d393695e90d424f9ae51e35c4d42358e6a71.tar.bz2 nvim-c489d393695e90d424f9ae51e35c4d42358e6a71.zip |
yes there's a bit of java in my nvim config why do you ask?
Diffstat (limited to '')
-rw-r--r-- | lua/conf/autos.lua | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/lua/conf/autos.lua b/lua/conf/autos.lua new file mode 100644 index 0000000..51ed58a --- /dev/null +++ b/lua/conf/autos.lua @@ -0,0 +1,50 @@ +local misc = require('core.misc') +local auto, augroup = misc.auto, misc.augroup + +-- auto commands which interact with bufferes without modifying them +local bufcheck = augroup('bufcheck') +-- auto commands which modify things on the filesystem +local fsmod = augroup('fsmod') + +auto('FocusGained', { + group = bufcheck, + desc = 'Update contents of file.', + command = 'checktime', +}) + +auto('TextYankPost', { + pattern = '*', + group = bufcheck, + desc = 'Highlight on yank.', + callback = function() + vim.highlight.on_yank { timeout = 250 } + end +}) + +auto('BufRead', { + pattern = '*', + group = bufcheck, + desc = 'Return to the last place the buffer was closed in.', + callback = function() + vim.cmd([[call setpos(".", getpos("'\""))]]) + vim.api.nvim_input('zz') + end +}) + +auto('BufWritePre', { + pattern = '*', + group = fsmod, + desc = 'remove trailing spaces on file save', + command = [[%s/\s\+$//e]] +}) + +auto('BufWritePre', { + pattern = '*', + group = fsmod, + desc = 'Basically mkdir -p.', + callback = function(ctx) + if ctx.match:match("^%w%w+://") then return end + local dir = vim.fn.fnamemodify(ctx.file, ':p:h') + vim.fn.mkdir(dir, 'p') + end +}) |