diff --git a/nvim/init.lua b/nvim/init.lua index 5b21840..68c223d 100644 --- a/nvim/init.lua +++ b/nvim/init.lua @@ -1,27 +1,5 @@ --- Is new loader available? -if vim.loader then - vim.loader.enable() -end - --- Setup default options -require 'config.options' -require 'config.keymaps' -require 'config.autocmd' - --- Are we inside Neovide? -if vim.g.neovide then - require 'config.neovide' -end - --- Try load package manager -local ok, err = pcall(function() - require 'config.manager' -end) - -if not ok and err then - vim.cmd 'colorscheme slate' - - vim.schedule(function() - vim.notify(err, vim.log.levels.ERROR) - end) +local ok, err = pcall(require, 'main') + +if not ok then + print('Error: ' .. err) end diff --git a/nvim/lazy-lock.json b/nvim/lazy-lock.json index 1bd0316..cf3dcde 100644 --- a/nvim/lazy-lock.json +++ b/nvim/lazy-lock.json @@ -7,26 +7,27 @@ "cmp-path": { "branch": "main", "commit": "91ff86cd9c29299a64f968ebb45846c485725f23" }, "cmp_luasnip": { "branch": "master", "commit": "05a9ab28b53f71d1aece421ef32fee2cb857a843" }, "diffview.nvim": { "branch": "main", "commit": "3dc498c9777fe79156f3d32dddd483b8b3dbd95f" }, - "gitsigns.nvim": { "branch": "main", "commit": "c5ff7628e19a47ec14d3657294cc074ecae27b99" }, + "gitsigns.nvim": { "branch": "main", "commit": "0a2a93f687ec051292943a4d139366332ac93688" }, "haskell-tools.nvim": { "branch": "master", "commit": "2faa2c879c82652f1df3974c185901cf93c6367c" }, "kanagawa.nvim": { "branch": "master", "commit": "c19b9023842697ec92caf72cd3599f7dd7be4456" }, - "lazy.nvim": { "branch": "main", "commit": "28126922c9b54e35a192ac415788f202c3944c9f" }, - "lualine.nvim": { "branch": "master", "commit": "566b7036f717f3d676362742630518a47f132fff" }, - "mason-lspconfig.nvim": { "branch": "main", "commit": "3ba1b92b771f33256b4969d696b82c8ae7075364" }, + "lazy.nvim": { "branch": "main", "commit": "aedcd79811d491b60d0a6577a9c1701063c2a609" }, + "lualine.nvim": { "branch": "master", "commit": "7d131a8d3ba5016229e8a1d08bf8782acea98852" }, + "mason-lspconfig.nvim": { "branch": "main", "commit": "b9084b1f42f790d6230dc66dbcb6bcc35b148552" }, "mason-nvim-dap.nvim": { "branch": "main", "commit": "3614a39aae98ccd34124b072939d6283853b3dd2" }, "mason.nvim": { "branch": "main", "commit": "9c9416817c9f4e6f333c749327a1ed5355cfab61" }, "neo-tree.nvim": { "branch": "v3.x", "commit": "2f2d08894bbc679d4d181604c16bb7079f646384" }, - "neodev.nvim": { "branch": "main", "commit": "5bbbeda6a9c672f314c95ca47a8b495cf6de17f9" }, + "neodev.nvim": { "branch": "main", "commit": "3408a4daeca5ff8f41cb2c668b6d8fcc665f793a" }, + "neogit": { "branch": "master", "commit": "ce0c369ccdba3f644a3b28f4c053421f435352c9" }, "nui.nvim": { "branch": "main", "commit": "35da9ca1de0fc4dda96c2e214d93d363c145f418" }, "nvim-cmp": { "branch": "main", "commit": "538e37ba87284942c1d76ed38dd497e54e65b891" }, "nvim-dap": { "branch": "master", "commit": "9adbfdca13afbe646d09a8d7a86d5d031fb9c5a5" }, "nvim-dap-ui": { "branch": "master", "commit": "d845ebd798ad1cf30aa4abd4c4eff795cdcfdd4f" }, "nvim-lspconfig": { "branch": "master", "commit": "8917d2c830e04bf944a699b8c41f097621283828" }, "nvim-notify": { "branch": "master", "commit": "80b67b265530632505193553d05127ae7fe09ddd" }, - "nvim-treesitter": { "branch": "master", "commit": "cd4e0909948eb33d3959e133c16f837e4db122c6" }, - "nvim-web-devicons": { "branch": "master", "commit": "140edfcf25093e8b321d13e154cbce89ee868ca0" }, + "nvim-treesitter": { "branch": "master", "commit": "ce4adf11cfe36fc5b0e5bcdce0c7c6e8fbc9798a" }, + "nvim-web-devicons": { "branch": "master", "commit": "b427ac5f9dff494f839e81441fb3f04a58cbcfbc" }, "plenary.nvim": { "branch": "master", "commit": "663246936325062427597964d81d30eaa42ab1e4" }, - "rustaceanvim": { "branch": "master", "commit": "a095a1f9397310d108ead239edc068b2624695b6" }, + "rustaceanvim": { "branch": "master", "commit": "bc8c4b8f7606d5b7c067cd8369e25c1a7ff77bd0" }, "telescope-fzf-native.nvim": { "branch": "main", "commit": "6c921ca12321edaa773e324ef64ea301a1d0da62" }, "telescope.nvim": { "branch": "0.1.x", "commit": "d90956833d7c27e73c621a61f20b29fdb7122709" }, "which-key.nvim": { "branch": "main", "commit": "4433e5ec9a507e5097571ed55c02ea9658fb268a" } diff --git a/nvim/lua/config/helpers.lua b/nvim/lua/config/helpers.lua index 603666b..52f8ea6 100644 --- a/nvim/lua/config/helpers.lua +++ b/nvim/lua/config/helpers.lua @@ -1,40 +1,3 @@ -local M = {} - - -local defaults = { noremap = true, silent = true } - ----@class KeymapOpts ----@field [1]? string Shorthand description ----@field desc? string Description ----@field [2]? number|boolean Shorthand buffer ----@field buffer? number|boolean Buffer - ----Wrapper around `vim.keymap.set` ----@param modes string|string[] -function M.keymap(modes) - ---@param lhs string - return function(lhs) - ---@param rhs string|function - return function(rhs) - ---@param opts string|KeymapOpts - return function(opts) - -- Either 'string' or 'table' - local type = type(opts) - ---@type table - local options - if type == 'string' then - options = vim.tbl_extend('force', defaults, {desc=opts}) - elseif type == 'table' then - opts.desc = opts[1] or opts.desc - opts.buffer = opts[2] or opts.buffer - opts[1], opts[2] = nil, nil - options = vim.tbl_extend('force', defaults, opts) - end - vim.keymap.set(modes, lhs, rhs, options) - end - end - end -end - - -return M +return { + keymap = require 'config.helpers.keymap', +} diff --git a/nvim/lua/config/helpers/keymap.lua b/nvim/lua/config/helpers/keymap.lua new file mode 100644 index 0000000..02f8028 --- /dev/null +++ b/nvim/lua/config/helpers/keymap.lua @@ -0,0 +1,35 @@ +local defaults = { noremap = true, silent = true } + +---@class KeymapOpts +---@field [1]? string Shorthand description +---@field desc? string Description +---@field [2]? number|boolean Shorthand buffer +---@field buffer? number|boolean Buffer + +---Wrapper around `vim.keymap.set` +---@param modes string|string[] +return function(modes) + ---@param lhs string + return function(lhs) + ---@param rhs string|function + return function(rhs) + ---@param opts string|KeymapOpts + return function(opts) + local kind = type(opts) ---@cast kind 'string'|'table' + ---@type table + local options + + if kind == 'string' then + options = vim.tbl_extend('force', defaults, {desc=opts}) + else + opts.desc = opts[1] or opts.desc + opts.buffer = opts[2] or opts.buffer + opts[1], opts[2] = nil, nil + options = vim.tbl_extend('force', defaults, opts) + end + + vim.keymap.set(modes, lhs, rhs, options) + end + end + end +end diff --git a/nvim/lua/config/keymaps.lua b/nvim/lua/config/keymaps.lua index c8b68e4..9093af8 100644 --- a/nvim/lua/config/keymaps.lua +++ b/nvim/lua/config/keymaps.lua @@ -1,7 +1,7 @@ -local H = require 'config.helpers' -local n = H.keymap 'n' -local t = H.keymap 't' -local nv = H.keymap {'n', 'v'} +local map = require 'config.helpers.keymap' +local n = map 'n' +local t = map 't' +local nv = map {'n', 'v'} n 'mn' ':Explore ~/.config/nvim/' 'Meta: open Neovim config' diff --git a/nvim/lua/config/plugins.lua b/nvim/lua/config/plugins.lua index eaf53ab..697caef 100644 --- a/nvim/lua/config/plugins.lua +++ b/nvim/lua/config/plugins.lua @@ -1,6 +1,6 @@ local is, when = require 'config.compose' () -local H = require 'config.helpers' -local n = H.keymap 'n' +local map = require 'config.helpers.keymap' +local n = map 'n' ---@type LazySpec @@ -63,13 +63,13 @@ return { } } - n 'ff' (builtin.find_files) 'Telescope: find files' - n 'fb' (builtin.buffers) 'Telescope: find buffers' - n 'fg' (builtin.live_grep) 'Telescope: grep content' - n 'fh' (builtin.help_tags) 'Telescope: search docs' + n 'ff' (builtin.find_files) 'Telescope: files' + n 'fb' (builtin.buffers) 'Telescope: buffers' + n 'fg' (builtin.live_grep) 'Telescope: grep' + n 'fh' (builtin.help_tags) 'Telescope: docs' if is 'standalone' then - n 'fn' (ext.notify.notify) 'Telescope: find notifications' + n 'fn' (ext.notify.notify) 'Telescope: notifications' end end, }, @@ -88,7 +88,7 @@ return { ignore_install = {}, ensure_installed = { -- neovim - 'vimdoc', 'lua', 'query', + 'vimdoc', 'lua', 'query', 'luadoc', -- data 'json', 'xml', 'yaml', 'toml', -- markdown @@ -131,11 +131,57 @@ return { end, }, - -- Git signs + -- Git - file hunks { 'lewis6991/gitsigns.nvim', enabled = is 'standalone', - config = true, + config = function() + local gs = require 'gitsigns' + + gs.setup { + on_attach = function() + n 'hp' (gs.preview_hunk) 'Hunk: preview' + n 'hs' (gs.stage_hunk) 'Hunk: stage' + n 'hu' (gs.undo_stage_hunk) 'Hunk: unstage' + n 'hr' (gs.reset_hunk) 'Hunk: reset' + n 'hS' (gs.stage_buffer) 'Hunk: buffer stage' + n 'hR' (gs.reset_buffer) 'Hunk: buffer reset' + n 'hd' (gs.toggle_deleted) 'Hunk: show deleted' + end + } + end, + }, + + -- Git - project diff + { + 'sindrets/diffview.nvim', + enabled = is 'standalone', + dependencies = { + 'nvim-lua/plenary.nvim', + 'nvim-tree/nvim-web-devicons', + }, + config = function() + n 'gd' ':DiffviewOpen' 'Git: Diff' + n 'gc' ':DiffviewClose' 'Git: Close' + n 'gh' ':DiffviewFileHistory' 'Git: History' + end + }, + + -- Git: ops + { + 'NeogitOrg/neogit', + dependencies = { + 'nvim-lua/plenary.nvim', + 'sindrets/diffview.nvim', + 'nvim-telescope/telescope.nvim' + }, + config = function() + local neogit = require 'neogit' + + n 'gn' (neogit.open) 'Git: Neogit' + + neogit.setup({}) + end }, -- Comments @@ -177,16 +223,6 @@ return { }, }, - -- Git diffviewer - { - 'sindrets/diffview.nvim', - enabled = is 'standalone', - dependencies = { - 'nvim-lua/plenary.nvim', - 'nvim-tree/nvim-web-devicons', - }, - }, - -- Snippet engine { 'L3MON4D3/LuaSnip', diff --git a/nvim/lua/config/plugins/haskell-tools.lua b/nvim/lua/config/plugins/haskell-tools.lua index 315a3af..d7b0e8b 100644 --- a/nvim/lua/config/plugins/haskell-tools.lua +++ b/nvim/lua/config/plugins/haskell-tools.lua @@ -1,5 +1,5 @@ -local H = require 'config.helpers' -local n = H.keymap 'n' +local map = require 'config.helpers.keymap' +local n = map 'n' ---@param buffer number diff --git a/nvim/lua/config/plugins/rustaceanvim.lua b/nvim/lua/config/plugins/rustaceanvim.lua index c20b6d1..30c7f18 100644 --- a/nvim/lua/config/plugins/rustaceanvim.lua +++ b/nvim/lua/config/plugins/rustaceanvim.lua @@ -1,5 +1,5 @@ -local H = require 'config.helpers' -local n = H.keymap 'n' +local map = require 'config.helpers.keymap' +local n = map 'n' vim.g.rustaceanvim = function() diff --git a/nvim/lua/main.lua b/nvim/lua/main.lua new file mode 100644 index 0000000..b15be30 --- /dev/null +++ b/nvim/lua/main.lua @@ -0,0 +1,20 @@ +-- Setup default options +require 'config.options' +require 'config.keymaps' +require 'config.autocmd' + +-- Are we inside Neovide? +if vim.g.neovide then + require 'config.neovide' +end + +-- Try load package manager +local ok, err = pcall(require, 'config.manager') + +if not ok then + vim.cmd 'colorscheme slate' + + vim.schedule(function() + vim.notify(err, vim.log.levels.ERROR) + end) +end