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)
|
2023-07-11 03:43:47 +00:00
|
|
|
if vim.b.lnstatus == nil then
|
|
|
|
vim.b.lnstatus = "number"
|
|
|
|
end
|
2023-02-28 02:27:44 +00:00
|
|
|
|
2023-07-11 03:43:47 +00:00
|
|
|
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
|
2023-02-28 02:27:44 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
autocmd("InsertEnter", {
|
2023-07-11 03:43:47 +00:00
|
|
|
pattern = "*",
|
|
|
|
callback = function()
|
|
|
|
relativeln("number")
|
|
|
|
end,
|
|
|
|
once = false,
|
|
|
|
group = _group,
|
2023-02-28 02:27:44 +00:00
|
|
|
})
|
|
|
|
autocmd("InsertLeave", {
|
2023-07-11 03:43:47 +00:00
|
|
|
pattern = "*",
|
|
|
|
callback = function()
|
|
|
|
relativeln("relativenumber")
|
|
|
|
end,
|
|
|
|
once = false,
|
|
|
|
group = _group,
|
2023-02-28 02:27:44 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
autocmd("FocusLost", {
|
2023-07-11 03:43:47 +00:00
|
|
|
pattern = "*",
|
|
|
|
callback = function()
|
|
|
|
relativeln("number")
|
|
|
|
end,
|
|
|
|
once = false,
|
|
|
|
group = _group,
|
2023-02-28 02:27:44 +00:00
|
|
|
})
|
|
|
|
autocmd("CursorMoved", {
|
2023-07-11 03:43:47 +00:00
|
|
|
pattern = "*",
|
|
|
|
callback = function()
|
|
|
|
relativeln("relativenumber")
|
|
|
|
end,
|
|
|
|
once = false,
|
|
|
|
group = _group,
|
2023-02-28 02:27:44 +00:00
|
|
|
})
|
|
|
|
|
2023-07-11 03:43:47 +00:00
|
|
|
vim.cmd([[
|
|
|
|
:augroup fmt
|
|
|
|
: autocmd!
|
|
|
|
: autocmd BufWritePre * silent! undojoin | silent! Neoformat
|
|
|
|
:augroup END
|
|
|
|
]])
|
|
|
|
|
|
|
|
local nvim_tree_events = require("nvim-tree.events")
|
|
|
|
local bufferline_api = require("bufferline.api")
|
2023-03-03 07:35:22 +00:00
|
|
|
|
|
|
|
local function get_tree_size()
|
2023-07-11 03:43:47 +00:00
|
|
|
return require("nvim-tree.view").View.width
|
2023-03-03 07:35:22 +00:00
|
|
|
end
|
|
|
|
|
2023-07-11 03:43:47 +00:00
|
|
|
nvim_tree_events.subscribe("TreeOpen", function()
|
|
|
|
bufferline_api.set_offset(get_tree_size())
|
2023-03-03 07:35:22 +00:00
|
|
|
end)
|
|
|
|
|
2023-07-11 03:43:47 +00:00
|
|
|
nvim_tree_events.subscribe("Resize", function()
|
|
|
|
bufferline_api.set_offset(get_tree_size())
|
2023-03-03 07:35:22 +00:00
|
|
|
end)
|
|
|
|
|
2023-07-11 03:43:47 +00:00
|
|
|
nvim_tree_events.subscribe("TreeClose", function()
|
|
|
|
bufferline_api.set_offset(0)
|
2023-03-03 07:35:22 +00:00
|
|
|
end)
|
|
|
|
|
2023-02-28 02:27:44 +00:00
|
|
|
-- change tmux title
|
|
|
|
autocmd("BufReadPost", {
|
2023-07-11 03:43:47 +00:00
|
|
|
pattern = "*",
|
|
|
|
callback = function()
|
|
|
|
vim.cmd([[call system("tmux rename-window '" . expand("%:t") . "'")]])
|
|
|
|
end,
|
|
|
|
once = false,
|
|
|
|
group = _group,
|
2023-02-28 02:27:44 +00:00
|
|
|
})
|
|
|
|
autocmd("FileReadPost", {
|
2023-07-11 03:43:47 +00:00
|
|
|
pattern = "*",
|
|
|
|
callback = function()
|
|
|
|
vim.cmd([[call system("tmux rename-window '" . expand("%:t") . "'")]])
|
|
|
|
end,
|
|
|
|
once = false,
|
|
|
|
group = _group,
|
2023-02-28 02:27:44 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
autocmd("BufNewFile", {
|
2023-07-11 03:43:47 +00:00
|
|
|
pattern = "*",
|
|
|
|
callback = function()
|
|
|
|
vim.cmd([[call system("tmux rename-window '" . expand("%:t") . "'")]])
|
|
|
|
end,
|
|
|
|
once = false,
|
|
|
|
group = _group,
|
2023-02-28 02:27:44 +00:00
|
|
|
})
|
|
|
|
autocmd("BufEnter", {
|
2023-07-11 03:43:47 +00:00
|
|
|
pattern = "*",
|
|
|
|
callback = function()
|
|
|
|
vim.cmd([[call system("tmux rename-window '" . expand("%:t") . "'")]])
|
|
|
|
end,
|
|
|
|
once = false,
|
|
|
|
group = _group,
|
2023-02-28 02:27:44 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
-- auto close nvimtree
|
2023-07-11 03:43:47 +00:00
|
|
|
autocmd("BufEnter", {
|
|
|
|
command = "if winnr('$') == 1 && bufname() == 'NvimTree_' . tabpagenr() | quit | endif",
|
|
|
|
nested = true,
|
2023-02-28 02:27:44 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
-- dont show line numbers for nvimtree buffers
|
2023-07-11 03:43:47 +00:00
|
|
|
autocmd("BufEnter", {
|
|
|
|
pattern = { "NvimTree*" },
|
|
|
|
callback = function()
|
|
|
|
vim.b.lnstatus = "nonumber"
|
|
|
|
end,
|
|
|
|
})
|
2023-02-28 02:27:44 +00:00
|
|
|
|
|
|
|
-- Disable the statusline, tabline and cmdline while the alpha dashboard is open
|
2023-07-11 03:43:47 +00:00
|
|
|
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,
|
2023-02-28 02:27:44 +00:00
|
|
|
})
|
2023-07-11 03:43:47 +00:00
|
|
|
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,
|
2023-02-28 02:27:44 +00:00
|
|
|
})
|