diff options
author | Gustaf Rydholm <gustaf.rydholm@gmail.com> | 2021-08-10 23:15:04 +0200 |
---|---|---|
committer | Gustaf Rydholm <gustaf.rydholm@gmail.com> | 2021-08-10 23:15:04 +0200 |
commit | 540268d618627079c9b958a955b586e1888b46a8 (patch) | |
tree | 1a22a5feb457135178b9d4fe8b6c1755f5ca66bc /.config/nvim/lua/core | |
parent | e79bd3273f58ba38e8fcd716090b89326791afbb (diff) |
Major refactor of nvim
Diffstat (limited to '.config/nvim/lua/core')
22 files changed, 638 insertions, 426 deletions
diff --git a/.config/nvim/lua/core/autocmds.lua b/.config/nvim/lua/core/autocmds.lua new file mode 100644 index 0000000..959ae15 --- /dev/null +++ b/.config/nvim/lua/core/autocmds.lua @@ -0,0 +1,114 @@ +local autocommands = {} + +options.autocommands = { + _general_settings = { + { + "Filetype", + "*", + "lua require('utils.ft').do_filetype(vim.fn.expand(\"<amatch>\"))", + }, + { + "TextYankPost", + "*", + "lua require('vim.highlight').on_yank({higroup = 'Search', timeout = 200})", + }, + { + "BufWinEnter", + "*", + "setlocal formatoptions-=c formatoptions-=r formatoptions-=o", + }, + { + "BufWinEnter", + "dashboard", + "setlocal cursorline signcolumn=yes cursorcolumn number", + }, + { + "BufRead", + "*", + "setlocal formatoptions-=c formatoptions-=r formatoptions-=o", + }, + { + "BufNewFile", + "*", + "setlocal formatoptions-=c formatoptions-=r formatoptions-=o", + }, + { "BufWritePost", USER_CONFIG_PATH, "lua require('utils').reload_config()" }, + { + "FileType", + "qf", + "set nobuflisted", + }, + -- { "VimLeavePre", "*", "set title set titleold=" }, + }, + _filetypechanges = { + { "BufWinEnter", ".tf", "setlocal filetype=terraform" }, + { "BufRead", "*.tf", "setlocal filetype=terraform" }, + { "BufNewFile", "*.tf", "setlocal filetype=terraform" }, + { "BufWinEnter", ".zsh", "setlocal filetype=sh" }, + { "BufRead", "*.zsh", "setlocal filetype=sh" }, + { "BufNewFile", "*.zsh", "setlocal filetype=sh" }, + }, + -- _solidity = { + -- {'BufWinEnter', '.sol', 'setlocal filetype=solidity'}, {'BufRead', '*.sol', 'setlocal filetype=solidity'}, + -- {'BufNewFile', '*.sol', 'setlocal filetype=solidity'} + -- }, + -- _gemini = { + -- {'BufWinEnter', '.gmi', 'setlocal filetype=markdown'}, {'BufRead', '*.gmi', 'setlocal filetype=markdown'}, + -- {'BufNewFile', '*.gmi', 'setlocal filetype=markdown'} + -- }, + _markdown = { + { "FileType", "markdown", "setlocal wrap" }, + { "FileType", "markdown", "setlocal spell" }, + }, + _buffer_bindings = { + { "FileType", "floaterm", "nnoremap <silent> <buffer> q :q<CR>" }, + }, + _auto_resize = { + -- will cause split windows to be resized evenly if main window is resized + { "VimResized", "*", "wincmd =" }, + }, + _packer_compile = { + -- will run PackerCompile after writing plugins.lua + { "BufWritePost", "plugins.lua", "PackerCompile" }, + }, + _general_lsp = { + { "FileType", "lspinfo", "nnoremap <silent> <buffer> q :q<CR>" }, + }, + + -- _fterm_lazygit = { + -- -- will cause esc key to exit lazy git + -- {"TermEnter", "*", "call LazyGitNativation()"} + -- }, + -- _mode_switching = { + -- -- will switch between absolute and relative line numbers depending on mode + -- {'InsertEnter', '*', 'if &relativenumber | let g:ms_relativenumberoff = 1 | setlocal number norelativenumber | endif'}, + -- {'InsertLeave', '*', 'if exists("g:ms_relativenumberoff") | setlocal relativenumber | endif'}, + -- {'InsertEnter', '*', 'if &cursorline | let g:ms_cursorlineoff = 1 | setlocal nocursorline | endif'}, + -- {'InsertLeave', '*', 'if exists("g:ms_cursorlineoff") | setlocal cursorline | endif'}, + -- }, + custom_groups = {}, +} + +function autocommands.define_augroups(definitions) -- {{{1 + -- Create autocommand groups based on the passed definitions + -- + -- The key will be the name of the group, and each definition + -- within the group should have: + -- 1. Trigger + -- 2. Pattern + -- 3. Text + -- just like how they would normally be defined from Vim itself + for group_name, definition in pairs(definitions) do + vim.cmd("augroup " .. group_name) + vim.cmd "autocmd!" + + for _, def in pairs(definition) do + local command = table.concat(vim.tbl_flatten { "autocmd", def }, " ") + vim.cmd(command) + end + + vim.cmd "augroup END" + end +end + +return autocommands diff --git a/.config/nvim/lua/core/autopairs.lua b/.config/nvim/lua/core/autopairs.lua index f0111db..afd6e28 100644 --- a/.config/nvim/lua/core/autopairs.lua +++ b/.config/nvim/lua/core/autopairs.lua @@ -1,8 +1,10 @@ -- if not package.loaded['nvim-autopairs'] then -- return -- end +local Log = require "core.log" local status_ok, _ = pcall(require, "nvim-autopairs") if not status_ok then + Log:get_default().error "Failed to load autopairs" return end local npairs = require "nvim-autopairs" diff --git a/.config/nvim/lua/core/bufferline.lua b/.config/nvim/lua/core/bufferline.lua index d4e4b4f..6306614 100644 --- a/.config/nvim/lua/core/bufferline.lua +++ b/.config/nvim/lua/core/bufferline.lua @@ -1,28 +1,20 @@ -vim.api.nvim_set_keymap("n", "<S-x>", ":BufferClose<CR>", { noremap = true, silent = true }) -vim.api.nvim_set_keymap("n", "<S-l>", ":BufferNext<CR>", { noremap = true, silent = true }) -vim.api.nvim_set_keymap("n", "<S-h>", ":BufferPrevious<CR>", { noremap = true, silent = true }) -vim.api.nvim_set_keymap("n", "<leader>c", ":BufferClose<CR>", { noremap = true, silent = true }) +local M = {} -O.plugin.which_key.mappings["b"] = { - name = "Buffers", - j = { "<cmd>BufferPick<cr>", "jump to buffer" }, - f = { "<cmd>Telescope buffers<cr>", "Find buffer" }, - w = { "<cmd>BufferWipeout<cr>", "wipeout buffer" }, - e = { - "<cmd>BufferCloseAllButCurrent<cr>", - "close all but current buffer", - }, - h = { "<cmd>BufferCloseBuffersLeft<cr>", "close all buffers to the left" }, - l = { - "<cmd>BufferCloseBuffersRight<cr>", - "close all BufferLines to the right", - }, - D = { - "<cmd>BufferOrderByDirectory<cr>", - "sort BufferLines automatically by directory", - }, - L = { - "<cmd>BufferOrderByLanguage<cr>", - "sort BufferLines automatically by language", - }, -} +M.config = function() + options.builtin.bufferline = { + active = true, + keymap = { + normal_mode = { + ["<S-l>"] = ":BufferNext<CR>", + ["<S-h>"] = ":BufferPrevious<CR>", + }, + }, + } +end + +M.setup = function() + local keymap = require "keymappings" + keymap.append_to_defaults(options.builtin.bufferline.keymap) +end + +return M diff --git a/.config/nvim/lua/core/colorizer.lua b/.config/nvim/lua/core/colorizer.lua deleted file mode 100644 index c6a2a27..0000000 --- a/.config/nvim/lua/core/colorizer.lua +++ /dev/null @@ -1,17 +0,0 @@ -local M = {} - -M.config = function() - O.plugin.hop = { - active = false, - } -end - -M.setup = function() - local status_ok, colorizer = pcall(require, "colorizer") - if not status_ok then - return - end - colorizer.setup(O.plugin.hop) -end - -return M diff --git a/.config/nvim/lua/core/commands.lua b/.config/nvim/lua/core/commands.lua new file mode 100644 index 0000000..c42b385 --- /dev/null +++ b/.config/nvim/lua/core/commands.lua @@ -0,0 +1,21 @@ +local M = {} + +M.defaults = { + [[ + function! QuickFixToggle() + if empty(filter(getwininfo(), 'v:val.quickfix')) + copen + else + cclose + endif + endfunction + ]], +} + +M.load = function(commands) + for _, command in ipairs(commands) do + vim.cmd(command) + end +end + +return M diff --git a/.config/nvim/lua/core/compe.lua b/.config/nvim/lua/core/compe.lua index c8152ad..3291918 100644 --- a/.config/nvim/lua/core/compe.lua +++ b/.config/nvim/lua/core/compe.lua @@ -1,6 +1,7 @@ local M = {} +local Log = require "core.log" M.config = function() - O.completion = { + options.builtin.compe = { enabled = true, autocomplete = true, debug = false, @@ -12,7 +13,15 @@ M.config = function() max_abbr_width = 100, max_kind_width = 100, max_menu_width = 100, - documentation = true, + documentation = { + border = "single", + winhighlight = "NormalFloat:CompeDocumentation,FloatBorder:CompeDocumentationBorder", + max_width = 120, + min_width = 60, + max_height = math.floor(vim.o.lines * 0.3), + min_height = 1, + }, + -- documentation = true, source = { path = { kind = " (Path)" }, @@ -30,18 +39,35 @@ M.config = function() emoji = { kind = " ﲃ (Emoji)", filetypes = { "markdown", "text" } }, -- for emoji press : (idk if that in compe tho) }, + + keymap = { + values = { + insert_mode = { + -- ["<Tab>"] = { 'pumvisible() ? "<C-n>" : "<Tab>"', { silent = true, noremap = true, expr = true } }, + -- ["<S-Tab>"] = { 'pumvisible() ? "<C-p>" : "<S-Tab>"', { silent = true, noremap = true, expr = true } }, + ["<C-Space>"] = { "compe#complete()", { silent = true, noremap = true, expr = true } }, + ["<C-e>"] = { "compe#close('<C-e>')", { silent = true, noremap = true, expr = true } }, + ["<C-f>"] = { "compe#scroll({ 'delta': +4 })", { silent = true, noremap = true, expr = true } }, + ["<C-d>"] = { "compe#scroll({ 'delta': -4 })", { silent = true, noremap = true, expr = true } }, + }, + }, + opts = { + insert_mode = { noremap = true, silent = true, expr = true }, + }, + }, } end M.setup = function() - vim.g.vsnip_snippet_dir = O.vsnip_dir + vim.g.vsnip_snippet_dir = options.vsnip_dir local status_ok, compe = pcall(require, "compe") if not status_ok then + Log:get_default().error "Failed to load compe" return end - compe.setup(O.completion) + compe.setup(options.builtin.compe) local t = function(str) return vim.api.nvim_replace_termcodes(str, true, true, true) @@ -62,12 +88,13 @@ M.setup = function() _G.tab_complete = function() if vim.fn.pumvisible() == 1 then return t "<C-n>" - elseif vim.fn.call("vsnip#available", { 1 }) == 1 then - return t "<Plug>(vsnip-expand-or-jump)" + elseif vim.fn.call("vsnip#jumpable", { 1 }) == 1 then + return t "<Plug>(vsnip-jump-next)" elseif check_back_space() then return t "<Tab>" else - return vim.fn["compe#complete"]() + -- return vim.fn["compe#complete"]() -- < use this if you want <tab> to always offer completion + return t "<Tab>" end end @@ -81,16 +108,13 @@ M.setup = function() end end + local keymap = require "keymappings" + keymap.load(options.builtin.compe.keymap.values, options.builtin.compe.keymap.opts) + vim.api.nvim_set_keymap("i", "<Tab>", "v:lua.tab_complete()", { expr = true }) vim.api.nvim_set_keymap("s", "<Tab>", "v:lua.tab_complete()", { expr = true }) vim.api.nvim_set_keymap("i", "<S-Tab>", "v:lua.s_tab_complete()", { expr = true }) vim.api.nvim_set_keymap("s", "<S-Tab>", "v:lua.s_tab_complete()", { expr = true }) - - vim.api.nvim_set_keymap("i", "<C-Space>", "compe#complete()", { noremap = true, silent = true, expr = true }) - vim.api.nvim_set_keymap("i", "<CR>", "compe#confirm('<CR>')", { noremap = true, silent = true, expr = true }) - vim.api.nvim_set_keymap("i", "<C-e>", "compe#close('<C-e>')", { noremap = true, silent = true, expr = true }) - vim.api.nvim_set_keymap("i", "<C-f>", "compe#scroll({ 'delta': +4 })", { noremap = true, silent = true, expr = true }) - vim.api.nvim_set_keymap("i", "<C-d>", "compe#scroll({ 'delta': -4 })", { noremap = true, silent = true, expr = true }) end return M diff --git a/.config/nvim/lua/core/dap.lua b/.config/nvim/lua/core/dap.lua index bc76e22..a325c7c 100644 --- a/.config/nvim/lua/core/dap.lua +++ b/.config/nvim/lua/core/dap.lua @@ -1,6 +1,7 @@ local M = {} +local Log = require "core.log" M.config = function() - O.plugin.dap = { + options.builtin.dap = { active = false, breakpoint = { text = "", @@ -14,13 +15,14 @@ end M.setup = function() local status_ok, dap = pcall(require, "dap") if not status_ok then + Log:get_default().error "Failed to load dap" return end - vim.fn.sign_define("DapBreakpoint", O.plugin.dap.breakpoint) + vim.fn.sign_define("DapBreakpoint", options.builtin.dap.breakpoint) dap.defaults.fallback.terminal_win_cmd = "50vsplit new" - O.user_which_key["d"] = { + options.builtin.which_key.mappings["d"] = { name = "Debug", t = { "<cmd>lua require'dap'.toggle_breakpoint()<cr>", "Toggle Breakpoint" }, b = { "<cmd>lua require'dap'.step_back()<cr>", "Step Back" }, @@ -34,7 +36,7 @@ M.setup = function() p = { "<cmd>lua require'dap'.pause.toggle()<cr>", "Pause" }, r = { "<cmd>lua require'dap'.repl.toggle()<cr>", "Toggle Repl" }, s = { "<cmd>lua require'dap'.continue()<cr>", "Start" }, - q = { "<cmd>lua require'dap'.stop()<cr>", "Quit" }, + q = { "<cmd>lua require'dap'.close()<cr>", "Quit" }, } end diff --git a/.config/nvim/lua/core/dashboard.lua b/.config/nvim/lua/core/dashboard.lua index 4c7ecc3..c868540 100644 --- a/.config/nvim/lua/core/dashboard.lua +++ b/.config/nvim/lua/core/dashboard.lua @@ -1,6 +1,6 @@ local M = {} M.config = function() - O.plugin.dashboard = { + options.builtin.dashboard = { active = false, search_handler = "telescope", custom_header = { @@ -49,26 +49,26 @@ end M.setup = function() vim.g.dashboard_disable_at_vimenter = 0 - vim.g.dashboard_custom_header = O.plugin.dashboard.custom_header + vim.g.dashboard_custom_header = options.builtin.dashboard.custom_header - vim.g.dashboard_default_executive = O.plugin.dashboard.search_handler + vim.g.dashboard_default_executive = options.builtin.dashboard.search_handler - vim.g.dashboard_custom_section = O.plugin.dashboard.custom_section + vim.g.dashboard_custom_section = options.builtin.dashboard.custom_section - O.plugin.which_key.mappings[";"] = { "<cmd>Dashboard<CR>", "Dashboard" } + options.builtin.which_key.mappings[";"] = { "<cmd>Dashboard<CR>", "Dashboard" } -- f = { -- description = { " Neovim Config Files" }, - -- command = "Telescope find_files cwd=" .. CONFIG_PATH, + -- command = "Telescope find_files cwd=" .. CoptionsFIG_PATH, -- }, -- e = {description = {' Marks '}, command = 'Telescope marks'} - vim.cmd "let g:dashboard_session_directory = $HOME..'/.config/nvim/.sessions'" + vim.cmd "let g:dashboard_session_directory = $HoptionsE..'/.config/nvim/.sessions'" vim.cmd "let packages = len(globpath('~/.local/share/nvim/site/pack/packer/start', '*', 0, 1))" vim.api.nvim_exec( [[ - let g:dashboard_custom_footer = ['LuaJIT loaded '..packages..' plugins'] + let g:dashboard_custom_footer = ['LuaJIT loaded '..packages..' builtins'] ]], false ) @@ -76,10 +76,10 @@ M.setup = function() -- file_browser = {description = {' File Browser'}, command = 'Telescope find_files'}, -- vim.g.dashboard_session_directory = CACHE_PATH..'/session' - -- vim.g.dashboard_custom_footer = O.dashboard.footer - require("utils").define_augroups { + -- vim.g.dashboard_custom_footer = optionsdashboard.footer + require("core.autocmds").define_augroups { _dashboard = { - -- seems to be nobuflisted that makes my stuff disapear will do more testing + -- seems to be nobuflisted that makes my stuff disappear will do more testing { "FileType", "dashboard", @@ -88,7 +88,7 @@ M.setup = function() { "FileType", "dashboard", - "set showtabline=0 | autocmd BufLeave <buffer> set showtabline=" .. O.default_options.showtabline, + "set showtabline=0 | autocmd BufLeave <buffer> set showtabline=" .. vim.opt.showtabline._value, }, { "FileType", "dashboard", "nnoremap <silent> <buffer> q :q<CR>" }, }, diff --git a/.config/nvim/lua/core/formatter.lua b/.config/nvim/lua/core/formatter.lua deleted file mode 100644 index 04c078a..0000000 --- a/.config/nvim/lua/core/formatter.lua +++ /dev/null @@ -1,60 +0,0 @@ --- autoformat -if O.format_on_save then - require("utils").define_augroups { - autoformat = { - { - "BufWritePost", - "*", - ":silent FormatWrite", - }, - }, - } -end - --- -- check if formatter has been defined for the language or not --- local function formatter_exists(lang_formatter) --- if lang_formatter == nil then --- return false --- end --- if lang_formatter.exe == nil or lang_formatter.args == nil then --- return false --- end --- return true --- end - --- returns default formatter for given language --- local function formatter_return(lang_formatter) --- return { --- exe = lang_formatter.exe, --- args = lang_formatter.args, --- stdin = not (lang_formatter.stdin ~= nil), --- } --- end - --- fill a table like this -> {rust: {exe:"sth",args:{"a","b"},stdin=true},go: {}...} --- local formatter_filetypes = {} --- for k, v in pairs(O.lang) do --- if formatter_exists(v.formatter) then --- local keys = v.filetypes --- if keys == nil then --- keys = { k } --- end --- for _, l in pairs(keys) do --- formatter_filetypes[l] = { --- function() --- return formatter_return(v.formatter) --- end, --- } --- end --- end --- end -local status_ok, _ = pcall(require, "formatter") -if not status_ok then - return -end - -if not O.format_on_save then - vim.cmd [[if exists('#autoformat#BufWritePost') - :autocmd! autoformat - endif]] -end diff --git a/.config/nvim/lua/core/galaxyline.lua b/.config/nvim/lua/core/galaxyline.lua index 1f9f781..ff8c59a 100644 --- a/.config/nvim/lua/core/galaxyline.lua +++ b/.config/nvim/lua/core/galaxyline.lua @@ -1,15 +1,17 @@ -- if not package.loaded['galaxyline'] then -- return -- end +local Log = require "core.log" local status_ok, gl = pcall(require, "galaxyline") if not status_ok then + Log:get_default().error "Failed to load galaxyline" return end -- NOTE: if someone defines colors but doesn't have them then this will break -local palette_status_ok, colors = pcall(require, O.colorscheme .. ".palette") +local palette_status_ok, colors = pcall(require, options.colorscheme .. ".palette") if not palette_status_ok then - colors = O.plugin.galaxyline.colors + colors = options.builtin.galaxyline.colors end local condition = require "galaxyline.condition" @@ -189,39 +191,27 @@ table.insert(gls.right, { }, }) -local get_lsp_client = function(msg) +local function get_attached_provider_name(msg) msg = msg or "LSP Inactive" - local buf_ft = vim.api.nvim_buf_get_option(0, "filetype") - local clients = vim.lsp.get_active_clients() - if next(clients) == nil then + local buf_clients = vim.lsp.buf_get_clients() + if next(buf_clients) == nil then return msg end - local lsps = "" - for _, client in ipairs(clients) do - local filetypes = client.config.filetypes - if filetypes and vim.fn.index(filetypes, buf_ft) ~= -1 then - -- print(client.name) - if lsps == "" then - -- print("first", lsps) - lsps = client.name - else - if not string.find(lsps, client.name) then - lsps = lsps .. ", " .. client.name - end - -- print("more", lsps) - end + local buf_ft = vim.bo.filetype + local buf_client_names = {} + local null_ls_providers = require("lsp.null-ls").get_registered_providers_by_filetype(buf_ft) + for _, client in pairs(buf_clients) do + if client.name ~= "null-ls" then + table.insert(buf_client_names, client.name) end end - if lsps == "" then - return msg - else - return lsps - end + vim.list_extend(buf_client_names, null_ls_providers) + return table.concat(buf_client_names, ", ") end table.insert(gls.right, { ShowLspClient = { - provider = get_lsp_client, + provider = get_attached_provider_name, condition = function() local tbl = { ["dashboard"] = true, [" "] = true } if tbl[vim.bo.filetype] then @@ -255,7 +245,11 @@ table.insert(gls.right, { table.insert(gls.right, { Tabstop = { provider = function() - return "Spaces: " .. vim.api.nvim_buf_get_option(0, "shiftwidth") .. " " + local label = "Spaces: " + if not vim.api.nvim_buf_get_option(0, "expandtab") then + label = "Tab size: " + end + return label .. vim.api.nvim_buf_get_option(0, "shiftwidth") .. " " end, condition = condition.hide_in_width, separator = " ", @@ -311,5 +305,3 @@ table.insert(gls.short_line_left, { highlight = { colors.alt_bg, colors.alt_bg }, }, }) - ---table.insert(gls.short_line_right[1] = {BufferIcon = {provider = 'BufferIcon', highlight = {colors.grey, colors.alt_bg}}}) diff --git a/.config/nvim/lua/core/gitsigns.lua b/.config/nvim/lua/core/gitsigns.lua index bc310ad..0b72689 100644 --- a/.config/nvim/lua/core/gitsigns.lua +++ b/.config/nvim/lua/core/gitsigns.lua @@ -1,6 +1,7 @@ local M = {} +local Log = require "core.log" M.config = function() - O.plugin.gitsigns = { + options.builtin.gitsigns = { signs = { add = { hl = "GitSignsAdd", @@ -44,16 +45,16 @@ M.config = function() sign_priority = 6, update_debounce = 200, status_formatter = nil, -- Use default - use_decoration_api = false, } end M.setup = function() local status_ok, gitsigns = pcall(require, "gitsigns") if not status_ok then + Log:get_default().error "Failed to load gitsigns" return end - gitsigns.setup(O.plugin.gitsigns) + gitsigns.setup(options.builtin.gitsigns) end return M diff --git a/.config/nvim/lua/core/hop.lua b/.config/nvim/lua/core/hop.lua deleted file mode 100644 index d3dd90d..0000000 --- a/.config/nvim/lua/core/hop.lua +++ /dev/null @@ -1,20 +0,0 @@ -vim.api.nvim_set_keymap('n', 's', ":HopChar2<cr>", { noremap = true, silent = true }) -vim.api.nvim_set_keymap('n', 'S', ":HopWord<cr>", { noremap = true, silent = true }) - -local M = {} - -M.config = function() - O.plugin.hop = { - active = false, - } -end - -M.setup = function() - local status_ok, hop = pcall(require, "hop") - if not status_ok then - return - end - hop.setup(O.plugin.hop) -end - -return M diff --git a/.config/nvim/lua/core/info.lua b/.config/nvim/lua/core/info.lua new file mode 100644 index 0000000..c9d34ce --- /dev/null +++ b/.config/nvim/lua/core/info.lua @@ -0,0 +1,180 @@ +local M = {} +local u = require "utils" +local null_ls_handler = require "lsp.null-ls" +local indent = " " + +M.banner = { + "", + "", + " ⠀⠀⠀ ⠀⠀ ⣺⡿⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀", + " ⣿⣯ ⣿⡟⠀ ⣤⣤⠀⠀⠀⠀⣠⣤⣤⣤⣄⣤⣤", + "⠀⣿⣿⠀⣰⡟⠀⠀⠀⠀⠀⢸⣿⠀⠀⠀⠀⣿⡟⢸⣿⡇⢀⣿", + "⠀⢻⣿⢰⣿⠀⠀⠀⠀⠀⠀⣾⡇⠀⠀⠀⢸⣿⠇⢸⣿⠀⢸⡏", + "⠀⢸⣿⣿⠋⠀⠀⠀⢠⣤⣤⣿⣥⣤⡄⠀⣼⣿⠀⣸⡏⠀⣿⠃", + "⠀⠈⠉⠉⠀⠀⠀⠀⠈⠉⠉⠉⠉⠉⠁⠀⠉⠁⠀⠉⠁⠀⠉⠀", + "", + "", +} + +local function str_list(list) + return "[ " .. table.concat(list, ", ") .. " ]" +end + +local function get_formatter_suggestion_msg(ft) + local supported_formatters = u.get_supported_formatters_by_filetype(ft) + return { + "-------------------------------------------------------------------", + "", + " HINT ", + "", + indent .. "* List of supported formatters: " .. str_list(supported_formatters), + "", + indent .. "You can enable a supported formatter by adding this to your config.lua", + "", + indent + .. "options.lang." + .. tostring(ft) + .. [[.formatting = { { exe = ']] + .. table.concat(supported_formatters, "|") + .. [[' } }]], + "", + "-------------------------------------------------------------------", + } +end + +local function get_linter_suggestion_msg(ft) + local supported_linters = u.get_supported_linters_by_filetype(ft) + return { + "-------------------------------------------------------------------", + "", + " HINT ", + "", + indent .. "* List of supported linters: " .. str_list(supported_linters), + "", + indent .. "You can enable a supported linter by adding this to your config.lua", + "", + indent + .. "options.lang." + .. tostring(ft) + .. [[.linters = { { exe = ']] + .. table.concat(supported_linters, "|") + .. [[' } }]], + "", + "-------------------------------------------------------------------", + } +end + +---creates an average size popup +---@param buf_lines a list of lines to print +---@param callback could be used to set syntax highlighting rules for example +---@return bufnr buffer number of the created buffer +---@return win_id window ID of the created popup +function M.create_simple_popup(buf_lines, callback) + -- runtime/lua/vim/lsp/util.lua + local bufnr = vim.api.nvim_create_buf(false, true) + local height_percentage = 0.7 + local width_percentage = 0.8 + local row_start_percentage = (1 - height_percentage) / 2 + local col_start_percentage = (1 - width_percentage) / 2 + local opts = {} + opts.relative = "editor" + opts.height = math.ceil(vim.o.lines * height_percentage) + opts.row = math.ceil(vim.o.lines * row_start_percentage) + opts.col = math.floor(vim.o.columns * col_start_percentage) + opts.width = math.floor(vim.o.columns * width_percentage) + opts.border = { + "┌", + "-", + "┐", + "|", + "┘", + "-", + "└", + "|", + } + + local win_id = vim.api.nvim_open_win(bufnr, true, opts) + + vim.api.nvim_win_set_buf(win_id, bufnr) + -- this needs to be window option! + vim.api.nvim_win_set_option(win_id, "number", false) + vim.cmd "setlocal nocursorcolumn" + vim.cmd "setlocal wrap" + -- set buffer options + vim.api.nvim_buf_set_option(bufnr, "filetype", "lspinfo") + vim.lsp.util.close_preview_autocmd({ "BufHidden", "BufLeave" }, win_id) + buf_lines = vim.lsp.util._trim(buf_lines, {}) + vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, buf_lines) + vim.api.nvim_buf_set_option(bufnr, "modifiable", false) + if type(callback) == "function" then + callback() + end + return bufnr, win_id +end + +function M.toggle_popup(ft) + local client = u.get_active_client_by_ft(ft) + local is_client_active = not client.is_stopped() + local client_enabled_caps = require("lsp").get_ls_capabilities(client.id) + local num_caps = vim.tbl_count(client_enabled_caps) + local null_ls_providers = null_ls_handler.get_registered_providers_by_filetype(ft) + + local missing_linters = options.lang[ft].linters._failed_requests or {} + local missing_formatters = options.lang[ft].formatters._failed_requests or {} + + local buf_lines = {} + vim.list_extend(buf_lines, M.banner) + + local header = { + "Detected filetype is: " .. tostring(ft), + "", + "Treesitter active: " .. tostring(next(vim.treesitter.highlighter.active) ~= nil), + "", + "", + } + vim.list_extend(buf_lines, header) + + local lsp_info = { + "Associated language-server: " .. client.name, + indent .. "* Active: " .. tostring(is_client_active) .. ", id: " .. tostring(client.id), + indent .. "* Formatting support: " .. tostring(client.resolved_capabilities.document_formatting), + indent .. "* Capabilities list: " .. table.concat(vim.list_slice(client_enabled_caps, 1, num_caps / 2), ", "), + indent .. indent .. indent .. table.concat(vim.list_slice(client_enabled_caps, ((num_caps / 2) + 1)), ", "), + "", + } + vim.list_extend(buf_lines, lsp_info) + + local null_ls_info = { + "Configured providers: " .. table.concat(null_ls_providers, " , ") .. " ", + "", + } + vim.list_extend(buf_lines, null_ls_info) + + local missing_formatters_status + if vim.tbl_count(missing_formatters) > 0 then + missing_formatters_status = { "Missing formatters: " .. table.concat(missing_formatters, " , ") .. " ", "" } + vim.list_extend(buf_lines, missing_formatters_status) + end + + local missing_linters_status + if vim.tbl_count(missing_linters) > 0 then + missing_linters_status = { "Missing linters: " .. table.concat(missing_linters, " , ") .. " ", "" } + vim.list_extend(buf_lines, missing_linters_status) + end + + vim.list_extend(buf_lines, get_formatter_suggestion_msg(ft)) + + vim.list_extend(buf_lines, get_linter_suggestion_msg(ft)) + + local function set_syntax_hl() + --TODO: highlighting is either inconsistent or not working :\ + vim.cmd("syntax match Identifier /filetype is: .*\\zs\\<" .. ft .. "\\>/") + vim.cmd("syntax match Identifier /server: .*\\zs\\<" .. client.name .. "\\>/") + vim.cmd("syntax match Identifier /providers: .*\\zs\\<" .. table.concat(null_ls_providers, ", ") .. "\\>/") + vim.cmd("syntax match Identifier /formatters: .*\\zs\\<" .. table.concat(missing_formatters, ", ") .. "\\>/") + vim.cmd("syntax match Identifier /linters: .*\\zs\\<" .. table.concat(missing_linters, ", ") .. "\\>/") + end + + return M.create_simple_popup(buf_lines, set_syntax_hl) +end +return M diff --git a/.config/nvim/lua/core/linter.lua b/.config/nvim/lua/core/linter.lua deleted file mode 100644 index 94dff93..0000000 --- a/.config/nvim/lua/core/linter.lua +++ /dev/null @@ -1,33 +0,0 @@ -local M = {} - -M.setup = function() - if O.lint_on_save then - require("utils").define_augroups { - autolint = { - { - "BufWritePost", - "<buffer>", - ":silent lua require('lint').try_lint()", - }, - { - "BufEnter", - "<buffer>", - ":silent lua require('lint').try_lint()", - }, - }, - } - end -end - -local status_ok, _ = pcall(require, "lint") -if not status_ok then - return -end - -if not O.lint_on_save then - vim.cmd [[if exists('#autolint#BufWritePost') - :autocmd! autolint - endif]] -end - -return M diff --git a/.config/nvim/lua/core/log.lua b/.config/nvim/lua/core/log.lua new file mode 100644 index 0000000..d364ffb --- /dev/null +++ b/.config/nvim/lua/core/log.lua @@ -0,0 +1,29 @@ +local Log = {} + +--- Creates a log handle based on Plenary.log +---@param opts these are passed verbatim to Plenary.log +---@return log handle +function Log:new(opts) + local status_ok, _ = pcall(require, "plenary.log") + if not status_ok then + return nil + end + + local obj = require("plenary.log").new(opts) + local path = string.format("%s/%s.log", vim.api.nvim_call_function("stdpath", { "cache" }), opts.plugin) + + obj.get_path = function() + return path + end + + return obj +end + +--- Creates or retrieves a log handle for the default logfile +--- based on Plenary.log +---@return log handle +function Log:get_default() + return Log:new { plugin = "nvim", level = options.log.level } +end + +return Log diff --git a/.config/nvim/lua/core/nvimtree.lua b/.config/nvim/lua/core/nvimtree.lua index a763c71..698bd6e 100644 --- a/.config/nvim/lua/core/nvimtree.lua +++ b/.config/nvim/lua/core/nvimtree.lua @@ -1,8 +1,10 @@ local M = {} +local Log = require "core.log" -- M.config = function() - O.plugin.nvimtree = { + options.builtin.nvimtree = { side = "left", + width = 30, show_icons = { git = 1, folders = 1, @@ -48,23 +50,54 @@ end M.setup = function() local status_ok, nvim_tree_config = pcall(require, "nvim-tree.config") if not status_ok then + Log:get_default().error "Failed to load nvim-tree.config" return end local g = vim.g - for opt, val in pairs(O.plugin.nvimtree) do + for opt, val in pairs(options.builtin.nvimtree) do g["nvim_tree_" .. opt] = val end local tree_cb = nvim_tree_config.nvim_tree_callback - g.nvim_tree_bindings = { - { key = { "l", "<CR>", "o" }, cb = tree_cb "edit" }, - { key = "h", cb = tree_cb "close_node" }, - { key = "v", cb = tree_cb "vsplit" }, - } + if not g.nvim_tree_bindings then + g.nvim_tree_bindings = { + { key = { "l", "<CR>", "o" }, cb = tree_cb "edit" }, + { key = "h", cb = tree_cb "close_node" }, + { key = "v", cb = tree_cb "vsplit" }, + } + end end -- +M.focus_or_close = function() + local view_status_ok, view = pcall(require, "nvim-tree.view") + if not view_status_ok then + return + end + local a = vim.api + + local curwin = a.nvim_get_current_win() + local curbuf = a.nvim_win_get_buf(curwin) + local bufnr = view.View.bufnr + local winnr = view.get_winnr() + + if view.win_open() then + if curwin == winnr and curbuf == bufnr then + view.close() + if package.loaded["bufferline.state"] then + require("bufferline.state").set_offset(0) + end + else + view.focus() + end + else + view.open() + if package.loaded["bufferline.state"] and options.builtin.nvimtree.side == "left" then + require("bufferline.state").set_offset(options.builtin.nvimtree.width + 1, "") + end + end +end -- M.toggle_tree = function() local view_status_ok, view = pcall(require, "nvim-tree.view") @@ -77,12 +110,17 @@ M.toggle_tree = function() require("bufferline.state").set_offset(0) end else - if package.loaded["bufferline.state"] then - -- require'bufferline.state'.set_offset(31, 'File Explorer') - require("bufferline.state").set_offset(31, "") + if package.loaded["bufferline.state"] and options.builtin.nvimtree.side == "left" then + require("bufferline.state").set_offset(options.builtin.nvimtree.width + 1, "") end require("nvim-tree").toggle() end end -- +function M.change_tree_dir(dir) + if vim.g.loaded_tree then + require("nvim-tree.lib").change_dir(dir) + end +end +-- return M diff --git a/.config/nvim/lua/core/status_colors.lua b/.config/nvim/lua/core/status_colors.lua index 9a70ddd..71b6277 100644 --- a/.config/nvim/lua/core/status_colors.lua +++ b/.config/nvim/lua/core/status_colors.lua @@ -1,4 +1,4 @@ -O.plugin.galaxyline = { +options.builtin.galaxyline = { active = true, colors = { alt_bg = "#0A0A0A", diff --git a/.config/nvim/lua/core/telescope.lua b/.config/nvim/lua/core/telescope.lua index 48157bc..2b0a013 100644 --- a/.config/nvim/lua/core/telescope.lua +++ b/.config/nvim/lua/core/telescope.lua @@ -1,11 +1,12 @@ local M = {} +local Log = require "core.log" M.config = function() local status_ok, actions = pcall(require, "telescope.actions") if not status_ok then return end - O.plugin.telescope = { + options.builtin.telescope = { active = false, defaults = { find_command = { @@ -39,7 +40,7 @@ M.config = function() borderchars = { "─", "│", "─", "│", "╭", "╮", "╯", "╰" }, color_devicons = true, use_less = true, - set_env = { ["COLORTERM"] = "truecolor" }, -- default = nil, + set_env = { ["CoptionsLoptionsRTERM"] = "truecolor" }, -- default = nil, file_previewer = require("telescope.previewers").vim_buffer_cat.new, grep_previewer = require("telescope.previewers").vim_buffer_vimgrep.new, qflist_previewer = require("telescope.previewers").vim_buffer_qflist.new, @@ -61,7 +62,7 @@ M.config = function() -- ["<c-t>"] = trouble.open_with_trouble, -- ["<c-x>"] = false, -- ["<esc>"] = actions.close, - -- Otherwise, just set the mapping to the function that you want it to be. + -- optionstherwise, just set the mapping to the function that you want it to be. -- ["<C-i>"] = actions.select_horizontal, -- Add up multiple actions -- You can perform as many actions in a row as you like @@ -88,10 +89,10 @@ end M.setup = function() local status_ok, telescope = pcall(require, "telescope") if not status_ok then + Log:get_default().error "Failed to load telescope" return end - telescope.setup(O.plugin.telescope) - vim.api.nvim_set_keymap("n", "<Leader>f", ":Telescope find_files<CR>", { noremap = true, silent = true }) + telescope.setup(options.builtin.telescope) end return M diff --git a/.config/nvim/lua/core/terminal.lua b/.config/nvim/lua/core/terminal.lua index 0f93045..2793da2 100644 --- a/.config/nvim/lua/core/terminal.lua +++ b/.config/nvim/lua/core/terminal.lua @@ -1,8 +1,11 @@ local M = {} +local Log = require "core.log" +local utils = require "utils" + M.config = function() - O.plugin["terminal"] = { + options.builtin["terminal"] = { -- size can be a number or function which is passed the current terminal - size = 5, + size = 20, -- open_mapping = [[<c-\>]], open_mapping = [[<c-t>]], hide_numbers = true, -- hide the number column in toggleterm buffers @@ -11,7 +14,7 @@ M.config = function() shading_factor = 2, -- the degree by which to darken to terminal colour, default: 1 for dark backgrounds, 3 for light start_in_insert = true, insert_mappings = true, -- whether or not the open mapping applies in insert mode - persist_size = true, + persist_size = false, -- direction = 'vertical' | 'horizontal' | 'window' | 'float', direction = "float", close_on_exit = true, -- close the terminal window when the process exits @@ -26,43 +29,105 @@ M.config = function() border = "curved", -- width = <value>, -- height = <value>, - winblend = 3, + winblend = 0, highlights = { border = "Normal", background = "Normal", }, }, + -- Add executables on the config.lua + -- { exec, keymap, name} + -- options.builtin.terminal.execs = {{}} to overwrite + -- options.builtin.terminal.execs[#options.builtin.terminal.execs+1] = {"gdb", "tg", "GNU Debugger"} + execs = { + { "lazygit", "gg", "LazyGit" }, + }, } end M.setup = function() local status_ok, terminal = pcall(require, "toggleterm") if not status_ok then + Log:get_default().error "Failed to load toggleterm" print(terminal) return end + for _, exec in pairs(options.builtin.terminal.execs) do + require("core.terminal").add_exec(exec[1], exec[2], exec[3]) + end + terminal.setup(options.builtin.terminal) +end + +local function is_installed(exe) + return vim.fn.executable(exe) == 1 +end + +M.add_exec = function(exec, keymap, name) vim.api.nvim_set_keymap( "n", - "<leader>gg", - "<cmd>lua require('core.terminal')._lazygit_toggle()<CR>", + "<leader>" .. keymap, + "<cmd>lua require('core.terminal')._exec_toggle('" .. exec .. "')<CR>", { noremap = true, silent = true } ) - O.plugin.which_key.mappings["gg"] = "LazyGit" - terminal.setup(O.plugin.terminal) + options.builtin.which_key.mappings[keymap] = name end -local function is_installed(exe) - return vim.fn.executable(exe) == 1 +M._split = function(inputstr, sep) + if sep == nil then + sep = "%s" + end + local t = {} + for str in string.gmatch(inputstr, "([^" .. sep .. "]+)") do + table.insert(t, str) + end + return t end -M._lazygit_toggle = function() - if is_installed "lazygit" ~= true then - print "Please install lazygit. Check documentation for more information" +M._exec_toggle = function(exec) + local binary = M._split(exec)[1] + if is_installed(binary) ~= true then + print("Please install executable " .. binary .. ". Check documentation for more information") return end local Terminal = require("toggleterm.terminal").Terminal - local lazygit = Terminal:new { cmd = "lazygit", hidden = true } - lazygit:toggle() + local exec_term = Terminal:new { cmd = exec, hidden = true } + exec_term:toggle() +end + +local function get_log_path(name) + --handle custom paths not managed by Plenary.log + local logger = require "core.log" + local file + if name == "nvim" then + file = CACHE_PATH .. "/log" + else + file = logger:new({ plugin = name }):get_path() + end + if utils.is_file(file) then + return file + end +end + +---Toggles a log viewer according to log.viewer.layout_config +---@param name can be the name of any of the managed logs, e,g. "lunarvim" or the default ones {"nvim", "lsp", "packer.nvim"} +M.toggle_log_view = function(name) + local logfile = get_log_path(name) + if not logfile then + return + end + local term_opts = vim.tbl_deep_extend("force", options.builtin.terminal, { + cmd = options.log.viewer.cmd .. " " .. logfile, + open_mapping = options.log.viewer.layout_config.open_mapping, + direction = options.log.viewer.layout_config.direction, + -- TODO: this might not be working as expected + size = options.log.viewer.layout_config.size, + float_opts = options.log.viewer.layout_config.float_opts, + }) + + local Terminal = require("toggleterm.terminal").Terminal + local log_view = Terminal:new(term_opts) + -- require("core.log"):get_default().debug("term", vim.inspect(term_opts)) + log_view:toggle() end return M diff --git a/.config/nvim/lua/core/treesitter.lua b/.config/nvim/lua/core/treesitter.lua index 2b7a2d5..ba70b70 100644 --- a/.config/nvim/lua/core/treesitter.lua +++ b/.config/nvim/lua/core/treesitter.lua @@ -1,6 +1,7 @@ local M = {} +local Log = require "core.log" M.config = function() - O.treesitter = { + options.builtin.treesitter = { ensure_installed = {}, -- one of "all", "maintained" (parsers with maintainers), or a list of languages ignore_install = {}, matchup = { @@ -18,7 +19,7 @@ M.config = function() }, -- indent = {enable = true, disable = {"python", "html", "javascript"}}, -- TODO seems to be broken - indent = { enable = { "javascriptreact" } }, + indent = { enable = true, disable = { "yaml" } }, autotag = { enable = false }, textobjects = { swap = { @@ -59,129 +60,16 @@ M.config = function() max_file_lines = 1000, -- Do not enable for files with more than 1000 lines, int }, } - - -- -- TODO refactor treesitter - -- -- @usage pass a table with your desired languages - -- treesitter = { - -- ensure_installed = "all", - -- ignore_install = { "haskell" }, - -- highlight = { enabled = true }, - -- -- The below are for treesitter-textobjects plugin - -- textobj_prefixes = { - -- goto_next = "]", -- Go to next - -- goto_previous = "[", -- Go to previous - -- inner = "i", -- Select inside - -- outer = "a", -- Selct around - -- swap = "<leader>a", -- Swap with next - -- }, - -- textobj_suffixes = { - -- -- Start and End respectively for the goto keys - -- -- for other keys it only uses the first - -- ["function"] = { "f", "F" }, - -- ["class"] = { "m", "M" }, - -- ["parameter"] = { "a", "A" }, - -- ["block"] = { "k", "K" }, - -- ["conditional"] = { "i", "I" }, - -- ["call"] = { "c", "C" }, - -- ["loop"] = { "l", "L" }, - -- ["statement"] = { "s", "S" }, - -- ["comment"] = { "/", "?" }, - -- }, - -- -- The below is for treesitter hint textobjects plugin - -- hint_labels = { "h", "j", "f", "d", "n", "v", "s", "l", "a" }, - -- }, end M.setup = function() - -- TODO: refacor this whole file and treesitter in general - -- if not package.loaded['nvim-treesitter'] then return end - -- - -- Custom parsers - -- local parser_config = require("nvim-treesitter.parsers").get_parser_configs() - -- parser_config.make = { - -- install_info = { - -- url = "https://github.com/alemuller/tree-sitter-make", -- local path or git repo - -- files = {"src/parser.c"}, - -- requires_generate_from_grammar = true - -- } - -- } - -- parser_config.just = { - -- install_info = { - -- url = "~/dev/tree-sitter-just", -- local path or git repo - -- files = {"src/parser.c"} - -- } - -- -- filetype = "just", -- if filetype does not agrees with parser name - -- -- used_by = {"bar", "baz"} -- additional filetypes that use this parser - -- } - -- Custom text objects - -- local textobj_prefixes = O.treesitter.textobj_prefixes - -- local textobj_suffixes = O.treesitter.textobj_suffixes - -- local textobj_sel_keymaps = {} - -- local textobj_swap_keymaps = {} - -- local textobj_move_keymaps = { - -- enable = O.plugin.ts_textobjects, - -- set_jumps = true, -- whether to set jumps in the jumplist - -- goto_next_start = {}, - -- goto_next_end = {}, - -- goto_previous_start = {}, - -- goto_previous_end = {}, - -- } - -- for obj, suffix in pairs(textobj_suffixes) do - -- if textobj_prefixes["goto_next"] ~= nil then - -- textobj_move_keymaps["goto_next_start"][textobj_prefixes["goto_next"] .. suffix[1]] = "@" .. obj .. ".outer" - -- textobj_move_keymaps["goto_next_end"][textobj_prefixes["goto_next"] .. suffix[2]] = "@" .. obj .. ".outer" - -- end - -- if textobj_prefixes["goto_previous"] ~= nil then - -- textobj_move_keymaps["goto_previous_start"][textobj_prefixes["goto_previous"] .. suffix[2]] = "@" .. obj .. ".outer" - -- textobj_move_keymaps["goto_previous_end"][textobj_prefixes["goto_previous"] .. suffix[1]] = "@" .. obj .. ".outer" - -- end - -- - -- if textobj_prefixes["inner"] ~= nil then - -- textobj_sel_keymaps[textobj_prefixes["inner"] .. suffix[1]] = "@" .. obj .. ".inner" - -- end - -- if textobj_prefixes["outer"] ~= nil then - -- textobj_sel_keymaps[textobj_prefixes["outer"] .. suffix[1]] = "@" .. obj .. ".outer" - -- end - -- - -- if textobj_prefixes["swap"] ~= nil then - -- textobj_swap_keymaps[textobj_prefixes["swap"] .. suffix[1]] = "@" .. obj .. ".outer" - -- end - -- end - -- vim.g.ts_hint_textobject_keys = O.treesitter.hint_labels -- Requires https://github.com/mfussenegger/nvim-ts-hint-textobject/pull/2 - -- - -- -- Add which key menu entries - -- local status, wk = pcall(require, "which-key") - -- if status then - -- local normal = { - -- mode = "n", -- Normal mode - -- } - -- local operators = { - -- mode = "o", -- Operator mode - -- } - -- wk.register(textobj_sel_keymaps, operators) - -- wk.register({ - -- ["m"] = "Hint Objects", - -- ["."] = "Textsubject", - -- [";"] = "Textsubject-big", - -- }, operators) - -- wk.register(textobj_swap_keymaps, normal) - -- wk.register({ - -- [textobj_prefixes["swap"]] = "Swap", - -- -- [textobj_prefixes["goto_next"]] = "Jump [", - -- -- [textobj_prefixes["goto_previous"]] = "Jump ]" - -- }, normal) - -- wk.register(textobj_move_keymaps["goto_next_start"], normal) - -- wk.register(textobj_move_keymaps["goto_next_end"], normal) - -- wk.register(textobj_move_keymaps["goto_previous_start"], normal) - -- wk.register(textobj_move_keymaps["goto_previous_end"], normal) - -- end - local status_ok, treesitter_configs = pcall(require, "nvim-treesitter.configs") if not status_ok then + Log:get_default().error "Failed to load nvim-treesitter.configs" return end - treesitter_configs.setup(O.treesitter) + treesitter_configs.setup(options.builtin.treesitter) end return M diff --git a/.config/nvim/lua/core/which-key.lua b/.config/nvim/lua/core/which-key.lua index dabf832..6227a8e 100644 --- a/.config/nvim/lua/core/which-key.lua +++ b/.config/nvim/lua/core/which-key.lua @@ -1,6 +1,7 @@ local M = {} +local Log = require "core.log" M.config = function() - O.plugin.which_key = { + options.builtin.which_key = { active = false, setup = { plugins = { @@ -58,7 +59,7 @@ M.config = function() -- NOTE: Prefer using : over <cmd> as the latter avoids going back in normal-mode. -- see https://neovim.io/doc/user/map.html#:map-cmd vmappings = { - ["/"] = { ":CommentToggle<CR>", "Comment" }, + ["k"] = { ":CommentToggle<CR>", "Comment" }, }, mappings = { ["w"] = { "<cmd>w!<CR>", "Save" }, @@ -68,14 +69,36 @@ M.config = function() ["e"] = { "<cmd>lua require'core.nvimtree'.toggle_tree()<CR>", "Explorer" }, ["f"] = { "<cmd>Telescope find_files<CR>", "Find File" }, ["n"] = { '<cmd>let @/=""<CR>', "No Highlight" }, - ["h"] = { "<cmd>vsplit<CR>", "Vertical Split" }, - ["v"] = { '<cmd>split<CR>', "Horizontal Split" }, + b = { + name = "Buffers", + j = { "<cmd>BufferPick<cr>", "jump to buffer" }, + f = { "<cmd>Telescope buffers<cr>", "Find buffer" }, + w = { "<cmd>BufferWipeout<cr>", "wipeout buffer" }, + e = { + "<cmd>BufferCloseAllButCurrent<cr>", + "close all but current buffer", + }, + h = { "<cmd>BufferCloseBuffersLeft<cr>", "close all buffers to the left" }, + l = { + "<cmd>BufferCloseBuffersRight<cr>", + "close all BufferLines to the right", + }, + D = { + "<cmd>BufferOrderByDirectory<cr>", + "sort BufferLines automatically by directory", + }, + L = { + "<cmd>BufferOrderByLanguage<cr>", + "sort BufferLines automatically by language", + }, + }, p = { name = "Packer", c = { "<cmd>PackerCompile<cr>", "Compile" }, i = { "<cmd>PackerInstall<cr>", "Install" }, - r = { "<cmd>lua require('utils').reload_config()<cr>", "Reload" }, + r = { "<cmd>lua require('utils').reload_lv_config()<cr>", "Reload" }, s = { "<cmd>PackerSync<cr>", "Sync" }, + S = { "<cmd>PackerStatus<cr>", "Status" }, u = { "<cmd>PackerUpdate<cr>", "Update" }, }, @@ -119,18 +142,24 @@ M.config = function() "<cmd>Telescope lsp_workspace_diagnostics<cr>", "Workspace Diagnostics", }, - f = { "<cmd>silent FormatWrite<cr>", "Format" }, + -- f = { "<cmd>silent FormatWrite<cr>", "Format" }, + f = { "<cmd>lua vim.lsp.buf.formatting()<cr>", "Format" }, i = { "<cmd>LspInfo<cr>", "Info" }, j = { - "<cmd>lua vim.lsp.diagnostic.goto_next({popup_opts = {border = O.lsp.popup_border}})<cr>", + "<cmd>lua vim.lsp.diagnostic.goto_next({popup_opts = {border = options.lsp.popup_border}})<cr>", "Next Diagnostic", }, k = { - "<cmd>lua vim.lsp.diagnostic.goto_prev({popup_opts = {border = O.lsp.popup_border}})<cr>", + "<cmd>lua vim.lsp.diagnostic.goto_prev({popup_opts = {border = options.lsp.popup_border}})<cr>", "Prev Diagnostic", }, - l = { "<cmd>silent lua require('lint').try_lint()<cr>", "Lint" }, - q = { "<cmd>Telescope quickfix<cr>", "Quickfix" }, + p = { + name = "Peek", + d = { "<cmd>lua require('lsp.peek').Peek('definition')<cr>", "Definition" }, + t = { "<cmd>lua require('lsp.peek').Peek('typeDefinition')<cr>", "Type Definition" }, + i = { "<cmd>lua require('lsp.peek').Peek('implementation')<cr>", "Implementation" }, + }, + q = { "<cmd>lua vim.lsp.diagnostic.set_loclist()<cr>", "Quickfix" }, r = { "<cmd>lua vim.lsp.buf.rename()<cr>", "Rename" }, s = { "<cmd>Telescope lsp_document_symbols<cr>", "Document Symbols" }, S = { @@ -138,6 +167,14 @@ M.config = function() "Workspace Symbols", }, }, + I = { + name = "+nvim", + k = { "<cmd>lua require('keymappings').print()<cr>", "View nvim's default keymappings" }, + i = { + "<cmd>lua require('core.info').toggle_popup(vim.bo.filetype)<cr>", + "Toggle nvim Info", + }, + }, s = { name = "Search", @@ -170,32 +207,22 @@ M.setup = function() -- end local status_ok, which_key = pcall(require, "which-key") if not status_ok then + Log:get_default "Failed to load whichkey" return end - which_key.setup(O.plugin.which_key.setup) - - local opts = O.plugin.which_key.opts - local vopts = O.plugin.which_key.vopts + which_key.setup(options.builtin.which_key.setup) - local mappings = O.plugin.which_key.mappings - local vmappings = O.plugin.which_key.vmappings + local opts = options.builtin.which_key.opts + local vopts = options.builtin.which_key.vopts - -- if O.plugin.ts_playground.active then - -- vim.api.nvim_set_keymap("n", "<leader>Th", ":TSHighlightCapturesUnderCursor<CR>", { noremap = true, silent = true }) - -- mappings[""] = "Highlight Capture" - -- end - - if O.plugin.zen.active then - vim.api.nvim_set_keymap("n", "<leader>z", ":ZenMode<CR>", { noremap = true, silent = true }) - mappings["z"] = "Zen" - end + local mappings = options.builtin.which_key.mappings + local vmappings = options.builtin.which_key.vmappings local wk = require "which-key" wk.register(mappings, opts) wk.register(vmappings, vopts) - wk.register(O.user_which_key, opts) end return M diff --git a/.config/nvim/lua/core/zen.lua b/.config/nvim/lua/core/zen.lua deleted file mode 100644 index 99a5d76..0000000 --- a/.config/nvim/lua/core/zen.lua +++ /dev/null @@ -1,34 +0,0 @@ -local M = {} -M.config = function() - O.plugin["zen"] = { - window = { - backdrop = 1, - height = 0.85, -- height of the Zen window - options = { - signcolumn = "no", -- disable signcolumn - number = false, -- disable number column - relativenumber = false, -- disable relative numbers - -- cursorline = false, -- disable cursorline - -- cursorcolumn = false, -- disable cursor column - -- foldcolumn = "0", -- disable fold column - -- list = false, -- disable whitespace characters - }, - }, - plugins = { - gitsigns = { enabled = false }, -- disables git signs - -- your configuration comes here - -- or leave it empty to use the default settings - -- refer to the configuration section below - }, - } -end - -M.setup = function() - local status_ok, zen_mode = pcall(require, "zen-mode") - if not status_ok then - return - end - zen_mode.setup(O.plugin.zen) -end - -return M |