summaryrefslogtreecommitdiff
path: root/pkgs/custom-neovim/config
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/custom-neovim/config')
-rw-r--r--pkgs/custom-neovim/config/init.lua1
-rw-r--r--pkgs/custom-neovim/config/lua/keymaps.lua5
-rw-r--r--pkgs/custom-neovim/config/lua/options.lua3
-rw-r--r--pkgs/custom-neovim/config/lua/plugins/auto-session.lua7
-rw-r--r--pkgs/custom-neovim/config/lua/plugins/fidget.lua7
-rw-r--r--pkgs/custom-neovim/config/lua/plugins/heirline.lua24
-rw-r--r--pkgs/custom-neovim/config/lua/plugins/mini-files.lua73
-rw-r--r--pkgs/custom-neovim/config/lua/plugins/mini-pick.lua2
-rw-r--r--pkgs/custom-neovim/config/lua/statusline.lua264
9 files changed, 384 insertions, 2 deletions
diff --git a/pkgs/custom-neovim/config/init.lua b/pkgs/custom-neovim/config/init.lua
index d567b58..83b5ef1 100644
--- a/pkgs/custom-neovim/config/init.lua
+++ b/pkgs/custom-neovim/config/init.lua
@@ -5,3 +5,4 @@ require('lz.n').load('plugins')
require("options")
require("keymaps")
require("lsp")
+require("statusline")
diff --git a/pkgs/custom-neovim/config/lua/keymaps.lua b/pkgs/custom-neovim/config/lua/keymaps.lua
index 08558af..a96902e 100644
--- a/pkgs/custom-neovim/config/lua/keymaps.lua
+++ b/pkgs/custom-neovim/config/lua/keymaps.lua
@@ -26,6 +26,11 @@ mapkey("n", "<leader>gc", "Git commit", ":Git commit<cr>", "mini-git")
mapkey("n", "<leader>gp", "Git pull", ":Git pull<cr>", "mini-git")
mapkey("n", "<leader>gP", "Git push", ":Git push<cr>", "mini-git")
+-- Session
+mapkey("n", "<leader>w", "Manage sessions", "")
+mapkey("n", "<leader>ww", "Open a session", ":Autosession search<cr>", {"mini.pick"})
+mapkey("n", "<leader>wd", "Delete a session", ":Autosession delete<cr>", {"mini.pick"})
+
-- Terminal
mapkey("n", "<leader>t", "Open terminal", ":botright terminal<cr>")
diff --git a/pkgs/custom-neovim/config/lua/options.lua b/pkgs/custom-neovim/config/lua/options.lua
index 6840085..67c4469 100644
--- a/pkgs/custom-neovim/config/lua/options.lua
+++ b/pkgs/custom-neovim/config/lua/options.lua
@@ -12,6 +12,9 @@ vim.o.number = true -- set absolute numbered lines
vim.o.scrolloff = 4 -- minimal number of screen lines to keep above and below the cursor
vim.o.signcolumn = "yes" -- always show the sign column, otherwise it would shift the text each time
+-- Finding
+vim.o.gdefault = true -- Replace globally by default
+
-- Folding
vim.o.foldmethod = "expr"
vim.o.foldexpr = "v:lua.vim.treesitter.foldexpr()" -- Set folder to treesitter.
diff --git a/pkgs/custom-neovim/config/lua/plugins/auto-session.lua b/pkgs/custom-neovim/config/lua/plugins/auto-session.lua
new file mode 100644
index 0000000..b5a7a07
--- /dev/null
+++ b/pkgs/custom-neovim/config/lua/plugins/auto-session.lua
@@ -0,0 +1,7 @@
+return {
+ "auto-session",
+ lazy = false,
+ after = function ()
+ require("auto-session").setup()
+ end
+}
diff --git a/pkgs/custom-neovim/config/lua/plugins/fidget.lua b/pkgs/custom-neovim/config/lua/plugins/fidget.lua
new file mode 100644
index 0000000..d8b8baf
--- /dev/null
+++ b/pkgs/custom-neovim/config/lua/plugins/fidget.lua
@@ -0,0 +1,7 @@
+return {
+ "fidget.nvim",
+ lazy = false,
+ after = function ()
+ require("fidget").setup()
+ end
+}
diff --git a/pkgs/custom-neovim/config/lua/plugins/heirline.lua b/pkgs/custom-neovim/config/lua/plugins/heirline.lua
index bc0a503..6160c94 100644
--- a/pkgs/custom-neovim/config/lua/plugins/heirline.lua
+++ b/pkgs/custom-neovim/config/lua/plugins/heirline.lua
@@ -1,5 +1,6 @@
return {
"heirline.nvim",
+ enabled = false,
lazy = false,
after = function ()
-- Extra stuff from heirline.
@@ -206,7 +207,26 @@ return {
hl = { fg = "blue", bold = true },
}
- -- Git component.
+ -- Git branch component.
+ components.git_branch = {
+ -- condition = conditions.is_git_repo,
+ --
+ -- init = function (self)
+ -- self.branch = vim.b.minigit_summary.head_name or nil
+ -- end,
+
+ provider = function (self)
+ local branch = vim.b.minigit_summary.head_name or nil
+ if branch then
+ local icon = using_icons and " " or "branch: "
+ return icon .. branch
+ else
+ return "none"
+ end
+ end
+ }
+
+ -- Git status component.
components.git_status = {
condition = conditions.is_git_repo,
@@ -286,7 +306,7 @@ return {
-- Assemble statusline.
local statusline = {
components.mode, space,
- components.git, space,
+ components.git_branch, space,
components.cwd, space,
components.diagnostics,
diff --git a/pkgs/custom-neovim/config/lua/plugins/mini-files.lua b/pkgs/custom-neovim/config/lua/plugins/mini-files.lua
index d9b7d41..0dc977a 100644
--- a/pkgs/custom-neovim/config/lua/plugins/mini-files.lua
+++ b/pkgs/custom-neovim/config/lua/plugins/mini-files.lua
@@ -11,5 +11,78 @@ return {
preview = true,
},
}
+
+ -- Add functionality
+
+ -- Set focused directory as current working directory
+ local set_cwd = function()
+ local path = (MiniFiles.get_fs_entry() or {}).path
+ if path == nil then return vim.notify('Cursor is not on valid entry') end
+ vim.fn.chdir(vim.fs.dirname(path))
+ end
+
+ -- Yank in register full path of entry under cursor
+ local yank_path = function()
+ local path = (MiniFiles.get_fs_entry() or {}).path
+ if path == nil then return vim.notify('Cursor is not on valid entry') end
+ vim.fn.setreg(vim.v.register, path)
+ end
+
+ -- Open path with system default handler (useful for non-text files)
+ local ui_open = function() vim.ui.open(MiniFiles.get_fs_entry().path) end
+
+ vim.api.nvim_create_autocmd('User', {
+ pattern = 'MiniFilesBufferCreate',
+ callback = function(args)
+ local b = args.data.buf_id
+ vim.keymap.set('n', 'g~', set_cwd, { buffer = b, desc = 'Set cwd' })
+ vim.keymap.set('n', 'gX', ui_open, { buffer = b, desc = 'OS open' })
+ vim.keymap.set('n', 'gy', yank_path, { buffer = b, desc = 'Yank path' })
+ end,
+ })
+
+ -- Add custom bookmarks.
+ local set_mark = function(id, path, desc)
+ MiniFiles.set_bookmark(id, path, { desc = desc })
+ end
+
+ vim.api.nvim_create_autocmd('User', {
+ pattern = 'MiniFilesExplorerOpen',
+ callback = function()
+ set_mark('w', vim.fn.getcwd, 'Working directory') -- callable
+ set_mark('~', '~', 'Home directory')
+ end,
+ })
+
+ -- Add split keys
+ local map_split = function(buf_id, lhs, direction)
+ local rhs = function()
+ -- Make new window and set it as target
+ local cur_target = MiniFiles.get_explorer_state().target_window
+ local new_target = vim.api.nvim_win_call(cur_target, function()
+ vim.cmd(direction .. ' split')
+ return vim.api.nvim_get_current_win()
+ end)
+
+ MiniFiles.set_target_window(new_target)
+
+ MiniFiles.go_in()
+ end
+
+ -- Adding `desc` will result into `show_help` entries
+ local desc = 'Split ' .. direction
+ vim.keymap.set('n', lhs, rhs, { buffer = buf_id, desc = desc })
+ end
+
+ vim.api.nvim_create_autocmd('User', {
+ pattern = 'MiniFilesBufferCreate',
+ callback = function(args)
+ local buf_id = args.data.buf_id
+ -- Tweak keys to your liking
+ map_split(buf_id, '<C-s>', 'belowright horizontal')
+ map_split(buf_id, '<C-v>', 'belowright vertical')
+ map_split(buf_id, '<C-t>', 'tab')
+ end,
+ })
end
}
diff --git a/pkgs/custom-neovim/config/lua/plugins/mini-pick.lua b/pkgs/custom-neovim/config/lua/plugins/mini-pick.lua
index 25f88de..68e57ec 100644
--- a/pkgs/custom-neovim/config/lua/plugins/mini-pick.lua
+++ b/pkgs/custom-neovim/config/lua/plugins/mini-pick.lua
@@ -19,5 +19,7 @@ return {
}
vim.cmd.packadd("mini.extra")
require("mini.extra").setup()
+
+ vim.ui.select = MiniPick.ui_select
end
}
diff --git a/pkgs/custom-neovim/config/lua/statusline.lua b/pkgs/custom-neovim/config/lua/statusline.lua
new file mode 100644
index 0000000..e4b336b
--- /dev/null
+++ b/pkgs/custom-neovim/config/lua/statusline.lua
@@ -0,0 +1,264 @@
+-- Custom Statusline
+
+-- Whether to use icons.
+local use_icons = true
+
+-- Utility functions for components.
+local utils = {}
+
+-- The width of the statusline.
+utils.linewidth = function ()
+ if vim.o.laststatus == 3 then
+ return vim.o.columns
+ else
+ return vim.api.nvim_win_get_width(0)
+ end
+end
+
+utils.component_takes_percentage = function (comp_width, percentage)
+ return comp_width > (percentage/100) * utils.linewidth()
+end
+
+-- Highlighting Shortcut
+local hi_pattern = '%%#%s#%s%%*'
+
+-- Define Components
+local components = {}
+
+components.mode = function (args)
+ args = args or {}
+ local before = args.before or ""
+ local after = args.after or ""
+
+ -- Convert mode to string
+ local mode_to_str = {
+ ['n'] = 'NORMAL',
+ ['no'] = 'OP-PENDING',
+ ['nov'] = 'OP-PENDING',
+ ['noV'] = 'OP-PENDING',
+ ['no\22'] = 'OP-PENDING',
+ ['niI'] = 'NORMAL',
+ ['niR'] = 'NORMAL',
+ ['niV'] = 'NORMAL',
+ ['nt'] = 'NORMAL',
+ ['ntT'] = 'NORMAL',
+ ['v'] = 'VISUAL',
+ ['vs'] = 'VISUAL',
+ ['V'] = 'VISUAL',
+ ['Vs'] = 'VISUAL',
+ ['\22'] = 'VISUAL',
+ ['\22s'] = 'VISUAL',
+ ['s'] = 'SELECT',
+ ['S'] = 'SELECT',
+ ['\19'] = 'SELECT',
+ ['i'] = 'INSERT',
+ ['ic'] = 'INSERT',
+ ['ix'] = 'INSERT',
+ ['R'] = 'REPLACE',
+ ['Rc'] = 'REPLACE',
+ ['Rx'] = 'REPLACE',
+ ['Rv'] = 'VIRT REPLACE',
+ ['Rvc'] = 'VIRT REPLACE',
+ ['Rvx'] = 'VIRT REPLACE',
+ ['c'] = 'COMMAND',
+ ['cv'] = 'VIM EX',
+ ['ce'] = 'EX',
+ ['r'] = 'PROMPT',
+ ['rm'] = 'MORE',
+ ['r?'] = 'CONFIRM',
+ ['!'] = 'SHELL',
+ ['t'] = 'TERMINAL',
+ }
+
+ -- Get the respective string to display.
+ local mode = mode_to_str[vim.api.nvim_get_mode().mode] or 'UNKNOWN'
+
+ -- Set the highlight group and text.
+ local mode_text = "?"
+ local hl = 'DiagnosticWarn'
+
+ if mode:find 'NORMAL' then
+ hl = 'DiagnosticInfo'
+ mode_text = "N"
+ elseif mode:find 'PENDING' then
+ hl = 'DiagnosticInfo'
+ mode_text = "P"
+ elseif mode:find 'VISUAL' then
+ hl = 'DiagnosticHint'
+ mode_text = "V"
+ elseif mode:find 'REPLACE' then
+ hl = 'DiagnosticError'
+ mode_text = "R"
+ elseif mode:find 'INSERT' or mode:find 'SELECT' then
+ hl = 'DiagnosticOk'
+ mode_text = "I"
+ elseif mode:find 'COMMAND' or mode:find 'TERMINAL' or mode:find 'EX' then
+ hl = 'DiagnosticHint'
+ mode_text = "C"
+ end
+
+ -- Construct the component.
+ return hi_pattern:format(hl, string.format(before..'%s'..after, mode_text))
+end
+
+components.location = function (args)
+ args = args or {}
+ local before = args.before or ""
+ local after = args.after or ""
+
+ return before.."%(%l/%L%): %c"..after
+end
+
+components.progress = function (args)
+ args = args or {}
+ local before = args.before or ""
+ local after = args.after or ""
+
+ local sbar = { '🭶', '🭷', '🭸', '🭹', '🭺', '🭻' }
+ local curr_line = vim.api.nvim_win_get_cursor(0)[1] or 0
+ local lines = vim.api.nvim_buf_line_count(0) or 0
+ local i = math.floor((curr_line - 1) / lines * #sbar) + 1
+ -- if i == nil then return "" end
+ local prog = string.rep(sbar[i], 2)
+ return before..hi_pattern:format("Visual", prog)..after
+end
+
+components.cwd = function (args)
+ args = args or {}
+ local before = args.before or ""
+ local after = args.after or ""
+
+ local cwd = vim.fn.getcwd(0)
+ cwd = vim.fn.fnamemodify(cwd, ":~")
+ if utils.component_takes_percentage(#cwd, 40) then cwd = vim.fn.pathshorten(cwd) end
+ if utils.component_takes_percentage(#cwd, 80) then return "" end
+ local trail = cwd:sub(-1) == '/' and '' or "/"
+ return before..cwd..trail..after
+end
+
+components.diagnostics = function (args)
+ args = args or {}
+ local before = args.before or ""
+ local after = args.after or ""
+
+ -- Define icons
+ local error_icon = use_icons and " " or "E"
+ local warning_icon = use_icons and " " or "W"
+ local info_icon = use_icons and " " or "I"
+ local hint_icon = use_icons and " " or "H"
+
+ -- Create empty diagnostics table
+ local diagnostics = {}
+
+ -- Count diagnostics
+ local errors = #vim.diagnostic.get(0, { severity = 1 })
+
+ if errors > 0 then
+ table.insert(diagnostics, hi_pattern:format("DiagnosticSignError", ("%s%s"):format(error_icon, errors)))
+ end
+
+ local warnings = #vim.diagnostic.get(0, { severity = 2 })
+
+ if warnings > 0 then
+ table.insert(diagnostics, hi_pattern:format("DiagnosticSignWarn", ("%s%s"):format(warning_icon, warnings)))
+ end
+
+ local infos = #vim.diagnostic.get(0, { severity = 3 })
+
+ if infos > 0 then
+ table.insert(diagnostics, hi_pattern:format("DiagnosticSignInfo", ("%s%s"):format(info_icon, infos)))
+ end
+
+ local hints = #vim.diagnostic.get(0, { severity = 4 })
+
+ if hints > 0 then
+ table.insert(diagnostics, hi_pattern:format("DiagnosticSignHint", ("%s%s"):format(hint_icon, hints)))
+ end
+
+ -- Don't show diagnostics in insert mode.
+ if vim.api.nvim_get_mode().mode:find "i" then
+ return ""
+ end
+
+ local icon = use_icons and '' or 'diag: '
+
+ local status = hi_pattern:format("Statusline", table.concat(diagnostics, " "))
+
+ return before..icon..status..after
+end
+
+components.git_branch = function (args)
+ args = args or {}
+ local before = args.before or ""
+ local after = args.after or ""
+
+ if not vim.b.minigit_summary then return "" end
+ local branch = vim.b.minigit_summary.head_name or ""
+ local icon = use_icons and " " or "branch: "
+ return before..icon..branch..after
+end
+
+components.git_status = function (args)
+ args = args or {}
+ local before = args.before or ""
+ local after = args.after or ""
+
+ if not vim.b.minidiff_summary then return "" end
+
+ local summary = vim.b.minidiff_summary
+
+ local status = {}
+
+ local add_icon = use_icons and " " or "+"
+ local change_icon = use_icons and " " or "~"
+ local delete_icon = use_icons and " " or "-"
+
+ if (summary.add or 0) > 0 then
+ table.insert(status, hi_pattern:format("Added", ("%s%s"):format(add_icon, summary.add)))
+ end
+ if (summary.change or 0) > 0 then
+ table.insert(status, hi_pattern:format("Changed", ("%s%s"):format(change_icon, summary.change)))
+ end
+ if (summary.delete or 0) > 0 then
+ table.insert(status, hi_pattern:format("Removed", ("%s%s"):format(delete_icon, summary.delete)))
+ end
+
+ return before..table.concat(status, " ")..after
+end
+
+-- Define Statusline
+local statusline = function ()
+ return {
+ components.mode({before = " "}),
+ components.git_branch(),
+ components.git_status(),
+ components.cwd(),
+
+ "%=",
+
+ components.diagnostics(),
+ components.location({after = ""}),
+ components.progress({after = ""}),
+ }
+end
+
+-- Gaps between components.
+local gaps = " "
+
+-- Process and apply statusline.
+Statusline_builder = function ()
+ --get a table of all the statusline strings
+ local statusline_strings = statusline()
+
+ -- Remove empty strings to prevent concat issues
+ for i = #statusline_strings, 1, -1 do
+ if statusline_strings[i] == "" then
+ table.remove(statusline_strings, i)
+ end
+ end
+
+ -- Concatentate strings with gaps
+ return table.concat(statusline_strings, gaps)
+end
+
+vim.o.statusline = "%{%v:lua.Statusline_builder()%}"