2024-04-23 04:34:15 +02:00
|
|
|
-- [[ Highlight on yank ]]
|
|
|
|
vim.api.nvim_create_autocmd("TextYankPost", {
|
2024-04-24 06:24:28 +02:00
|
|
|
callback = function()
|
|
|
|
vim.highlight.on_yank({ timeout = 100 })
|
|
|
|
end,
|
|
|
|
group = vim.api.nvim_create_augroup("YankHighlight", { clear = true }),
|
|
|
|
pattern = "*",
|
2024-04-23 04:34:15 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
-- [[ Disable Autocommenting on new lines ]]
|
|
|
|
vim.api.nvim_create_autocmd("BufEnter", {
|
2024-04-24 06:24:28 +02:00
|
|
|
callback = function()
|
|
|
|
vim.opt.formatoptions:remove({ "c", "r", "o" })
|
|
|
|
end,
|
|
|
|
group = vim.api.nvim_create_augroup("DisableAutocommenting", { clear = true }),
|
2024-04-23 04:34:15 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
-- [[ Update file on Focus ]]
|
|
|
|
vim.api.nvim_create_autocmd("FocusGained", {
|
2024-04-24 06:24:28 +02:00
|
|
|
callback = function()
|
|
|
|
vim.cmd("checktime")
|
|
|
|
end,
|
|
|
|
group = vim.api.nvim_create_augroup("UpdateOnFocus", { clear = true }),
|
2024-04-23 04:34:15 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
-- [[ Open lf when it's a Directory ]]
|
|
|
|
vim.api.nvim_create_autocmd("VimEnter", {
|
2024-04-24 06:24:28 +02:00
|
|
|
callback = function(data)
|
|
|
|
local directory = vim.fn.isdirectory(data.file) == 1
|
|
|
|
if directory then
|
|
|
|
require("lf").start()
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
group = vim.api.nvim_create_augroup("lf_ifDirectory", { clear = true }),
|
2024-04-23 04:34:15 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
-- [[ Remove trailing whitespaces ]]
|
|
|
|
vim.api.nvim_create_autocmd({ "BufWritePre" }, {
|
2024-04-24 06:24:28 +02:00
|
|
|
pattern = { "*" },
|
|
|
|
callback = function()
|
|
|
|
local save_cursor = vim.fn.getpos(".")
|
|
|
|
vim.cmd([[%s/\s\+$//e]])
|
|
|
|
vim.cmd([[%s/\n\+\%$//e]])
|
|
|
|
vim.fn.setpos(".", save_cursor)
|
|
|
|
end,
|
|
|
|
group = vim.api.nvim_create_augroup("RemoveTrailingWhitespaces", { clear = true }),
|
2024-04-23 04:34:15 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
-- [[ Restore last cursor position ]]
|
|
|
|
vim.api.nvim_create_autocmd("BufReadPost", {
|
|
|
|
pattern = "*",
|
|
|
|
callback = function()
|
|
|
|
local line = vim.fn.line "'\""
|
|
|
|
if
|
2024-04-24 06:24:28 +02:00
|
|
|
line > 1
|
|
|
|
and line <= vim.fn.line "$"
|
|
|
|
and vim.bo.filetype ~= "commit"
|
|
|
|
and vim.fn.index({ "xxd", "gitrebase" }, vim.bo.filetype) == -1
|
2024-04-23 04:34:15 +02:00
|
|
|
then
|
|
|
|
vim.cmd 'normal! g`"zz'
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
|
|
|
-- [[ Reload xresources on write ]]
|
|
|
|
vim.api.nvim_create_autocmd({ "BufWritePost" }, {
|
2024-04-24 06:24:28 +02:00
|
|
|
pattern = vim.fn.resolve(vim.fn.expand("~/.config/x11/xresources")),
|
|
|
|
callback = function()
|
|
|
|
-- cmd([[!xrdb % ; killall -USR1 st ; renew-dwm ; notify-send " - xresources reloaded"]])
|
|
|
|
vim.cmd([[!xrdb % ; killall -USR1 st ; renew-dwm]])
|
|
|
|
end,
|
|
|
|
group = vim.api.nvim_create_augroup("ReloadXresources", { clear = true }),
|
2024-04-23 04:34:15 +02:00
|
|
|
})
|
|
|
|
|
2024-05-16 18:26:31 +02:00
|
|
|
-- [[ Restore cursor shape on exit]]
|
|
|
|
vim.api.nvim_create_autocmd({ "VimLeave" }, {
|
|
|
|
pattern = "*",
|
|
|
|
callback = function()
|
|
|
|
vim.cmd("set guicursor=a:hor20-blinkon500-blinkoff500-blinkwait700")
|
|
|
|
end,
|
|
|
|
group = vim.api.nvim_create_augroup("RestoreCursor", { clear = true }),
|
|
|
|
})
|
|
|
|
|
2024-04-23 04:34:15 +02:00
|
|
|
-- [[ Recompile suckless software on write and show notification ]]
|
|
|
|
local function recompile(path)
|
2024-04-24 06:24:28 +02:00
|
|
|
vim.api.nvim_create_augroup("RecompileGroup_" .. path, { clear = true })
|
|
|
|
vim.api.nvim_create_autocmd({ "BufWritePost" }, {
|
|
|
|
pattern = vim.fn.resolve(vim.fn.expand(path)),
|
|
|
|
callback = function()
|
|
|
|
local dir = vim.fn.fnamemodify(path, ":h")
|
2024-05-16 18:26:31 +02:00
|
|
|
local shell_cmd = string.format("cd %s && sudo make install && renew-dwm && notify-send ' refresh complete'", dir)
|
2024-04-24 06:24:28 +02:00
|
|
|
vim.cmd("!" .. shell_cmd)
|
|
|
|
end,
|
|
|
|
})
|
2024-04-23 04:34:15 +02:00
|
|
|
end
|
2024-04-24 06:24:28 +02:00
|
|
|
|
2024-04-23 04:34:15 +02:00
|
|
|
recompile("~/.config/suckless/dwm/config.h")
|
|
|
|
recompile("~/.config/suckless/dmenu/config.h")
|
|
|
|
recompile("~/.config/suckless/st/config.h")
|
|
|
|
recompile("~/.config/suckless/dwmblocks/config.h")
|
2024-04-25 08:43:27 +02:00
|
|
|
recompile("~/.config/suckless/slock/config.h")
|
2024-04-23 04:34:15 +02:00
|
|
|
|
|
|
|
--[[ Close nvim if toggleterm or Outline is the last buffer ]]
|
|
|
|
vim.api.nvim_create_autocmd({ "BufEnter" }, {
|
2024-04-24 06:24:28 +02:00
|
|
|
pattern = "*",
|
|
|
|
callback = function()
|
|
|
|
if
|
|
|
|
vim.fn.tabpagenr("$") == 1
|
|
|
|
and vim.fn.winnr("$") == 1
|
|
|
|
and (vim.bo.ft == "toggleterm" or vim.bo.ft == "Outline")
|
|
|
|
then
|
|
|
|
vim.cmd("bd! | q")
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
group = vim.api.nvim_create_augroup("CloseLast", { clear = true }),
|
2024-04-23 04:34:15 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
-- [[ Autosave ]]
|
|
|
|
-- vim.api.nvim_create_autocmd({ "FocusLost", "BufLeave", "BufWinLeave", "InsertLeave" }, {
|
|
|
|
-- callback = function()
|
|
|
|
-- if vim.bo.filetype ~= "" and vim.bo.buftype == "" then
|
|
|
|
-- vim.cmd("silent! w")
|
|
|
|
-- end
|
|
|
|
-- end,
|
|
|
|
-- group = vim.api.nvim_create_augroup("AutoSave", { clear = true }),
|
|
|
|
-- })
|