absvim/lua/autocmds.lua

146 lines
3.1 KiB
Lua
Raw Normal View History

2023-02-28 02:27:44 +00:00
local autocmd = vim.api.nvim_create_autocmd -- Create autocommand
---- Toggle between line numbers and relative line numbers
local _group = vim.api.nvim_create_augroup("LineNumber", { clear = true })
local function relativeln(target)
if vim.b.lnstatus == nil then
vim.b.lnstatus = "number"
end
if vim.b.lnstatus ~= "nonumber" then
if target == "number" then
vim.o.number = true
vim.o.relativenumber = false
else
vim.o.number = true
vim.o.relativenumber = true
end
else
vim.o.number = false
end
end
autocmd("InsertEnter", {
pattern = "*",
callback = function()
relativeln("number")
end,
once = false,
group = _group,
})
autocmd("InsertLeave", {
pattern = "*",
callback = function()
relativeln("relativenumber")
end,
once = false,
group = _group,
})
autocmd("FocusLost", {
pattern = "*",
callback = function()
relativeln("number")
end,
once = false,
group = _group,
})
autocmd("CursorMoved", {
pattern = "*",
callback = function()
relativeln("relativenumber")
end,
once = false,
group = _group,
})
2023-03-03 07:35:22 +00:00
local nvim_tree_events = require('nvim-tree.events')
local bufferline_api = require('bufferline.api')
local function get_tree_size()
return require 'nvim-tree.view'.View.width
end
nvim_tree_events.subscribe('TreeOpen', function()
bufferline_api.set_offset(get_tree_size())
end)
nvim_tree_events.subscribe('Resize', function()
bufferline_api.set_offset(get_tree_size())
end)
nvim_tree_events.subscribe('TreeClose', function()
bufferline_api.set_offset(0)
end)
2023-02-28 02:27:44 +00:00
-- change tmux title
autocmd("BufReadPost", {
pattern = "*",
callback = function()
vim.cmd([[call system("tmux rename-window '" . expand("%:t") . "'")]])
end,
once = false,
group = _group,
})
autocmd("FileReadPost", {
pattern = "*",
callback = function()
vim.cmd([[call system("tmux rename-window '" . expand("%:t") . "'")]])
end,
once = false,
group = _group,
})
autocmd("BufNewFile", {
pattern = "*",
callback = function()
vim.cmd([[call system("tmux rename-window '" . expand("%:t") . "'")]])
end,
once = false,
group = _group,
})
autocmd("BufEnter", {
pattern = "*",
callback = function()
vim.cmd([[call system("tmux rename-window '" . expand("%:t") . "'")]])
end,
once = false,
group = _group,
})
-- auto close nvimtree
autocmd('BufEnter', {
command = "if winnr('$') == 1 && bufname() == 'NvimTree_' . tabpagenr() | quit | endif",
nested = true,
})
-- dont show line numbers for nvimtree buffers
autocmd("BufEnter",
{
pattern = { "NvimTree*" },
callback = function()
vim.b.lnstatus = "nonumber"
end
})
-- Disable the statusline, tabline and cmdline while the alpha dashboard is open
autocmd('User', {
pattern = 'AlphaReady',
desc = 'disable status, tabline and cmdline for alpha',
callback = function()
vim.go.laststatus = 1
vim.opt.showtabline = 1
vim.opt.cmdheight = 1
end,
})
autocmd('BufUnload', {
buffer = 0,
desc = 'enable status, tabline and cmdline after alpha',
callback = function()
vim.go.laststatus = 2
vim.opt.showtabline = 2
vim.opt.cmdheight = 1
end,
})