dotfiles/nvim/.config/nvim/lua/plugins/ui.lua
Marty Oehme 4f2acad60d
nvim: Add todo comment highlighting plugin
Added todo-comments.nvim plugin by folke, which will automatically
highlight (in a sane color) all the `TODO:`, `FIXME:`, `WARN:`, and more
comments within code.
2024-08-07 21:17:17 +02:00

276 lines
7.1 KiB
Lua

return {
-- statusline
{
"nvim-lualine/lualine.nvim",
dependencies = { { "nvim-tree/nvim-web-devicons", config = true } },
config = function()
local has_pynvim = -1
-- if molten exists, is initialized and connected to a kernel
-- show it in the statusline
local function molten()
local function checked_pynvim(_, exitcode)
if exitcode == 0 then
has_pynvim = 1
else
has_pynvim = 0
end
end
if has_pynvim == 0 then
return ""
elseif has_pynvim == -1 then
vim.fn.jobstart({ "python", "-c", "from neovim import VERSION" }, { on_exit = checked_pynvim })
end
if
has_pynvim == 1
and require("core.util").is_available("molten.status")
and require("molten.status").kernels() ~= ""
then
return "󱪄"
end
return ""
end
-- count number of selected lines and characters
-- stolen: https://github.com/chrisgrieser/.config/blob/8af1841ba24f7c81c513e12f853b52f530ef5b37/nvim/lua/plugins/lualine.lua#L80C1-L87C4
local function selectionCount()
local isVisualMode = vim.fn.mode():find("[Vv]")
if not isVisualMode then
return ""
end
local starts = vim.fn.line("v")
local ends = vim.fn.line(".")
local lines = starts <= ends and ends - starts + 1 or starts - ends + 1
return " " .. tostring(lines) .. "L " .. tostring(vim.fn.wordcount().visual_chars) .. "C"
end
require("lualine").setup({
options = {
icons_enabled = true,
theme = "auto",
component_separators = { left = "", right = "" },
section_separators = { left = "", right = "" },
disabled_filetypes = {},
always_divide_middle = true,
},
sections = {
lualine_a = { "mode" },
lualine_b = { "branch", "diff", "diagnostics" },
lualine_c = { "filename" },
lualine_x = { "encoding", "fileformat", "filetype", molten },
lualine_y = { "progress" },
lualine_z = { selectionCount, "location" },
},
inactive_sections = {
lualine_a = {},
lualine_b = { "branch", "diff" },
lualine_c = { "filename" },
lualine_x = {},
lualine_y = { "location" },
lualine_z = {},
},
tabline = {},
extensions = {
"aerial",
"lazy",
"man",
"mason",
"nvim-dap-ui",
"nvim-tree",
"oil",
"quickfix",
"toggleterm",
"trouble",
},
})
end,
event = { "VeryLazy" },
},
-- create pretty unobtrusive notifications
{
"j-hui/fidget.nvim",
opts = {
progress = {
suppress_on_insert = true,
ignore_done_already = true,
},
notification = {
override_vim_notify = true,
},
},
event = { "VeryLazy" },
cmd = { "Fidget" },
keys = {
{ "<leader>sh", "<cmd>Fidget history<cr>", { silent = true, desc = "show notification history" } },
},
},
-- make all vim.ui interfaces prettyy
{ "stevearc/dressing.nvim", config = true, event = "VeryLazy" },
-- numbers to absolute for all buffers but the current which is relative
{ "jeffkreeftmeijer/vim-numbertoggle", event = "InsertEnter" },
-- auto-hiding colorcolumn
{
"m4xshen/smartcolumn.nvim",
event = "BufEnter",
opts = {
colorcolumn = { "100" },
scope = "window",
disabled_filetypes = {
"help",
"text",
"markdown",
"NvimTree",
"lazy",
"mason",
"help",
"quarto",
},
},
},
-- display pretty colors when they are mentioned in buffer
{
"NvChad/nvim-colorizer.lua", -- color hex, named colors in the correct preview scheme
config = function()
require("colorizer").setup({
user_default_options = { mode = "virtualtext" },
})
end,
cmd = {
"ColorizerToggle",
"ColorizerAttachToBuffer",
"ColorizerDetachFromBuffer",
"ColorizerReloadAllBuffers",
},
keys = {
{ "<localleader>sc", "<cmd>ColorizerToggle<cr>", { silent = true, desc = "toggle colorizer" } },
{
"<localleader>sC",
'<cmd>lua require("colorizer").attach_to_buffer(0, {mode = "background"} )<cr>',
{ silent = true, desc = "colorize background" },
},
},
},
{
"folke/todo-comments.nvim",
dependencies = { "nvim-lua/plenary.nvim" },
opts = {},
event = "VeryLazy",
},
{
"jiaoshijie/undotree",
dependencies = {
"nvim-lua/plenary.nvim",
},
config = true,
keys = {
{
"<leader>su",
function()
require("undotree").toggle()
end,
desc = "toggle undotree",
silent = true,
},
},
},
-- simpler, programmable and multiple terminal toggling for nvim
{
"akinsho/nvim-toggleterm.lua",
config = function()
require("toggleterm").setup({
open_mapping = [[<leader>=]],
insert_mappings = false, -- don't map the key in insert mode
terminal_mappings = false,
})
local Terminal = require("toggleterm.terminal").Terminal
-- need to disable indentlines since they obscure first line of terminal
if require("core.util").is_available("mini.nvim") then
vim.api.nvim_create_autocmd({ "TermOpen" }, {
pattern = "*",
callback = function()
vim.b.miniindentscope_disable = true
end,
})
end
local function custom_term_set_toggle_key(term)
vim.keymap.set("t", "<C-\\>", function()
term:toggle()
end, { silent = true, buffer = true })
end
-- create python window
local function get_python_cmd()
if vim.fn.executable("py") then
return "py"
end
if vim.fn.executable("ptipython") then
return "ptipython"
end
if vim.fn.executable("ipython") then
return "ipython"
end
if vim.fn.executable("ptpython") then
return "ptpython"
end
if vim.fn.executable("python") then
return "python"
end
end
local terms = {
lazygit = Terminal:new({
cmd = "lazygit",
hidden = true,
direction = "float",
float_opts = { border = "curved" },
on_open = custom_term_set_toggle_key,
}),
python = Terminal:new({
cmd = get_python_cmd(),
hidden = true,
direction = "float",
float_opts = { border = "curved" },
on_open = custom_term_set_toggle_key,
}),
}
-- create a lazygit window with the lazygit command
local function toggle_custom_term(term, bang, vertsize)
vertsize = vertsize or vim.o.columns * 0.4
if not bang then
term.direction = "float"
term:toggle()
else
term.direction = "vertical"
term:resize(vertsize)
term:toggle()
end
end
local function _Pythonterm_toggle(opts)
toggle_custom_term(terms.python, opts.bang)
end
local function _Lazygit_toggle(opts)
toggle_custom_term(terms.lazygit, opts.bang, vim.o.columns * 0.6)
end
vim.api.nvim_create_user_command(
"Lazygit",
_Lazygit_toggle,
{ desc = "Toggle floating Lazygit terminal", bang = true }
)
vim.api.nvim_create_user_command(
"Pythonterm",
_Pythonterm_toggle,
{ desc = "Toggle floating Python terminal", bang = true }
)
end,
cmd = { "ToggleTerm", "TermExec", "Lazygit", "Pythonterm" },
keys = {
{ "<leader>sg", ":Lazygit<cr>", desc = "git floating" },
{ "<leader>sG", ":Lazygit!<cr>", desc = "git buffer" },
{ "<leader>sp", ":Pythonterm<cr>", desc = "python floating" },
{ "<leader>sP", ":Pythonterm!<cr>", desc = "python buffer" },
},
},
}