dotfiles/nvim/.config/nvim/lua/core/commands.lua

45 lines
1.6 KiB
Lua

-- Highlight whatever is being yanked
vim.api.nvim_create_autocmd({ "TextYankPost" }, {
command = 'silent! lua require"vim.highlight".on_yank{timeout=500}',
desc = "Highlight yanked text whenevery yanking something",
group = vim.api.nvim_create_augroup("highlightyanks", { clear = true }),
})
-- Special setting for editing gopass files - make sure nothing leaks outside the directories it
-- is supposed to
vim.api.nvim_create_autocmd({ "BufNewFile", "BufRead" }, {
pattern = {
"/dev/shm/gopass.*",
"/dev/shm/pass.?*/?*.txt",
"$TMPDIR/pass.?*/?*.txt",
"/tmp/pass.?*/?*.txt",
},
command = "setlocal noswapfile nobackup noundofile nowritebackup viminfo=",
desc = "Don't leak any information when editing potential password files",
group = vim.api.nvim_create_augroup("passnoleak", { clear = true }),
})
-- remove line numbers from terminal buffers
vim.api.nvim_create_autocmd({ "TermOpen" }, {
desc = "Hide buffer numbers for terminals",
pattern = "*",
command = "setlocal nonumber norelativenumber",
})
-- Custom spell enable which fires an event that other things can
-- hook into.
-- Toggles off and on by default, only turns on if called with bang.
vim.api.nvim_create_user_command("SpellToggle", function(opt)
vim.opt.spell = opt.bang or not vim.opt.spell:get()
if vim.opt.spell:get() then
if next(opt.fargs) ~= nil then
vim.opt.spelllang = opt.fargs
end
vim.api.nvim_exec_autocmds("User", { pattern = "SpellEnable" })
vim.notify("Spellcheck enabled")
else
vim.api.nvim_exec_autocmds("User", { pattern = "SpellDisable" })
vim.notify("Spellcheck disabled")
end
end, { nargs = "*", bang = true })