aboutsummaryrefslogtreecommitdiff
path: root/.config/nvim/lua/config
diff options
context:
space:
mode:
authorMichal Hanus <mikehanus@protonmail.com>2025-12-29 19:02:55 +0100
committerMichal Hanus <mikehanus@protonmail.com>2025-12-29 19:02:55 +0100
commit5eda7770be54f222e27e87190a95847e6d0e2c8c (patch)
tree6974ac951d1f955f1a05144f1504a41fcf990251 /.config/nvim/lua/config
parent688a636a43e70da5337c8dd671d4269621fae80b (diff)
nvim setup
Diffstat (limited to '.config/nvim/lua/config')
-rw-r--r--.config/nvim/lua/config/indent-blankline.lua36
-rw-r--r--.config/nvim/lua/config/nvim-tree.lua108
-rw-r--r--.config/nvim/lua/config/statusline.lua197
3 files changed, 341 insertions, 0 deletions
diff --git a/.config/nvim/lua/config/indent-blankline.lua b/.config/nvim/lua/config/indent-blankline.lua
new file mode 100644
index 0000000..9b210d7
--- /dev/null
+++ b/.config/nvim/lua/config/indent-blankline.lua
@@ -0,0 +1,36 @@
+local api = vim.api
+
+local exclude_ft = { "help", "git", "markdown", "snippets", "text", "gitconfig", "alpha", "dashboard" }
+
+require("ibl").setup {
+ indent = {
+ -- -- U+2502 may also be a good choice, it will be on the middle of cursor.
+ -- -- U+250A is also a good choice
+ char = "▏",
+ },
+ scope = {
+ show_start = false,
+ show_end = false,
+ },
+ exclude = {
+ filetypes = exclude_ft,
+ buftypes = { "terminal" },
+ },
+}
+
+local gid = api.nvim_create_augroup("indent_blankline", { clear = true })
+api.nvim_create_autocmd("InsertEnter", {
+ pattern = "*",
+ group = gid,
+ command = "IBLDisable",
+})
+
+api.nvim_create_autocmd("InsertLeave", {
+ pattern = "*",
+ group = gid,
+ callback = function()
+ if not vim.tbl_contains(exclude_ft, vim.bo.filetype) then
+ vim.cmd([[IBLEnable]])
+ end
+ end,
+})
diff --git a/.config/nvim/lua/config/nvim-tree.lua b/.config/nvim/lua/config/nvim-tree.lua
new file mode 100644
index 0000000..6bf653d
--- /dev/null
+++ b/.config/nvim/lua/config/nvim-tree.lua
@@ -0,0 +1,108 @@
+local keymap = vim.keymap
+local nvim_tree = require("nvim-tree")
+
+nvim_tree.setup {
+ auto_reload_on_write = true,
+ disable_netrw = false,
+ hijack_netrw = true,
+ hijack_cursor = false,
+ hijack_unnamed_buffer_when_opening = false,
+ open_on_tab = false,
+ sort_by = "name",
+ update_cwd = false,
+ view = {
+ width = 30,
+ side = "left",
+ preserve_window_proportions = false,
+ number = false,
+ relativenumber = false,
+ signcolumn = "yes",
+ },
+ renderer = {
+ indent_markers = {
+ enable = false,
+ icons = {
+ corner = "└ ",
+ edge = "│ ",
+ none = " ",
+ },
+ },
+ icons = {
+ webdev_colors = true,
+ },
+ },
+ hijack_directories = {
+ enable = true,
+ auto_open = true,
+ },
+ update_focused_file = {
+ enable = false,
+ update_cwd = false,
+ ignore_list = {},
+ },
+ system_open = {
+ cmd = "",
+ args = {},
+ },
+ diagnostics = {
+ enable = false,
+ show_on_dirs = false,
+ icons = {
+ hint = "",
+ info = "",
+ warning = "",
+ error = "",
+ },
+ },
+ filters = {
+ dotfiles = false,
+ custom = {},
+ exclude = {},
+ },
+ git = {
+ enable = true,
+ ignore = true,
+ timeout = 400,
+ },
+ actions = {
+ use_system_clipboard = true,
+ change_dir = {
+ enable = true,
+ global = false,
+ restrict_above_cwd = false,
+ },
+ open_file = {
+ quit_on_open = false,
+ resize_window = false,
+ window_picker = {
+ enable = true,
+ chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890",
+ exclude = {
+ filetype = { "notify", "qf", "diff", "fugitive", "fugitiveblame" },
+ buftype = { "nofile", "terminal", "help" },
+ },
+ },
+ },
+ },
+ trash = {
+ cmd = "trash",
+ require_confirm = true,
+ },
+ log = {
+ enable = false,
+ truncate = false,
+ types = {
+ all = false,
+ config = false,
+ copy_paste = false,
+ diagnostics = false,
+ git = false,
+ profile = false,
+ },
+ },
+}
+
+keymap.set("n", "<space>s", require("nvim-tree.api").tree.toggle, {
+ silent = true,
+ desc = "toggle nvim-tree",
+})
diff --git a/.config/nvim/lua/config/statusline.lua b/.config/nvim/lua/config/statusline.lua
new file mode 100644
index 0000000..0563ba6
--- /dev/null
+++ b/.config/nvim/lua/config/statusline.lua
@@ -0,0 +1,197 @@
+local fn = vim.fn
+
+local function spell()
+ if vim.o.spell then
+ return string.format("[SPELL]")
+ end
+
+ return ""
+end
+
+--- show indicator for Chinese IME
+local function ime_state()
+ if vim.g.is_mac then
+ -- ref: https://github.com/vim-airline/vim-airline/blob/master/autoload/airline/extensions/xkblayout.vim#L11
+ local layout = fn.libcall(vim.g.XkbSwitchLib, "Xkb_Switch_getXkbLayout", "")
+
+ -- We can use `xkbswitch -g` on the command line to get current mode.
+ -- mode for macOS builtin pinyin IME: com.apple.inputmethod.SCIM.ITABC
+ -- mode for Rime: im.rime.inputmethod.Squirrel.Rime
+ local res = fn.match(layout, [[\v(Squirrel\.Rime|SCIM.ITABC)]])
+ if res ~= -1 then
+ return "[CN]"
+ end
+ end
+
+ return ""
+end
+
+local function trailing_space()
+ if not vim.o.modifiable then
+ return ""
+ end
+
+ local line_num = nil
+
+ for i = 1, fn.line("$") do
+ local linetext = fn.getline(i)
+ -- To prevent invalid escape error, we wrap the regex string with `[[]]`.
+ local idx = fn.match(linetext, [[\v\s+$]])
+
+ if idx ~= -1 then
+ line_num = i
+ break
+ end
+ end
+
+ local msg = ""
+ if line_num ~= nil then
+ msg = string.format("[%d]trailing", line_num)
+ end
+
+ return msg
+end
+
+local function mixed_indent()
+ if not vim.o.modifiable then
+ return ""
+ end
+
+ local space_pat = [[\v^ +]]
+ local tab_pat = [[\v^\t+]]
+ local space_indent = fn.search(space_pat, "nwc")
+ local tab_indent = fn.search(tab_pat, "nwc")
+ local mixed = (space_indent > 0 and tab_indent > 0)
+ local mixed_same_line
+ if not mixed then
+ mixed_same_line = fn.search([[\v^(\t+ | +\t)]], "nwc")
+ mixed = mixed_same_line > 0
+ end
+ if not mixed then
+ return ""
+ end
+ if mixed_same_line ~= nil and mixed_same_line > 0 then
+ return "MI:" .. mixed_same_line
+ end
+ local space_indent_cnt = fn.searchcount({ pattern = space_pat, max_count = 1e3 }).total
+ local tab_indent_cnt = fn.searchcount({ pattern = tab_pat, max_count = 1e3 }).total
+ if space_indent_cnt > tab_indent_cnt then
+ return "MI:" .. tab_indent
+ else
+ return "MI:" .. space_indent
+ end
+end
+
+local diff = function()
+ local git_status = vim.b.gitsigns_status_dict
+ if git_status == nil then
+ return
+ end
+
+ local modify_num = git_status.changed
+ local remove_num = git_status.removed
+ local add_num = git_status.added
+
+ local info = { added = add_num, modified = modify_num, removed = remove_num }
+ -- vim.print(info)
+ return info
+end
+
+local virtual_env = function()
+ -- only show virtual env for Python
+ if vim.bo.filetype ~= 'python' then
+ return ""
+ end
+
+ local conda_env = os.getenv('CONDA_DEFAULT_ENV')
+ local venv_path = os.getenv('VIRTUAL_ENV')
+
+ if venv_path == nil then
+ if conda_env == nil then
+ return ""
+ else
+ return string.format(" %s (conda)", conda_env)
+ end
+ else
+ local venv_name = vim.fn.fnamemodify(venv_path, ':t')
+ return string.format(" %s (venv)", venv_name)
+ end
+end
+
+require("lualine").setup {
+ options = {
+ icons_enabled = true,
+ theme = "auto",
+ -- component_separators = { left = "", right = "" },
+ -- section_separators = { left = "", right = "" },
+ section_separators = "",
+ component_separators = "",
+ disabled_filetypes = {},
+ always_divide_middle = true,
+ },
+ sections = {
+ lualine_a = { "mode" },
+ lualine_b = {
+ "branch",
+ {
+ "diff",
+ source = diff,
+ },
+ {
+ virtual_env,
+ color = { fg = 'black', bg = "#F1CA81" }
+ }
+ },
+ lualine_c = {
+ "filename",
+ {
+ ime_state,
+ color = { fg = "black", bg = "#f46868" },
+ },
+ {
+ spell,
+ color = { fg = "black", bg = "#a7c080" },
+ },
+ {
+ "diagnostics",
+ sources = { "nvim_diagnostic" },
+ symbols = {error = '🆇 ', warn = '⚠️ ', info = 'ℹ️ ', hint = ' '},
+ },
+ },
+ lualine_x = {
+ "encoding",
+ {
+ "fileformat",
+ symbols = {
+ unix = "unix",
+ dos = "win",
+ mac = "mac",
+ },
+ },
+ "filetype",
+ },
+ lualine_y = {
+ "location",
+ },
+ lualine_z = {
+ {
+ trailing_space,
+ color = "WarningMsg",
+ },
+ {
+ mixed_indent,
+ color = "WarningMsg",
+ },
+ },
+ },
+ inactive_sections = {
+ lualine_a = {},
+ lualine_b = {},
+ lualine_c = { "filename" },
+ lualine_x = { "location" },
+ lualine_y = {},
+ lualine_z = {},
+ },
+ tabline = {},
+ extensions = { "quickfix", "fugitive", "nvim-tree" },
+}