diff --git a/README.md b/README.md index ffbc5e2..daaeef4 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,10 @@ # Neovim Config +To ignore changes to local plugins file. Used for keeping computer specific configs/plugins +```shell +git update-index --assume-unchanged lua/plugins-local.lua +``` ## Requirements * ripgrep - for telescope * [A patched font](https://www.nerdfonts.com/) - for icons - - diff --git a/after/plugin/lspsignature-theme.lua b/after/plugin/lspsignature-theme.lua new file mode 100644 index 0000000..0438b36 --- /dev/null +++ b/after/plugin/lspsignature-theme.lua @@ -0,0 +1,8 @@ +if vim.g.colors_name == "srcery" then + local hard_black = vim.api.nvim_get_hl_by_name("SrceryHardBlack", true).foreground + local bright_white = vim.api.nvim_get_hl_by_name("SrceryBrightWhite", true).foreground + + vim.api.nvim_set_hl(0, "FloatBorder", {bg=hard_black, fg=bright_white}) + vim.api.nvim_set_hl(0, "FloatNormal", {bg=hard_black, fg=bright_white}) + vim.api.nvim_set_hl(0, "Pmenu", {bg=hard_black, fg=bright_white}) +end diff --git a/after/plugin/telescope-theme.lua b/after/plugin/telescope-theme.lua new file mode 100644 index 0000000..c71df0c --- /dev/null +++ b/after/plugin/telescope-theme.lua @@ -0,0 +1,22 @@ +if vim.g.colors_name == "srcery" then + local bright_white = vim.api.nvim_get_hl_by_name("SrceryBrightWhite", true).foreground + local hard_black = vim.api.nvim_get_hl_by_name("SrceryHardBlack", true).foreground + local red = vim.api.nvim_get_hl_by_name("SrceryRed", true).foreground + local yellow = vim.api.nvim_get_hl_by_name("SrceryYellow", true).foreground + local gray1 = vim.api.nvim_get_hl_by_name("SrceryXgray1", true).foreground + + local TelescopePrompt = { + TelescopeBorder = {bg = hard_black, fg = hard_black}, + TelescopePromptBorder = {bg = gray1, fg = gray1}, + TelescopePromptNormal = {bg = gray1}, + TelescopePromptTitle = {fg = hard_black, bg = red }, + TelescopePreviewTitle = {fg = hard_black, bg = yellow }, + TelescopeNormal = {bg = hard_black, fg = bright_white}, + TelescopeResultsNormal = {bg = hard_black, fg = bright_white}, + TelescopePreviewNormal = {bg = hard_black, fg = bright_white}, + TelescopeSelection = {bg = hard_black, fg = bright_white, underline = true}, + } + for hl, col in pairs(TelescopePrompt) do + vim.api.nvim_set_hl(0, hl, col) + end +end diff --git a/init.lua b/init.lua index dcfad18..58d840f 100644 --- a/init.lua +++ b/init.lua @@ -1,46 +1,21 @@ -local opt = require 'utils.opt' -local g = vim.g -local cmd = vim.cmd - -- Allow loading */init.lua files package.path = "./?/init.lua;"..package.path -- Leader/local leader -g.mapleader = [[ ]] -g.maplocalleader = [[,]] +vim.g.mapleader = [[ ]] +vim.g.maplocalleader = [[,]] -- Disable some built-in plugins we don't want -local disabled_built_ins = { - 'matchit', - 'netrw', - 'netrwPlugin', - 'netrwSettings', - 'netrwFileHandlers', -} - -for _, name in ipairs(disabled_built_ins) do - g['loaded_' .. name] = 1 -end - -require("plugins") +require("disable-builtin") +require("highlight-yank") +require("plugin-manager") require("options") require("bindings") require("pludin-dev") -require("add-guard") -require("cmacro-align") - --- Misc features -require("highlight-yank") - --- Background transparency --- cmd [[autocmd ColorScheme * highlight Normal ctermbg=none guibg=none]] --- cmd [[autocmd ColorScheme * highlight Folded ctermbg=none guibg=none]] --- cmd [[autocmd ColorScheme * highlight SignColumn ctermbg=none guibg=none]] --- cmd [[autocmd ColorScheme * highlight VertSplit ctermbg=none guibg=none]] --- cmd [[autocmd ColorScheme * highlight StatusLineNC ctermbg=none guibg=none]] --- cmd [[autocmd ColorScheme * highlight CursorLineNr ctermbg=none guibg=none]] +require("personal.add-guard") +require("personal.cmacro-align") -- THEME_BEGIN -cmd("colorscheme srcery") +vim.cmd("colorscheme srcery") -- THEME_END diff --git a/lua/bindings.lua b/lua/bindings.lua index e6aaca9..12df6cc 100644 --- a/lua/bindings.lua +++ b/lua/bindings.lua @@ -6,7 +6,7 @@ local silent = {silent = true} map('n', 'Q', '') -- Save file -map('n', '', ':w') +map('n', '', ':w', silent) -- Paste from register and not replace it -- map('x', 'p', '"_dP') @@ -31,13 +31,6 @@ map('v', '>', '>gv') map('n', '', ':tabprevious', silent) map('n', '', ':tabnext', silent) --- Move lines up or down -map('n', '', ':m .+1==', silent) -map('n', '', ':m .+1==', silent) -map('n', '', ':m .-2==', silent) -map('v', '', ":m '>+1gv=gv", silent) -map('v', '', ":m '<-2gv=gv", silent) - -- Move between windows easier in terminal windows function _G.set_terminal_keymaps() local opts = {buffer = 0} diff --git a/lua/config/autosource.lua b/lua/config/autosource.lua index 2c6534e..5a7a6e3 100644 --- a/lua/config/autosource.lua +++ b/lua/config/autosource.lua @@ -1,3 +1,7 @@ -local user = os.getenv("USER") -vim.g.autosource_hashdir = '/home/'..user..'/.cache/vim-autosource/hashes' - +return { + 'jenterkin/vim-autosource', + config = function() + local user = os.getenv("USER") + vim.g.autosource_hashdir = '/home/'..user..'/.cache/vim-autosource/hashes' + end +} diff --git a/lua/config/baleia.lua b/lua/config/baleia.lua index 1a6dd94..bd70bff 100644 --- a/lua/config/baleia.lua +++ b/lua/config/baleia.lua @@ -1,4 +1,14 @@ -local baleia = require("baleia").setup() -vim.api.nvim_create_user_command("BaleiaColorize", function() - baleia.once(vim.api.nvim_get_current_buf()) -end, { }) +return { + 'm00qek/baleia.nvim', + tag = 'v1.2.0', + config = function() + local baleia = require("baleia").setup() + vim.api.nvim_create_user_command("BaleiaColorize", function() + baleia.once(vim.api.nvim_get_current_buf()) + end, { }) + + require("legendary").command{ + ":BaleiaColorize", description = "Colorize ANSI codes" + } + end +} diff --git a/lua/config/based.lua b/lua/config/based.lua new file mode 100644 index 0000000..5cffb22 --- /dev/null +++ b/lua/config/based.lua @@ -0,0 +1,15 @@ +return { + 'trmckay/based.nvim', + config = function () + local based = require("based") + based.setup{} + + vim.keymap.set({"n", "v"}, "", based.convert) + + require("legendary").keymap{ + "", + { n = based.convert, v = based.convert }, + description = "Convert number to other base" + } + end +} diff --git a/lua/config/colorizer.lua b/lua/config/colorizer.lua index 444a0a4..98dd054 100644 --- a/lua/config/colorizer.lua +++ b/lua/config/colorizer.lua @@ -1,15 +1,19 @@ -require('colorizer').setup( - nil, - { - RGB = true, - RRGGBB = true, - names = false, - RRGGBBAA = true, - rgb_fn = true, - hsl_fn = true, - css = false, - css_fn = false, - mode = 'background' - } -) - +return { + 'norcalli/nvim-colorizer.lua', + config = function() + require('colorizer').setup( + nil, + { + RGB = true, + RRGGBB = true, + names = false, + RRGGBBAA = true, + rgb_fn = true, + hsl_fn = true, + css = false, + css_fn = false, + mode = 'background' + } + ) + end +} diff --git a/lua/config/comment.lua b/lua/config/comment.lua index a70d91a..b360fd1 100644 --- a/lua/config/comment.lua +++ b/lua/config/comment.lua @@ -1,11 +1,17 @@ -local config = {} +return { + 'terrortylor/nvim-comment', + requires = 'JoosepAlviste/nvim-ts-context-commentstring', + config = function() + local config = {} -if packer_plugins['nvim-ts-context-commentstring'] and packer_plugins['nvim-ts-context-commentstring'].loaded then - config.hook = function() - if vim.api.nvim_buf_get_option(0, "filetype") == "vue" then - require("ts_context_commentstring.internal").update_commentstring() - end + if packer_plugins['nvim-ts-context-commentstring'] and packer_plugins['nvim-ts-context-commentstring'].loaded then + config.hook = function() + if vim.api.nvim_buf_get_option(0, "filetype") == "vue" then + require("ts_context_commentstring.internal").update_commentstring() + end + end + end + + require("nvim_comment").setup(config) end -end - -require("nvim_comment").setup(config) +} diff --git a/lua/config/devicons.lua b/lua/config/devicons.lua new file mode 100644 index 0000000..aebc460 --- /dev/null +++ b/lua/config/devicons.lua @@ -0,0 +1,4 @@ +return { + 'kyazdani42/nvim-web-devicons', + config = function() require('nvim-web-devicons').setup() end +} diff --git a/lua/config/diffview.lua b/lua/config/diffview.lua new file mode 100644 index 0000000..c1a0435 --- /dev/null +++ b/lua/config/diffview.lua @@ -0,0 +1,9 @@ +return { + "sindrets/diffview.nvim", + requires = 'nvim-lua/plenary.nvim', + config = function() + require("legendary").command{ + ":DiffviewOpen", description = "Open diff view" + } + end +} diff --git a/lua/config/dressing.lua b/lua/config/dressing.lua new file mode 100644 index 0000000..2c88375 --- /dev/null +++ b/lua/config/dressing.lua @@ -0,0 +1,27 @@ +return { + "stevearc/dressing.nvim", + requires = "nvim-telescope/telescope.nvim", + config = function() + require('dressing').setup({ + select = { + get_config = function(opts) + opts = opts or {} + local cfg = { + telescope = { + layout_config = { + -- width = 120, + -- height = 60, + width = 0.87, + height = 0.80, + }, + }, + } + if opts.kind == 'legendary.nvim' then + cfg.telescope.sorter = require('telescope.sorters').fuzzy_with_index_bias({}) + end + return cfg + end, + }, + }) + end +} diff --git a/lua/config/fugitive.lua b/lua/config/fugitive.lua index da0ce8d..54e3136 100644 --- a/lua/config/fugitive.lua +++ b/lua/config/fugitive.lua @@ -1,3 +1,9 @@ -local map = require 'utils.map' - -map('n', 'gg', ':G', { silent = true }) +return { + 'tpope/vim-fugitive', + config = function () + -- TODO: Add most commonly used fugitive bindings + require("legendary").keymaps{ + {"gg", ":G", description = "Open fugitive", opts = {silent = true}} + } + end +} diff --git a/lua/config/gitblame.lua b/lua/config/gitblame.lua index 85729ca..4fe7786 100644 --- a/lua/config/gitblame.lua +++ b/lua/config/gitblame.lua @@ -1,8 +1,22 @@ -local map = require 'utils.map' -local silent = {silent = true} +return { + 'f-person/git-blame.nvim', + config = function () + local silent = {silent = true} -map('n', 'gm', ":GitBlameCopySHA", silent) -map('n', 'gj', ":GitBlameOpenCommitURL", silent) -map('n', 'gu', ":GitBlameToggle", silent) + require("legendary").keymaps{ + { + itemgroup = "gitblame", + description = "Git blame", + icon = "", + keymaps = { + {"gm", ":GitBlameCopySHA", description = "Copy commit hash", opts = silent}, + {"gj", ":GitBlameOpenCommit", description = "Open commit", opts = silent}, + {"gu", ":GitBlameToggle", description = "Toggle git blame", opts = silent}, + } + } + } -vim.g["gitblame_enabled"] = 0 + vim.g["gitblame_enabled"] = 0 + vim.g["gitblame_date_format"] = "%r" + end +} diff --git a/lua/config/gitsigns.lua b/lua/config/gitsigns.lua index 7c3b280..7f84daf 100644 --- a/lua/config/gitsigns.lua +++ b/lua/config/gitsigns.lua @@ -1,33 +1,42 @@ -local gitsigns = require 'gitsigns' +return { + 'lewis6991/gitsigns.nvim', + requires = 'nvim-lua/plenary.nvim', + config = function () + local gitsigns = require 'gitsigns' -gitsigns.setup{ - on_attach = function(bufnr) - local function map(mode, lhs, rhs, opts) - opts = vim.tbl_extend('force', {noremap = true, silent = true}, opts or {}) - vim.api.nvim_buf_set_keymap(bufnr, mode, lhs, rhs, opts) - end + gitsigns.setup{ + on_attach = function(bufnr) + local function keymap_n(key, command, description, opts) + opts = vim.tbl_extend('force', {noremap = true, silent = true, buffer=bufnr}, opts or {}) + return {key, command, description=description, opts=opts} + end + local function keymap_vn(key, command, description, opts) + opts = vim.tbl_extend('force', {noremap = true, silent = true, buffer=bufnr}, opts or {}) + return {key, command, mode={"v", "n"}, description=description, opts=opts} + end - -- Navigation - map('n', ']c', "&diff ? ']c' : 'Gitsigns next_hunk'", {expr=true}) - map('n', '[c', "&diff ? '[c' : 'Gitsigns prev_hunk'", {expr=true}) + require("legendary").keymaps{ + { + itemgroup = "githunks", + description = "Git hunks", + icon = "", + keymaps = { + keymap_n(']c', "&diff ? ']c' : 'Gitsigns next_hunk'", "Jump to next hunk", {expr=true}), + keymap_n('[c', "&diff ? '[c' : 'Gitsigns prev_hunk'", "Jump to prev hunk", {expr=true}), - -- Actions - map('n', 'hs', ':Gitsigns stage_hunk') - map('v', 'hs', ':Gitsigns stage_hunk') - map('n', 'hr', ':Gitsigns reset_hunk') - map('v', 'hr', ':Gitsigns reset_hunk') - map('n', 'hS', 'Gitsigns stage_buffer') - map('n', 'hu', 'Gitsigns undo_stage_hunk') - map('n', 'hR', 'Gitsigns reset_buffer') - map('n', 'hp', 'Gitsigns preview_hunk') - map('n', 'hb', 'lua require"gitsigns".blame_line{full=true}') - map('n', 'tb', 'Gitsigns toggle_current_line_blame') - map('n', 'hd', 'Gitsigns diffthis') - map('n', 'hD', 'lua require"gitsigns".diffthis("~")') - map('n', 'td', 'Gitsigns toggle_deleted') + keymap_vn("hs", ":Gitsigns stage_hunk", "Stage hunk"), + keymap_vn("hr", ":Gitsigns reset_hunk", "Reset hunk"), + keymap_n("hS", "Gitsigns stage_buffer", "Stage buffer"), + keymap_n("hu", "Gitsigns undo_stage_hunk", "Undo stage hunk"), + keymap_n("hR", "Gitsigns reset_buffer", "Reset buffer"), + keymap_n("hp", "Gitsigns preview_hunk", "Preview hunk"), + keymap_n('td', 'Gitsigns toggle_deleted', "Toggle deleted"), - -- Text object - map('o', 'ih', ':Gitsigns select_hunk') - map('x', 'ih', ':Gitsigns select_hunk') + {'ih', {o=':Gitsigns select_hunk', x=':Gitsigns select_hunk'}, description="Select hunk" } + } + } + } + end + } end } diff --git a/lua/config/leap.lua b/lua/config/leap.lua index fbb3e6c..1e52c73 100644 --- a/lua/config/leap.lua +++ b/lua/config/leap.lua @@ -1,3 +1,12 @@ -local silent = {silent=true} -vim.keymap.set("n", "s", "(leap-forward-to)", silent) -vim.keymap.set("n", "S", "(leap-backward-to)", silent) +return { + 'ggandor/leap.nvim', + config = function() + local silent = {silent=true} + + require("legendary").keymaps{ + {"s", "(leap-forward-to)", description="Leap forward", opts=silent}, + {"S", "(leap-backward-to)", description="Leap backward", opts=silent} + } + + end +} diff --git a/lua/config/legendary.lua b/lua/config/legendary.lua new file mode 100644 index 0000000..b9993d3 --- /dev/null +++ b/lua/config/legendary.lua @@ -0,0 +1,12 @@ +return { + 'mrjones2014/legendary.nvim', + requires = 'stevearc/dressing.nvim', + config = function() + require("legendary").setup{ + include_legendary_cmds = false, + keymaps = { + {"l", ":Legendary", description = "Open this help menu"} + } + } + end +} diff --git a/lua/config/lightline.lua b/lua/config/lightline.lua deleted file mode 100644 index bf1ff95..0000000 --- a/lua/config/lightline.lua +++ /dev/null @@ -1,26 +0,0 @@ -local opt = require 'utils.opt' - -opt('showmode', false) - -vim.cmd [[ -function! LightlineFilename() - let filename = expand('%:t') !=# '' ? expand('%:t') : '[No Name]' - let modified = &modified ? ' +' : '' - return filename . modified -endfunction -]] - -vim.g.lightline = { - colorscheme = vim.g.colors_name, - active = { - left = { { 'mode', 'paste' }, { 'gitbranch', 'readonly', 'filename' } } - }, - component_function = { - gitbranch = 'FugitiveHead', - filename = 'LightlineFilename' - }, - tabline = { - right = {} - } -} - diff --git a/lua/config/lspconfig.lua b/lua/config/lspconfig.lua index facd74a..15777bd 100644 --- a/lua/config/lspconfig.lua +++ b/lua/config/lspconfig.lua @@ -87,20 +87,31 @@ end ---@diagnostic disable-next-line: unused-local function M.on_attach(client, bufnr) -- Mappings. - local opts = { noremap = true, silent = true } + local opts = { noremap = true, silent = true, buffer = bufnr} - local function buf_set_keymap(mode, lhs, rhs) vim.api.nvim_buf_set_keymap(bufnr, mode, lhs, rhs, opts) end + -- local function keymap(mode, lhs, rhs) vim.api.nvim_buf_set_keymap(bufnr, mode, lhs, rhs, opts) end local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end + require("legendary").keymaps{ + { + itemgroup = "lsp", + description = "LSP", + keymaps = { + {'gd', 'lua vim.lsp.buf.definition()', description = "Jump to definition", opts=opts}, + {'gD', 'lua vim.lsp.buf.declaration()', description = "Jump to declaration", opts=opts}, + {'gi', 'lua vim.lsp.buf.implementation()', description = "Jump to implementation", opts=opts}, + {'K', 'lua vim.lsp.buf.hover()', description = "Show info", opts=opts}, + {'rn', 'lua vim.lsp.buf.rename()', description = "Rename symbol"}, + {'ca', 'lua vim.lsp.buf.code_action()', description = "Show code actions"}, + {'d', 'lua vim.diagnostic.open_float()', description = "Open float"} + } + } + } + -- Enable completion triggered by buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc') -- See `:help vim.lsp.*` for documentation on any of the below functions - buf_set_keymap('n', 'gd', 'lua vim.lsp.buf.definition()') - buf_set_keymap('n', 'gD', 'lua vim.lsp.buf.declaration()') - buf_set_keymap('n', 'gr', 'lua vim.lsp.buf.references()') - buf_set_keymap('n', 'gi', 'lua vim.lsp.buf.implementation()') - buf_set_keymap('n', 'K', 'lua vim.lsp.buf.hover()') -- Conflicts with movement between panes -- buf_set_keymap('n', '', 'lua vim.lsp.buf.signature_help()') @@ -109,9 +120,6 @@ function M.on_attach(client, bufnr) -- buf_set_keymap('n', 'wr', 'lua vim.lsp.buf.remove_workspace_folder()') -- buf_set_keymap('n', 'wl', 'lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))') -- buf_set_keymap('n', 'D', 'lua vim.lsp.buf.type_definition()') - buf_set_keymap('n', 'rn', 'lua vim.lsp.buf.rename()') - buf_set_keymap('n', 'ca', 'lua vim.lsp.buf.code_action()') - buf_set_keymap('n', 'd', 'lua vim.diagnostic.open_float()') -- buf_set_keymap('n', '[d', 'lua vim.lsp.diagnostic.goto_prev()') -- buf_set_keymap('n', ']d', 'lua vim.lsp.diagnostic.goto_next()') -- buf_set_keymap('n', 'q', 'lua vim.lsp.diagnostic.set_loclist()') diff --git a/lua/config/lspinstaller.lua b/lua/config/lspinstaller.lua index e6bb58e..4d4292a 100644 --- a/lua/config/lspinstaller.lua +++ b/lua/config/lspinstaller.lua @@ -1,7 +1,6 @@ -local lspconfig_config = require 'config.lspconfig' -local lsp_installer = require 'nvim-lsp-installer' -local lsp_installer_servers = require'nvim-lsp-installer.servers' -local M = {} +local lspconfig_config = require('config.lspconfig') +local lsp_installer = require('nvim-lsp-installer') +local lsp_installer_servers = require('nvim-lsp-installer.servers') -- local autoinstall_servers = {"sumneko_lua", "efm"} local autoinstall_servers = {"sumneko_lua"} @@ -17,8 +16,8 @@ local capabilities = lspconfig_config.get_capabilities() for _, server in ipairs(lsp_installer.get_installed_servers()) do local opts = { root_dir = function() - return vim.fn.getcwd() - end, + return vim.fn.getcwd() + end, init_options = lspconfig_config.get_server_init_options(server.name), on_attach = lspconfig_config.on_attach, on_init = lspconfig_config.on_init, @@ -38,5 +37,3 @@ for _, server in ipairs(lsp_installer.get_installed_servers()) do server:setup(opts) ::continue:: end - -return M diff --git a/lua/config/lspsignature.lua b/lua/config/lspsignature.lua index 122669c..14bd77c 100644 --- a/lua/config/lspsignature.lua +++ b/lua/config/lspsignature.lua @@ -1,4 +1,18 @@ -require "lsp_signature".setup{ - hint_enable = false, - toggle_key = '' +return { + "ray-x/lsp_signature.nvim", + config = function() + local lsp_signature = require("lsp_signature") + + lsp_signature.setup{ + hint_enable = false, + toggle_key = nil, + handler_opts = { + border = { " ", " ", " ", " ", " ", " ", " ", " " } + } + } + + require("legendary").keymap{ + "", lsp_signature.toggle_float_win, description="Toggle signature float" + } + end } diff --git a/lua/config/lsputils.lua b/lua/config/lsputils.lua index dc91e60..d3dd310 100644 --- a/lua/config/lsputils.lua +++ b/lua/config/lsputils.lua @@ -1,43 +1,14 @@ -if vim.fn.has('nvim-0.5.1') == 1 then - vim.lsp.handlers['textDocument/codeAction'] = require'lsputil.codeAction'.code_action_handler - vim.lsp.handlers['textDocument/references'] = require'lsputil.locations'.references_handler - vim.lsp.handlers['textDocument/definition'] = require'lsputil.locations'.definition_handler - vim.lsp.handlers['textDocument/declaration'] = require'lsputil.locations'.declaration_handler - vim.lsp.handlers['textDocument/typeDefinition'] = require'lsputil.locations'.typeDefinition_handler - vim.lsp.handlers['textDocument/implementation'] = require'lsputil.locations'.implementation_handler - vim.lsp.handlers['textDocument/documentSymbol'] = require'lsputil.symbols'.document_handler - vim.lsp.handlers['workspace/symbol'] = require'lsputil.symbols'.workspace_handler -else - local bufnr = vim.api.nvim_buf_get_number(0) - vim.lsp.handlers['textDocument/codeAction'] = function(_, _, actions) - require('lsputil.codeAction').code_action_handler(nil, actions, nil, nil, nil) +return { + 'RishabhRD/nvim-lsputils', + requires = 'RishabhRD/popfix', + config = function() + vim.lsp.handlers['textDocument/codeAction'] = require'lsputil.codeAction'.code_action_handler + vim.lsp.handlers['textDocument/references'] = require'lsputil.locations'.references_handler + vim.lsp.handlers['textDocument/definition'] = require'lsputil.locations'.definition_handler + vim.lsp.handlers['textDocument/declaration'] = require'lsputil.locations'.declaration_handler + vim.lsp.handlers['textDocument/typeDefinition'] = require'lsputil.locations'.typeDefinition_handler + vim.lsp.handlers['textDocument/implementation'] = require'lsputil.locations'.implementation_handler + vim.lsp.handlers['textDocument/documentSymbol'] = require'lsputil.symbols'.document_handler + vim.lsp.handlers['workspace/symbol'] = require'lsputil.symbols'.workspace_handler end - - vim.lsp.handlers['textDocument/references'] = function(_, _, result) - require('lsputil.locations').references_handler(nil, result, { bufnr = bufnr }, nil) - end - - vim.lsp.handlers['textDocument/definition'] = function(_, method, result) - require('lsputil.locations').definition_handler(nil, result, { bufnr = bufnr, method = method }, nil) - end - - vim.lsp.handlers['textDocument/declaration'] = function(_, method, result) - require('lsputil.locations').declaration_handler(nil, result, { bufnr = bufnr, method = method }, nil) - end - - vim.lsp.handlers['textDocument/typeDefinition'] = function(_, method, result) - require('lsputil.locations').typeDefinition_handler(nil, result, { bufnr = bufnr, method = method }, nil) - end - - vim.lsp.handlers['textDocument/implementation'] = function(_, method, result) - require('lsputil.locations').implementation_handler(nil, result, { bufnr = bufnr, method = method }, nil) - end - - vim.lsp.handlers['textDocument/documentSymbol'] = function(_, _, result, _, bufn) - require('lsputil.symbols').document_handler(nil, result, { bufnr = bufn }, nil) - end - - vim.lsp.handlers['textDocument/symbol'] = function(_, _, result, _, bufn) - require('lsputil.symbols').workspace_handler(nil, result, { bufnr = bufn }, nil) - end -end +} diff --git a/lua/config/lualine.lua b/lua/config/lualine.lua new file mode 100644 index 0000000..c2a47b7 --- /dev/null +++ b/lua/config/lualine.lua @@ -0,0 +1,161 @@ +local bg = vim.g.srcery_xgray1 + +local colors = { + red = vim.g.srcery_red, + grey = vim.g.srcery_black, + black = vim.g.srcery_hard_black, + white = vim.g.srcery_bright_white, + light_green = vim.g.srcery_bright_green, + orange = vim.g.srcery_orange, + green = vim.g.srcery_green, +} + +local theme = { + normal = { + a = { fg = colors.white, bg = colors.black }, + b = { fg = colors.white, bg = colors.grey }, + c = { fg = colors.black, bg = bg }, + z = { fg = colors.white, bg = colors.black }, + }, + insert = { a = { fg = colors.black, bg = colors.light_green } }, + visual = { a = { fg = colors.black, bg = colors.orange } }, + replace = { a = { fg = colors.black, bg = colors.green } }, +} + +local empty = require('lualine.component'):extend() +function empty:draw(default_highlight) + self.status = '' + self.applied_separator = '' + self:apply_highlights(default_highlight) + self:apply_section_separators() + return self.status +end + +-- Put proper separators and gaps between components in sections +local function process_sections(sections) + for name, section in pairs(sections) do + local left = name:sub(9, 10) < 'x' + for pos = 1, name ~= 'lualine_z' and #section or #section - 1 do + table.insert(section, pos * 2, { empty, color = { fg = bg, bg = bg } }) + end + for id, comp in ipairs(section) do + if type(comp) ~= 'table' then + comp = { comp } + section[id] = comp + end + comp.separator = left and { right = '' } or { left = '' } + end + end + return sections +end + +local function search_result() + local last_search = vim.fn.getreg('/') + if not last_search or last_search == '' then + return '' + end + local searchcount = vim.fn.searchcount { maxcount = 9999 } + if searchcount.total == 0 then + return '' + end + return last_search .. '(' .. searchcount.current .. '/' .. searchcount.total .. ')' +end + +local function modified() + if vim.bo.modified then + return '+' + elseif vim.bo.modifiable == false or vim.bo.readonly == true then + return '-' + end + return '' +end + +local function recording_macro() + local reg = vim.api.nvim_call_function("reg_recording", {}) + if reg ~= "" then + return "@" .. reg + else + return "" + end +end + +local extensions = {"man", "quickfix"} +if pcall(require, "nvim-tree") then + table.insert(extensions, "nvim-tree") +end +if pcall(require, "toggleterm") then + table.insert(extensions, "toggleterm") +end +if pcall(require, "luapad.statusline") then + table.insert(extensions, { + sections = process_sections { + lualine_a = {'mode'}, + lualine_b = { + { + 'diagnostics', + source = { 'nvim' }, + sections = { 'error' }, + diagnostics_color = { error = { bg = colors.red, fg = colors.white } }, + }, + { + 'diagnostics', + source = { 'nvim' }, + sections = { 'warn' }, + diagnostics_color = { warn = { bg = colors.orange, fg = colors.white } }, + }, + { recording_macro, color = { bg = colors.orange } } + }, + lualine_y = { search_result, 'filetype' }, + lualine_z = { '%l:%c', '%p%%/%L' }, + }, + filetypes = {'lua.luapad'} + }) +end + +require('lualine').setup { + options = { + theme = theme, + component_separators = '', + section_separators = { left = '', right = '' }, + -- ignore_focus = {"NvimTree"}, + globalstatus = true + }, + sections = process_sections { + lualine_a = { 'mode' }, + lualine_b = { + 'branch', + 'diff', + { + 'diagnostics', + source = { 'nvim' }, + sections = { 'error' }, + diagnostics_color = { error = { bg = colors.red, fg = colors.white } }, + }, + { + 'diagnostics', + source = { 'nvim' }, + sections = { 'warn' }, + diagnostics_color = { warn = { bg = colors.orange, fg = colors.white } }, + }, + { 'filename', file_status = false, path = 1 }, + { modified, color = { bg = colors.red } }, + { '%w', cond = function() return vim.wo.previewwindow end }, + { '%r', cond = function() return vim.bo.readonly end }, + { '%q', cond = function() return vim.bo.buftype == 'quickfix' end }, + { recording_macro, color = { bg = colors.orange } } + }, + lualine_c = {}, + lualine_x = {}, + lualine_y = { search_result, 'filetype' }, + lualine_z = { '%l:%c', '%p%%/%L' }, + }, + inactive_sections = { + lualine_a = {}, + lualine_b = {}, + lualine_c = {}, + lualine_x = {}, + lualine_y = {}, + lualine_z = {}, + }, + extensions = extensions +} diff --git a/lua/config/luapad.lua b/lua/config/luapad.lua new file mode 100644 index 0000000..3ef3994 --- /dev/null +++ b/lua/config/luapad.lua @@ -0,0 +1,15 @@ +local pattern = "^/tmp/.*/%d+_Luapad%.lua$" +local group = vim.api.nvim_create_augroup("LuaPadFiletype", {clear=true}) +vim.api.nvim_create_autocmd("FileType", { + group = group, + callback = function(data) + if data.file:match(pattern) then + vim.bo[data.buf].filetype = "lua.luapad" + end + end +}) + +require("legendary").commands{ + { ":Luapad", description = "Open interactive lua" }, + { ":LuaRun", description = "Run lua from current buffer" } +} diff --git a/lua/config/luasnip.lua b/lua/config/luasnip.lua index a1f9e7b..87285c7 100644 --- a/lua/config/luasnip.lua +++ b/lua/config/luasnip.lua @@ -1,92 +1,99 @@ -local ls = require("luasnip") -local capture = require("utils.capture") -local s = ls.snippet -local sn = ls.snippet_node -local fmt = require("luasnip.extras.fmt").fmt -local t = ls.text_node -local i = ls.insert_node -local f = ls.function_node -local c = ls.choice_node -local d = ls.dynamic_node +local function config() + local ls = require("luasnip") + local capture = require("utils.capture") + local s = ls.snippet + local sn = ls.snippet_node + local fmt = require("luasnip.extras.fmt").fmt + local t = ls.text_node + local i = ls.insert_node + local f = ls.function_node + local c = ls.choice_node + local d = ls.dynamic_node -local function getCurrentYear() - return os.date("%Y") -end - -local function getGitUsername() - local stdout = capture("git config user.name") - if stdout == "" then - return nil + local function getCurrentYear() + return os.date("%Y") end - return stdout -end -ls.config.set_config { - history = true, - updateevents = "TextChanged,TextChangedI", - enable_autosnippets = true -} - -vim.keymap.set({"i", "s"}, "", function() - if ls.expand_or_jumpable() then - ls.expand_or_jump() + local function getGitUsername() + local stdout = capture("git config user.name") + if stdout == "" then + return nil + end + return stdout end -end, { silent = true }) -vim.keymap.set({ "i", "s" }, "", function() - if ls.jumpable(-1) then - ls.jump(-1) - end -end, { silent = -1 }) + ls.config.set_config { + history = true, + updateevents = "TextChanged,TextChangedI", + enable_autosnippets = true + } -vim.keymap.set({"i"}, "", function() - if ls.choice_active() then - ls.change_choice(1) - end -end) + vim.keymap.set({"i", "s"}, "", function() + if ls.expand_or_jumpable() then + ls.expand_or_jump() + end + end, { silent = true }) -ls.add_snippets("all", { - s("MIT", { - t({"The MIT License (MIT)", "Copyright © "}), - f(getCurrentYear, {}), - t(" "), - d(1, function() - return sn(nil, { - i(1, getGitUsername() or "") - }) - end, {}), - t{ - "", - "", - "Permission is hereby granted, free of charge, to any person obtaining a copy of", - "this software and associated documentation files (the “Software”), to deal in", - "the Software without restriction, including without limitation the rights to", - "use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies", - "of the Software, and to permit persons to whom the Software is furnished to do", - "so, subject to the following conditions:", - "", - "The above copyright notice and this permission notice shall be included in all", - "copies or substantial portions of the Software.", - "", - "THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR", - "IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,", - "FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE", - "AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER", - "LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,", - "OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE", - "SOFTWARE.", - } - }) -}) + vim.keymap.set({ "i", "s" }, "", function() + if ls.jumpable(-1) then + ls.jump(-1) + end + end, { silent = -1 }) -ls.add_snippets("lua", { - s("req", - fmt([[local {} = require("{}")]], { - f(function(module_name) - local parts = vim.split(module_name[1][1], ".", true) - return (parts[#parts] or ""):gsub("-", "_") - end, { 1 }), - i(1) + vim.keymap.set({"i"}, "", function() + if ls.choice_active() then + ls.change_choice(1) + end + end) + + ls.add_snippets("all", { + s("MIT", { + t({"The MIT License (MIT)", "Copyright © "}), + f(getCurrentYear, {}), + t(" "), + d(1, function() + return sn(nil, { + i(1, getGitUsername() or "") + }) + end, {}), + t{ + "", + "", + "Permission is hereby granted, free of charge, to any person obtaining a copy of", + "this software and associated documentation files (the “Software”), to deal in", + "the Software without restriction, including without limitation the rights to", + "use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies", + "of the Software, and to permit persons to whom the Software is furnished to do", + "so, subject to the following conditions:", + "", + "The above copyright notice and this permission notice shall be included in all", + "copies or substantial portions of the Software.", + "", + "THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR", + "IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,", + "FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE", + "AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER", + "LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,", + "OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE", + "SOFTWARE.", + } }) - ) -}) + }) + + ls.add_snippets("lua", { + s("req", + fmt([[local {} = require("{}")]], { + f(function(module_name) + local parts = vim.split(module_name[1][1], ".", true) + return (parts[#parts] or ""):gsub("-", "_") + end, { 1 }), + i(1) + }) + ) + }) +end + +return { + 'L3MON4D3/LuaSnip', + config = config +} diff --git a/lua/config/move.lua b/lua/config/move.lua new file mode 100644 index 0000000..49aeadf --- /dev/null +++ b/lua/config/move.lua @@ -0,0 +1,11 @@ +return { + 'fedepujol/move.nvim', + config = function() + local opts = { noremap = true, silent = true } + + require("legendary").keymaps{ + {mode='v', '', ':MoveBlock(1)', description = "Move block up", opts=opts}, + {mode='v', '', ':MoveBlock(-1)', description = "Move block down", opts=opts}, + } + end +} diff --git a/lua/config/nvim-tree.lua b/lua/config/nvim-tree.lua index 7fa61af..5271c87 100644 --- a/lua/config/nvim-tree.lua +++ b/lua/config/nvim-tree.lua @@ -1,13 +1,19 @@ -local map = require("utils.map") +return { + 'kyazdani42/nvim-tree.lua', + requires = 'kyazdani42/nvim-web-devicons', + config = function () + require("nvim-tree").setup{ + git = { + enable = false + }, + renderer = { + group_empty = true, + }, + } -require("nvim-tree").setup{ - git = { - enable = false - }, - renderer = { - group_empty = true, - }, + require("legendary").keymaps{ + {"e", ":NvimTreeToggle", description = "Toggle file tree", {silent = true}}, + {"f", ":NvimTreeFindFileToggle", description = "Show file in tree", {silent = true}} + } + end } - -map("n", "e", ":NvimTreeToggle", {silent = true}) -map("n", "f", ":NvimTreeFindFileToggle", {silent = true}) diff --git a/lua/config/quickscope.lua b/lua/config/quickscope.lua index 0390c0b..a78d999 100644 --- a/lua/config/quickscope.lua +++ b/lua/config/quickscope.lua @@ -1,8 +1,9 @@ -local g = vim.g -local cmd = vim.cmd - --- Trigger a highlight in the appropriate direction when pressing these keys: -g['qs_highlight_on_keys'] = {'f', 'F', 't', 'T'} - -g['qs_max_chars'] = 150 +return { + 'unblevable/quick-scope', + config = function () + -- Trigger a highlight in the appropriate direction when pressing these keys: + vim.g['qs_highlight_on_keys'] = {'f', 'F', 't', 'T'} + vim.g['qs_max_chars'] = 150 + end +} diff --git a/lua/config/refactoring.lua b/lua/config/refactoring.lua deleted file mode 100644 index 617fc92..0000000 --- a/lua/config/refactoring.lua +++ /dev/null @@ -1,39 +0,0 @@ -local refactoring = require("refactoring") -refactoring.setup() - --- telescope refactoring helper -local function refactor(prompt_bufnr) - local content = require("telescope.actions.state").get_selected_entry( - prompt_bufnr - ) - require("telescope.actions").close(prompt_bufnr) - require("refactoring").refactor(content.value) -end - --- NOTE: M is a global object --- for the sake of simplicity in this example --- you can extract this function and the helper above --- and then require the file and call the extracted function --- in the mappings below -M = {} -M.refactors = function() - local opts = require("telescope.themes").get_cursor() -- set personal telescope options - require("telescope.pickers").new(opts, { - prompt_title = "refactors", - finder = require("telescope.finders").new_table({ - results = require("refactoring").get_refactors(), - }), - sorter = require("telescope.config").values.generic_sorter(opts), - attach_mappings = function(_, map) - map("i", "", refactor) - map("n", "", refactor) - return true - end - }):find() -end - -vim.api.nvim_set_keymap("v", "re", [[ lua require('refactoring').refactor('Extract Function')]], {noremap = true, silent = true, expr = false}) -vim.api.nvim_set_keymap("v", "rf", [[ lua require('refactoring').refactor('Extract Function To File')]], {noremap = true, silent = true, expr = false}) -vim.api.nvim_set_keymap("v", "rt", [[ lua M.refactors()]], {noremap = true, silent = true, expr = false}) - -return M diff --git a/lua/config/reload.lua b/lua/config/reload.lua deleted file mode 100644 index 943d5e9..0000000 --- a/lua/config/reload.lua +++ /dev/null @@ -1,6 +0,0 @@ -local map = require 'utils.map' - -map('n', 'rc', ':Restart', {silent = true}) - -vim.cmd [[command! PackerRestart exe 'Restart' | exe 'PackerCompile' | exe 'PackerSync']] - diff --git a/lua/config/sneak.lua b/lua/config/sneak.lua deleted file mode 100644 index 314f8aa..0000000 --- a/lua/config/sneak.lua +++ /dev/null @@ -1,23 +0,0 @@ -local map = require 'utils.map' -local g = vim.g - -g['sneak#label'] = 1 - --- case insensitive sneak -g['sneak#use_ic_scs'] = 1 - --- immediately move to the next instance of search, if you move the cursor sneak is back to default behavior -g['sneak#s_next'] = 1 - --- remap so I can use , and ; with f and t -map({'n', 'v'}, 'gS', 'Sneak_;') -map({'n', 'v'}, 'gs', 'Sneak_;') --- map gS Sneak_, --- map gs Sneak_; - --- highlight Sneak guifg=black guibg=#00C7DF ctermfg=black ctermbg=cyan --- highlight SneakScope guifg=red guibg=yellow ctermfg=red ctermbg=yellow - --- Emoji prompt -g['sneak#prompt'] = '🔎' - diff --git a/lua/config/telescope.lua b/lua/config/telescope.lua index d10f2c8..df715f3 100644 --- a/lua/config/telescope.lua +++ b/lua/config/telescope.lua @@ -1,99 +1,115 @@ local telescope = require('telescope') -local map = require('utils.map') local actions = require('telescope.actions') local builtin = require('telescope.builtin') -local previewers = require('telescope.previewers') -local M = {} - -local function sizelimit_maker(filepath, bufnr, opts) - opts = opts or {} - local size_limit = 100 * 1024 -- 100KiB - - filepath = vim.fn.expand(filepath) - vim.loop.fs_stat(filepath, function(_, stat) - if not stat then return end - if stat.size > size_limit then - return - else - previewers.buffer_previewer_maker(filepath, bufnr, opts) - end - end) -end -- Falling back to find_files if git_files can't find a .git directory -function M.project_files(opts) - local ok = pcall(builtin.git_files, opts) - if not ok then builtin.find_files(opts) end +local function project_files() + local opts = { prompt_title = 'Project files' } + local ok = pcall(builtin.git_files, opts) + if not ok then builtin.find_files(opts) end end -function M.edit_config(_opts) +local function edit_config() return M.project_files{ cwd = "~/.config/nvim", prompt_title = "Neovim config" } end -local silent = {silent = true} - --- Search project files -map('n', '', [[:lua require('config.telescope').project_files{ prompt_title = 'Project files' }]], silent) - --- Search files from current working directory -map('n', 'p', [[:lua require('telescope.builtin').find_files()]], silent) - --- Edit neovim config -map('n', 'ce', [[:lua require('config.telescope').edit_config()]], silent) - --- Find string -map('n', 'fw', [[:lua require('telescope.builtin').live_grep()]], silent) - --- Change colorscheme -map('n', 'cs', [[:lua require('telescope.builtin').colorscheme()]], silent) - --- See help tags -map('n', 'fh', [[:lua require('telescope.builtin').help_tags()]], silent) - telescope.setup{ defaults = { - buffer_previewer_maker = sizelimit_maker, - path_display = { "shorten" }, + vimgrep_arguments = { + "rg", + "-L", + "--color=never", + "--no-heading", + "--with-filename", + "--line-number", + "--column", + "--smart-case", + }, + prompt_prefix = "  ", + selection_caret = " ", + entry_prefix = " ", + initial_mode = "insert", + selection_strategy = "reset", + sorting_strategy = "ascending", + layout_strategy = "horizontal", + layout_config = { + horizontal = { + prompt_position = "top", + preview_width = 0.55, + results_width = 0.8, + }, + vertical = { mirror = false }, + width = 0.87, + height = 0.80, + preview_cutoff = 120, + }, + file_sorter = require("telescope.sorters").get_fuzzy_file, + file_ignore_patterns = { "node_modules" }, + generic_sorter = require("telescope.sorters").get_generic_fuzzy_sorter, + path_display = { "truncate" }, color_devicons = true, + winblend = 0, + border = {}, + borderchars = { "─", "│", "─", "│", "╭", "╮", "╯", "╰" }, + set_env = { ["COLORTERM"] = "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, + -- Developer configurations: Not meant for general override + buffer_previewer_maker = require("telescope.previewers").buffer_previewer_maker, mappings = { - i = { - [""] = actions.close - } - } + i = { [""] = actions.close } + }, }, pickers = { - find_files = { - theme = "dropdown", - }, - marks = { - theme = "dropdown", - }, - help_tags = { - theme = "dropdown", - }, - oldfiles = { - theme = "dropdown", - }, - git_files = { - theme = "dropdown", - }, live_grep = { - theme = "dropdown", disable_coordinates = true }, colorscheme = { - theme = "dropdown", enable_preview = true } + }, + extensions = { + ["ui-select"] = { + require("telescope.themes").get_dropdown {} + } } } +telescope.load_extension("ui-select") + local fzfPlugin = packer_plugins["telescope-fzf-native.nvim"] if fzfPlugin and fzfPlugin.loaded then telescope.load_extension('fzf') end -return M + +local keymaps = { + -- Search project files + { "", project_files, description = "Open git files" }, + + -- Search files from current working directory + { "p", function() builtin.find_files() end, description = "Open files" }, + + -- Edit neovim config + {"ce", edit_config, description = "Edit neovim config" }, + + -- Grep string + { "fw", function() builtin.live_grep() end, description = "Grep" }, + + -- Change colorscheme + { "cs", function() builtin.colorscheme() end, description = "Change colorscheme" }, + + -- See help tags + { "fh", function() builtin.help_tags() end, description = "Search help tags" } +} + +local silent = {silent = true} +for _, keymap in ipairs(keymaps) do + keymap.opts = silent +end + +require("legendary").keymaps(keymaps) diff --git a/lua/config/tidy.lua b/lua/config/tidy.lua new file mode 100644 index 0000000..f44885e --- /dev/null +++ b/lua/config/tidy.lua @@ -0,0 +1,4 @@ +return { + "mcauley-penney/tidy.nvim", + config = function() require("tidy").setup() end +} diff --git a/lua/config/todo-comments.lua b/lua/config/todo-comments.lua new file mode 100644 index 0000000..2081f9d --- /dev/null +++ b/lua/config/todo-comments.lua @@ -0,0 +1,11 @@ +return { + "folke/todo-comments.nvim", + requires = "nvim-lua/plenary.nvim", + config = function() + require("todo-comments").setup { signs = false } + + require("legendary").command{ + ":TodoTelescope", description = "Show TODO's in telescope" + } + end +} diff --git a/lua/config/toggleterm.lua b/lua/config/toggleterm.lua index 22ddcba..8da2232 100644 --- a/lua/config/toggleterm.lua +++ b/lua/config/toggleterm.lua @@ -1,3 +1,11 @@ -require('toggleterm').setup() +return { + 'akinsho/toggleterm.nvim', + tag = '*', + config = function() + require('toggleterm').setup() -vim.keymap.set("n", "t", ":ToggleTerm") + require("legendary").keymap{ + "t", ":ToggleTerm", description = "Toggle terminal", opts = { silent = true } + } + end +} diff --git a/lua/config/treesitter.lua b/lua/config/treesitter.lua index 9d1d955..a35f111 100644 --- a/lua/config/treesitter.lua +++ b/lua/config/treesitter.lua @@ -1,6 +1,12 @@ -local treesitter = require("nvim-treesitter.configs") +return { + 'nvim-treesitter/nvim-treesitter', + run = function() require('nvim-treesitter.install').update{ with_sync = true } end, + config = function () + local treesitter = require("nvim-treesitter.configs") -treesitter.setup{ - highlight = { enable = true }, - auto_install = true + treesitter.setup{ + highlight = { enable = true }, + auto_install = true + } + end } diff --git a/lua/config/trouble.lua b/lua/config/trouble.lua index a0b4d46..324ce86 100644 --- a/lua/config/trouble.lua +++ b/lua/config/trouble.lua @@ -1,9 +1,15 @@ -local map = require 'utils.map' +return { + 'folke/trouble.nvim', + requires = 'kyazdani42/nvim-web-devicons', + config = function () + require('trouble').setup() -require('trouble').setup() + local silent = {silent = true} -local silent = {silent = true} - -map('n', 'qq', ':TroubleToggle document_diagnostics', silent) -map('n', 'qf', ':TroubleToggle workspace_diagnostics', silent) -map('n', 'rf', ':TroubleToggle lsp_references', silent) + require("legendary").keymaps{ + {'qq', ':TroubleToggle document_diagnostics', description="Toggle file diagnostics", opts=silent}, + {'qf', ':TroubleToggle workspace_diagnostics', description="Toggle workspace diagnostics", opts=silent}, + {'gr', ':TroubleToggle lsp_references', description="Show references in trouble", opts=silent}, + } + end +} diff --git a/lua/config/ts-playground.lua b/lua/config/ts-playground.lua new file mode 100644 index 0000000..9b48306 --- /dev/null +++ b/lua/config/ts-playground.lua @@ -0,0 +1,5 @@ +return { + 'nvim-treesitter/playground', + requires = 'nvim-treesitter/nvim-treesitter', + cmd = "TSPlaygroundToggle" +} diff --git a/lua/config/twilight.lua b/lua/config/twilight.lua deleted file mode 100644 index 88fe653..0000000 --- a/lua/config/twilight.lua +++ /dev/null @@ -1,2 +0,0 @@ -require("twilight").setup{ -} diff --git a/lua/config/vimspector.lua b/lua/config/vimspector.lua deleted file mode 100644 index 17438ef..0000000 --- a/lua/config/vimspector.lua +++ /dev/null @@ -1,2 +0,0 @@ -local g = vim.g -g['vimspector_enable_mappings']="HUMAN" diff --git a/lua/config/zen-mode.lua b/lua/config/zen-mode.lua deleted file mode 100644 index 7aee0a5..0000000 --- a/lua/config/zen-mode.lua +++ /dev/null @@ -1,13 +0,0 @@ -local map = require 'utils.map' - -require("zen-mode").setup{ - window = { - options = { - number = false, - relativenumber = false, - cursorline = false - } - } -} - -map('n', 'z', ':ZenMode') diff --git a/lua/disable-builtin.lua b/lua/disable-builtin.lua new file mode 100644 index 0000000..6c6fe83 --- /dev/null +++ b/lua/disable-builtin.lua @@ -0,0 +1,11 @@ +local disabled_built_ins = { + 'matchit', + 'netrw', + 'netrwPlugin', + 'netrwSettings', + 'netrwFileHandlers', +} + +for _, name in ipairs(disabled_built_ins) do + vim.g['loaded_' .. name] = 1 +end diff --git a/lua/options.lua b/lua/options.lua index 6af6edc..a11edb3 100644 --- a/lua/options.lua +++ b/lua/options.lua @@ -117,3 +117,12 @@ if vim.g.neovide then vim.g.neovide_scale_factor = 0.75 vim.g.neovide_hide_mouse_when_typing = true end + +-- Change c file comment string +vim.api.nvim_create_autocmd("FileType", { + group = vim.api.nvim_create_augroup("set-c-commentstring", { clear = true }), + pattern = {"c", "cc", "cpp", "h", "hpp"}, + callback = function(data) + vim.api.nvim_buf_set_option(data.buf, "commentstring", "// %s") + end +}) diff --git a/lua/add-guard.lua b/lua/personal/add-guard.lua similarity index 100% rename from lua/add-guard.lua rename to lua/personal/add-guard.lua diff --git a/lua/cmacro-align.lua b/lua/personal/cmacro-align.lua similarity index 94% rename from lua/cmacro-align.lua rename to lua/personal/cmacro-align.lua index 8c4a2d3..ddc05df 100644 --- a/lua/cmacro-align.lua +++ b/lua/personal/cmacro-align.lua @@ -1,5 +1,8 @@ local ts = vim.treesitter -local query = ts.parse_query("c", "(preproc_function_def value: (preproc_arg) @macro_def)") +local query = ts.parse_query("c", [[ +(preproc_function_def value: (preproc_arg) @macro_def) +(preproc_def value: (preproc_arg) @macro_def) +]]) local function get_ast_root(bufnr) local tree = ts.get_parser(bufnr, "c"):parse() diff --git a/lua/pludin-dev.lua b/lua/pludin-dev.lua index 5106c89..0d6b64b 100644 --- a/lua/pludin-dev.lua +++ b/lua/pludin-dev.lua @@ -1,6 +1,5 @@ -local map = require 'utils.map' -map("n", "x", ":w:source %") +vim.keymap.set("n", "x", ":w:source %", { silent = true }) function P(...) print(vim.inspect(...)) diff --git a/lua/plugin-manager.lua b/lua/plugin-manager.lua new file mode 100644 index 0000000..7e397d4 --- /dev/null +++ b/lua/plugin-manager.lua @@ -0,0 +1,88 @@ +-- Register custom commands for plugin manager +vim.cmd [[command! -bang -nargs=+ -complete=customlist,v:lua.require'plugin-manager'.loader_complete PackerLoad lua require('plugin-manager').loader(, '' == '!')]] +vim.cmd [[command! PackerInstall packadd packer.nvim | lua require('plugin-manager').install()]] +vim.cmd [[command! PackerUpdate packadd packer.nvim | lua require('plugin-manager').update()]] +vim.cmd [[command! PackerSync packadd packer.nvim | lua require('plugin-manager').sync()]] +vim.cmd [[command! PackerClean packadd packer.nvim | lua require('plugin-manager').clean()]] +vim.cmd [[command! PackerCompile source lua/plugin-manager.lua | packadd packer.nvim | lua require('plugin-manager').compile()]] + +-- Bootstrap packer.nvim. If packer.nvim is not installed, install it. +local function bootstrap() + local fn = vim.fn + local install_path = fn.stdpath('data')..'/site/pack/packer/start/packer.nvim' + if fn.empty(fn.glob(install_path)) > 0 then + return fn.system({'git', 'clone', '--depth', '1', 'https://github.com/wbthomason/packer.nvim', install_path}) + end +end + +local function create_custom_use(use) + return function (opts) + if type(opts) == "string" then + use(opts) + return opts + elseif type(opts) == "table" then + if opts.load_config then + local name = vim.split(opts[1], "/")[2] + if name:match("%.nvim$") then + name = name:sub(1, -6) + end + opts.config_name = name + end + if opts.config_name then + opts.config = ("require('config.%s')"):format(opts.config_name) + end + use(opts) + + return opts[1] + else + error("What are you doing???") + end + end +end + +local packer = nil +local function init() + -- Perform bootstrap + local packer_bootstrap = bootstrap() + + -- Initialize packer + if packer == nil then + packer = require 'packer' + local util = require 'packer.util' + packer.init { + compile_path = util.join_paths(vim.fn.stdpath('config'), 'plugin', 'packer-compiled.lua'), + disable_commands = true + } + end + + -- Reset plugins if already loaded + packer.reset() + + -- Packer can manage itself + packer.use 'wbthomason/packer.nvim' + + -- Use plugins + local use = create_custom_use(packer.use) + for _, module_name in ipairs{"plugins", "plugins-local"} do + local ok, use_plugins = pcall(require, module_name) + if ok then + assert(type(use_plugins) == "function") + use_plugins(use) + end + end + + -- Automatically set up your configuration after cloning packer.nvim + -- Put this at the end after all plugins + if packer_bootstrap then + require('packer').sync() + end +end + +local plugins = setmetatable({}, { + __index = function(_, key) + init() + return packer[key] + end +}) + +return plugins diff --git a/lua/plugins-local.lua b/lua/plugins-local.lua new file mode 100644 index 0000000..1b6f21c --- /dev/null +++ b/lua/plugins-local.lua @@ -0,0 +1,2 @@ +return function(use) +end diff --git a/lua/plugins.lua b/lua/plugins.lua index fe97c01..492c63e 100644 --- a/lua/plugins.lua +++ b/lua/plugins.lua @@ -1,16 +1,87 @@ -- TODO: Add minimal plugin mode. Disables all plugins which are not super -- important, to get better performance. ----@diagnostic disable-next-line: unused-local -local function usePlugins(use, use_rocks) - -- Toggle terminal - use {'akinsho/toggleterm.nvim', tag = '*', config=[[require('config.toggleterm')]]} +return function(use) + local function use_config(name) + use(require(("config.%s"):format(name))) + end - -- Colorize ANSI codes - use { 'm00qek/baleia.nvim', tag = 'v1.2.0', config=[[require('config.baleia')]] } + use_config "toggleterm" + use_config "baleia" + use_config "todo-comments" + use_config "dressing" + use_config "legendary" + use_config "move" + use_config "gitblame" + use_config "based" + use_config "lspsignature" + use_config "lsputils" + use_config "luasnip" + use_config "trouble" + use_config "fugitive" + use_config "gitsigns" + use_config "nvim-tree" + use_config "autosource" + use_config "tidy" + use_config "quickscope" + use_config "leap" + use_config "comment" + use_config "colorizer" + use_config "devicons" + use_config "treesitter" + use_config "ts-playground" + use_config "diffview" + + use { + "nvim-telescope/telescope.nvim", + requires = { + "nvim-lua/plenary.nvim", + "nvim-treesitter/nvim-treesitter", + "kyazdani42/nvim-web-devicons", + "nvim-telescope/telescope-ui-select.nvim", + {"nvim-telescope/telescope-fzf-native.nvim", run = "make"} + }, + load_config = true + } + + use { + "neovim/nvim-lspconfig", + config_name = "lspconfig" + } + + use { + 'williamboman/nvim-lsp-installer', + requires = 'neovim/nvim-lspconfig', + config_name = "lspinstaller" + } + + use { + "nvim-lualine/lualine.nvim", + requires = "kyazdani42/nvim-web-devicons", + load_config = true + } + + use { + 'rafcamlet/nvim-luapad', + config_name = "luapad" + } + + use "tpope/vim-eunuch" + use "christoomey/vim-tmux-navigator" + use "eandrju/cellular-automaton.nvim" + use "tweekmonster/startuptime.vim" + use "tpope/vim-unimpaired" + use "wellle/targets.vim" + use "michaeljsmith/vim-indent-object" + use "psliwka/vim-smoothie" + use "godlygeek/tabular" + use "editorconfig/editorconfig-vim" + use "tpope/vim-surround" + use "tpope/vim-repeat" + use "tikhomirov/vim-glsl" -- Debugger - use { 'mfussenegger/nvim-dap', config=[[require('config.dap')]]} + use { "mfussenegger/nvim-dap", config_name="dap" } use { "rcarriga/nvim-dap-ui", requires = "mfussenegger/nvim-dap", config=[[require('dapui').setup()]] } use 'simrat39/rust-tools.nvim' use { @@ -19,40 +90,6 @@ local function usePlugins(use, use_rocks) config=[[require('nvim-dap-virtual-text')]] } - -- Git blame - use { 'f-person/git-blame.nvim', config=[[require("config.gitblame")]] } - - -- Seemless pane switching betwen tmux and vim - use 'christoomey/vim-tmux-navigator' - - -- UNIX commands - use 'tpope/vim-eunuch' - - -- Movement utilities - use 'tpope/vim-unimpaired' - - -- LSP - use { - 'neovim/nvim-lspconfig', - config = [[require 'config.lspconfig']], - } - use { - 'williamboman/nvim-lsp-installer', - requires = 'neovim/nvim-lspconfig', - config = [[require 'config.lspinstaller']] - } - - -- LSP utils - use {"ray-x/lsp_signature.nvim", config = [[require 'config.lspsignature']]} - use { - 'RishabhRD/nvim-lsputils', - config = [[require 'config.lsputils']], - requires = 'RishabhRD/popfix' - } - - -- Snippets - use { 'L3MON4D3/LuaSnip', config = [[require 'config.luasnip']] } - -- Completion use { 'onsails/lspkind-nvim' } use { @@ -60,9 +97,9 @@ local function usePlugins(use, use_rocks) -- requires = 'onsails/lspkind-nvim', -- For some reason breaks with this line requires = {'saadparwaiz1/cmp_luasnip'}, after = 'lspkind-nvim', - config = [[require 'config.cmp']] + config_name = "cmp" } - use {'tzachar/cmp-tabnine', after = 'nvim-cmp', run='./install.sh', requires = 'hrsh7th/nvim-cmp', config = [[require 'config.tabnine']]} + use {'tzachar/cmp-tabnine', after = 'nvim-cmp', run='./install.sh', requires = 'hrsh7th/nvim-cmp', config_name = "tabnine"} use {'hrsh7th/cmp-nvim-lsp', requires = {'hrsh7th/nvim-cmp', 'nvim-lspconfig'}} use {'hrsh7th/cmp-nvim-lua', after = 'nvim-cmp', requires = 'hrsh7th/nvim-cmp'} use {'hrsh7th/cmp-buffer', after = 'nvim-cmp', requires = 'hrsh7th/nvim-cmp'} @@ -70,209 +107,20 @@ local function usePlugins(use, use_rocks) use {'hrsh7th/cmp-cmdline', after = 'nvim-cmp', requires = 'hrsh7th/nvim-cmp'} use {'saadparwaiz1/cmp_luasnip', after = 'nvim-cmp', requires = {'L3MON4D3/LuaSnip', 'nvim-cmp'}} - -- Better diagnostics viewer - use { - 'folke/trouble.nvim', - requires = 'kyazdani42/nvim-web-devicons', - config = [[require 'config.trouble']] - } - - -- Color themes - use 'srcery-colors/srcery-vim' - -- use 'morhetz/gruvbox' - -- use 'tomasr/molokai' - -- use 'Mangeshrex/uwu.vim' - -- use 'ayu-theme/ayu-vim' - -- use 'sickill/vim-monokai' - -- use 'joshdick/onedark.vim' - -- use 'mswift42/vim-themes' - -- use 'squarefrog/tomorrow-night.vim' - -- use 'fnune/base16-vim' - - -- Text object target - use 'wellle/targets.vim' - - -- Git integration - use { 'tpope/vim-fugitive', config = [[require 'config.fugitive']] } - use { - 'lewis6991/gitsigns.nvim', - requires = 'nvim-lua/plenary.nvim', - config = [[require 'config.gitsigns']] - -- tag = 'release' -- To use the latest release - } - - -- Refactoring - -- use { - -- "ThePrimeagen/refactoring.nvim", - -- requires = { - -- "nvim-lua/plenary.nvim", - -- "nvim-treesitter/nvim-treesitter" - -- }, - -- disable = true, - -- config = [[require 'config.refactoring']] - -- } - - -- Analyze startup time - use 'tweekmonster/startuptime.vim' - - -- Status line and tab line - use { 'itchyny/lightline.vim', config = [[require 'config.lightline']]} - - -- Load project specific settings from exrc - use { 'jenterkin/vim-autosource', config = [[require 'config.autosource']] } - - -- Remove spaces at end of lines - use{ "mcauley-penney/tidy.nvim", config = [[require("tidy").setup()]] } + do -- Color themes + use 'srcery-colors/srcery-vim' + -- use 'morhetz/gruvbox' + -- use 'tomasr/molokai' + -- use 'Mangeshrex/uwu.vim' + -- use 'ayu-theme/ayu-vim' + -- use 'sickill/vim-monokai' + -- use 'joshdick/onedark.vim' + -- use 'mswift42/vim-themes' + -- use 'squarefrog/tomorrow-night.vim' + -- use 'fnune/base16-vim' + end -- Training plugins -- use 'tjdevries/train.nvim' -- use 'ThePrimeagen/vim-be-good' - - -- Quick movement - -- use { 'justinmk/vim-sneak', config = [[require 'config.sneak']] } - use { 'unblevable/quick-scope', config = [[require 'config.quickscope']] } - use 'michaeljsmith/vim-indent-object' - use { 'ggandor/leap.nvim', config=[[require 'config.leap']]} - - -- Smooth smooth scrolling - -- use { 'karb94/neoscroll.nvim', config = [[require('neoscroll').setup()]] } - use 'psliwka/vim-smoothie' - - -- Commenting - use { - 'terrortylor/nvim-comment', - config = [[require 'config.comment']], - requires = 'JoosepAlviste/nvim-ts-context-commentstring' - } - - -- Color code colorizer - use { 'norcalli/nvim-colorizer.lua', config = [[require 'config.colorizer']] } - - -- Fuzzy file finder - use { - 'nvim-telescope/telescope.nvim', - config = [[require 'config.telescope']], - requires = { - 'nvim-lua/plenary.nvim', - 'nvim-treesitter/nvim-treesitter', - 'kyazdani42/nvim-web-devicons', - {'nvim-telescope/telescope-fzf-native.nvim', run = 'make'} - } - } - - -- Align characters vertically - use 'godlygeek/tabular' - - -- Used for loading project specific code styles - use 'editorconfig/editorconfig-vim' - - -- Provides mappings for working with symbols like (), {}, [], etc. - use 'tpope/vim-surround' - - -- Allow repeating - use 'tpope/vim-repeat' - - -- GLSL language support - use 'tikhomirov/vim-glsl' - - -- Treesitter - use { - 'nvim-treesitter/nvim-treesitter', - config = [[require 'config.treesitter']], - run = function() require('nvim-treesitter.install').update{ with_sync = true } end - } - use { - 'nvim-treesitter/playground', - requires = 'nvim-treesitter/nvim-treesitter', - cmd = "TSPlaygroundToggle" - } - - -- Dev icons - use {'kyazdani42/nvim-web-devicons', config = [[require('nvim-web-devicons').setup()]]} - - -- Zen mode - use { 'folke/zen-mode.nvim', config = [[require 'config.zen-mode']] } - use { - 'folke/twilight.nvim', - requires = 'folke/zen-mode.nvim', - config = [[require 'config.twilight']] - } - - -- File browser - use { - 'kyazdani42/nvim-tree.lua', - requires = 'kyazdani42/nvim-web-devicons', - config = [[require 'config.nvim-tree']] - } - -- use { - -- 'lambdalisue/fern.vim', - -- config = [[require 'config.fern']], - -- requires = { - -- 'antoinemadec/FixCursorHold.nvim', - -- 'lambdalisue/fern-hijack.vim', - -- {'lambdalisue/fern-renderer-nerdfont.vim', config = [[vim.g["fern#renderer"] = "nerdfont"]]}, - -- 'lambdalisue/nerdfont.vim' - -- } - -- } - -- alternatives: - -- use 'kyazdani42/nvim-tree.lua' - -- use 'zgpio/tree.nvim' - -- use 'tpope/vim-vinegar' end - --- Register custom commands for plugin manager -vim.cmd [[command! -bang -nargs=+ -complete=customlist,v:lua.require'plugins'.loader_complete PackerLoad lua require('plugins').loader(, '' == '!')]] -vim.cmd [[command! PackerInstall packadd packer.nvim | lua require('plugins').install()]] -vim.cmd [[command! PackerUpdate packadd packer.nvim | lua require('plugins').update()]] -vim.cmd [[command! PackerSync packadd packer.nvim | lua require('plugins').sync()]] -vim.cmd [[command! PackerClean packadd packer.nvim | lua require('plugins').clean()]] -vim.cmd [[command! PackerCompile source lua/plugins.lua | packadd packer.nvim | lua require('plugins').compile()]] - --- Bootstrap packer.nvim. If packer.nvim is not installed, install it. -local function bootstrap() - local fn = vim.fn - local install_path = fn.stdpath('data')..'/site/pack/packer/start/packer.nvim' - if fn.empty(fn.glob(install_path)) > 0 then - return fn.system({'git', 'clone', '--depth', '1', 'https://github.com/wbthomason/packer.nvim', install_path}) - end -end - -local packer = nil -local function init() - -- Perform bootstrap - local packer_bootstrap = bootstrap() - - -- Initialize packer - if packer == nil then - packer = require 'packer' - local util = require 'packer.util' - packer.init { - compile_path = util.join_paths(vim.fn.stdpath('config'), 'plugin', 'packer-compiled.lua'), - disable_commands = true - } - end - - -- Reset plugins if already loaded - packer.reset() - - -- Packer can manage itself - packer.use 'wbthomason/packer.nvim' - - -- Use plugins - usePlugins(packer.use, packer.use_rocks) - - -- Automatically set up your configuration after cloning packer.nvim - -- Put this at the end after all plugins - if packer_bootstrap then - require('packer').sync() - end -end - -local plugins = setmetatable({}, { - __index = function(_, key) - init() - return packer[key] - end, -}) - -return plugins