From 1e98df6cc30d5cd89c03ad89ed8d58e0eddf031d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sascha=20L=C3=BCdecke?= Date: Thu, 19 Sep 2024 21:48:06 +0200 Subject: [PATCH] Reformatted code after changing indent width to 2, TODO highlighting - set all indent widths from 4 to 2 - added plugin to highlight TODO markers, can also be searched ft --- lua/keybindings.lua | 7 +- lua/lsp.lua | 149 +++++++-------- lua/options.lua | 6 +- lua/plugins.lua | 436 +++++++++++++++++++++++--------------------- 4 files changed, 309 insertions(+), 289 deletions(-) diff --git a/lua/keybindings.lua b/lua/keybindings.lua index 3a93536..a9f94dd 100644 --- a/lua/keybindings.lua +++ b/lua/keybindings.lua @@ -6,16 +6,17 @@ vim.keymap.set('n', 'fg', fzf.live_grep, { desc = "Grep" }) vim.keymap.set('n', 'fG', fzf.grep_cword, { desc = "Grep word under cursor" }) vim.keymap.set('n', 'fc', fzf.commands, { desc = "Commands" }) vim.keymap.set('n', 'fm', fzf.manpages, { desc = "Manpages" }) - vim.keymap.set('n', 'b', fzf.buffers, { desc = "Buffers" }) +vim.keymap.set('n', 'ft', ":TodoFzfLua", { desc = "Todos" }) + -- use fzf buffer lines as default search vim.keymap.set('n', '/', fzf.blines, { desc = "Search buffer" }) vim.keymap.set('n', 'z=', fzf.spell_suggest, { desc = "Spelling suggestions" }) -- open file manager and git -vim.keymap.set('n', 'g', ":Neogit", { desc = "Git Manager" }) -vim.keymap.set('n', 'T', ":Neotree", { desc = "File Manager" }) +vim.keymap.set('n', 'g', ":Neogit", { desc = "Neogit" }) +vim.keymap.set('n', 'T', ":Neotree reveal", { desc = "File Manager" }) -- -- configure workspaces diff --git a/lua/lsp.lua b/lua/lsp.lua index b0e75fa..efa38ed 100644 --- a/lua/lsp.lua +++ b/lua/lsp.lua @@ -1,25 +1,26 @@ require('mason').setup({ - ui = { - icons = { - package_installed = "✓", - package_pending = "➜", - package_uninstalled = "✗" - } + ui = { + icons = { + package_installed = "✓", + package_pending = "➜", + package_uninstalled = "✗" } + } }) require('mason-lspconfig').setup({ - -- A list of servers to automatically install if they're not already installed - ensure_installed = { - 'pylsp', - 'lua_ls', - 'rust_analyzer', - 'yamlls', - 'tsserver', - 'gopls', - 'pylsp', - -- 'volar', - }, + -- A list of servers to automatically install if they're not already installed + ensure_installed = { + 'pylsp', + 'lua_ls', + 'rust_analyzer', + 'yamlls', + 'ts_ls', + 'gopls', + 'pylsp', + 'clangd', + -- 'volar', + }, }) -- Customized on_attach function @@ -33,38 +34,38 @@ vim.keymap.set('n', ']d', vim.diagnostic.goto_next, opts) -- Use an on_attach function to only map the following keys -- after the language server attaches to the current buffer local on_attach = function(client, bufnr) - -- Enable completion triggered by - vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc') + -- Enable completion triggered by + vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc') - -- See `:help vim.lsp.*` for documentation on any of the below functions - local bufopts = { noremap = true, silent = true, buffer = bufnr } - vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, bufopts) - vim.keymap.set('n', 'gd', vim.lsp.buf.definition, bufopts) - vim.keymap.set('n', 'K', vim.lsp.buf.hover, bufopts) - vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, bufopts) - vim.keymap.set('n', '', vim.lsp.buf.signature_help, bufopts) - vim.keymap.set('n', 'wa', vim.lsp.buf.add_workspace_folder, bufopts) - vim.keymap.set('n', 'wr', vim.lsp.buf.remove_workspace_folder, bufopts) - vim.keymap.set('n', 'wl', function() - print(vim.inspect(vim.lsp.buf.list_workspace_folders())) - end, bufopts) - -- vim.keymap.set('n', 'D', vim.lsp.buf.type_definition, bufopts) - vim.keymap.set('n', 'rn', vim.lsp.buf.rename, bufopts) - -- vim.keymap.set('n', 'ca', vim.lsp.buf.code_action, bufopts) - vim.keymap.set("n", "f", function() - vim.lsp.buf.format({ async = true }) - end, bufopts) + -- See `:help vim.lsp.*` for documentation on any of the below functions + local bufopts = { noremap = true, silent = true, buffer = bufnr } + vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, bufopts) + vim.keymap.set('n', 'gd', vim.lsp.buf.definition, bufopts) + vim.keymap.set('n', 'K', vim.lsp.buf.hover, bufopts) + vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, bufopts) + vim.keymap.set('n', '', vim.lsp.buf.signature_help, bufopts) + vim.keymap.set('n', 'wa', vim.lsp.buf.add_workspace_folder, bufopts) + vim.keymap.set('n', 'wr', vim.lsp.buf.remove_workspace_folder, bufopts) + vim.keymap.set('n', 'wl', function() + print(vim.inspect(vim.lsp.buf.list_workspace_folders())) + end, bufopts) + -- vim.keymap.set('n', 'D', vim.lsp.buf.type_definition, bufopts) + vim.keymap.set('n', 'rn', vim.lsp.buf.rename, bufopts) + -- vim.keymap.set('n', 'ca', vim.lsp.buf.code_action, bufopts) + vim.keymap.set("n", "f", function() + vim.lsp.buf.format({ async = true }) + end, bufopts) - -- 2024-09-09 - some ccflow commands + -- 2024-09-09 - some ccflow commands - local fzf = require('fzf-lua') - vim.keymap.set('n', 'd', fzf.diagnostics_document , { desc = "Doc diagnostics" }) - vim.keymap.set('n', 'D', fzf.diagnostics_workspace, { desc = "Workspace diagnostics" }) - vim.keymap.set('n', 's', fzf.lsp_document_symbols, { desc = "Doc symbols" }) - vim.keymap.set('n', 'c', fzf.lsp_code_actions, { desc = "Code Actions" }) - -- vim.keymap.set('n', 'gr', vim.lsp.buf.references, bufopts) - vim.keymap.set('n', '', fzf.lsp_references, { desc = "Find References" }) - vim.keymap.set('n', '', fzf.lsp_definitions, { desc = "Find References" }) + local fzf = require('fzf-lua') + vim.keymap.set('n', 'd', fzf.diagnostics_document, { desc = "Doc diagnostics" }) + vim.keymap.set('n', 'D', fzf.diagnostics_workspace, { desc = "Workspace diagnostics" }) + vim.keymap.set('n', 's', fzf.lsp_document_symbols, { desc = "Doc symbols" }) + vim.keymap.set('n', 'c', fzf.lsp_code_actions, { desc = "Code Actions" }) + -- vim.keymap.set('n', 'gr', vim.lsp.buf.references, bufopts) + vim.keymap.set('n', '', fzf.lsp_references, { desc = "Find References" }) + vim.keymap.set('n', '', fzf.lsp_definitions, { desc = "Find References" }) end -- Set different settings for different languages' LSP @@ -76,34 +77,34 @@ local lspconfig = require('lspconfig') -- from :h mason-lspconfig-automatic-server-setup require('mason-lspconfig').setup_handlers({ - -- The first entry (without a key) will be the default handler - -- and will be called for each installed server that doesn't have - -- a dedicated handler. - function(server_name) -- default handler (optional) - if server_name == 'tsserver' then - -- taken from https://github.com/vuejs/language-tools - -- If you are using mason.nvim, you can get the ts_plugin_path like this - local mason_registry = require('mason-registry') - local vue_language_server_path = mason_registry.get_package('vue-language-server'):get_install_path() .. - '/node_modules/@vue/language-server' + -- The first entry (without a key) will be the default handler + -- and will be called for each installed server that doesn't have + -- a dedicated handler. + function(server_name) -- default handler (optional) + if server_name == 'ts_ls' then + -- taken from https://github.com/vuejs/language-tools + -- If you are using mason.nvim, you can get the ts_plugin_path like this + local mason_registry = require('mason-registry') + local vue_language_server_path = mason_registry.get_package('vue-language-server'):get_install_path() .. + '/node_modules/@vue/language-server' - lspconfig[server_name].setup { - on_attach = on_attach, - init_options = { - plugins = { - { - name = '@vue/typescript-plugin', - location = vue_language_server_path, - languages = { 'vue' }, - }, - }, - }, - filetypes = { 'typescript', 'javascript', 'javascriptreact', 'typescriptreact', 'vue' }, - } - else - lspconfig[server_name].setup { - on_attach = on_attach - } - end + lspconfig[server_name].setup { + on_attach = on_attach, + init_options = { + plugins = { + { + name = '@vue/typescript-plugin', + location = vue_language_server_path, + languages = { 'vue' }, + }, + }, + }, + filetypes = { 'typescript', 'javascript', 'javascriptreact', 'typescriptreact', 'vue' }, + } + else + lspconfig[server_name].setup { + on_attach = on_attach + } end + end }) diff --git a/lua/options.lua b/lua/options.lua index 7f2ea20..5b4880a 100644 --- a/lua/options.lua +++ b/lua/options.lua @@ -4,9 +4,9 @@ vim.opt.completeopt = { 'menu', 'menuone', 'noselect' } vim.opt.mouse = 'a' -- allow the mouse to be used in Nvim -- Tab -vim.opt.tabstop = 4 -- number of visual spaces per TAB -vim.opt.softtabstop = 4 -- number of spacesin tab when editing -vim.opt.shiftwidth = 4 -- insert 4 spaces on a tab +vim.opt.tabstop = 2 -- number of visual spaces per TAB +vim.opt.softtabstop = 2 -- number of spacesin tab when editing +vim.opt.shiftwidth = 2 -- insert 4 spaces on a tab vim.opt.expandtab = true -- tabs are spaces, mainly because of python -- UI config diff --git a/lua/plugins.lua b/lua/plugins.lua index 91c1f74..40483e0 100644 --- a/lua/plugins.lua +++ b/lua/plugins.lua @@ -1,228 +1,246 @@ local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" if not (vim.uv or vim.loop).fs_stat(lazypath) then - vim.fn.system({ - "git", - "clone", - "--filter=blob:none", - "https://github.com/folke/lazy.nvim.git", - "--branch=stable", -- latest stable release - lazypath, - }) + vim.fn.system({ + "git", + "clone", + "--filter=blob:none", + "https://github.com/folke/lazy.nvim.git", + "--branch=stable", -- latest stable release + lazypath, + }) end vim.opt.rtp:prepend(lazypath) require("lazy").setup({ - -- Vscode-like pictograms - { - "onsails/lspkind.nvim", - event = { "VimEnter" }, + -- Vscode-like pictograms + { + "onsails/lspkind.nvim", + event = { "VimEnter" }, + }, + + -- Auto-completion engine + { + "hrsh7th/nvim-cmp", + dependencies = { + "lspkind.nvim", + "hrsh7th/cmp-nvim-lsp", -- lsp auto-completion + "hrsh7th/cmp-buffer", -- buffer auto-completion + "hrsh7th/cmp-path", -- path auto-completion + "hrsh7th/cmp-cmdline", -- cmdline auto-completion }, + config = function() + require("config.nvim-cmp") + end, + }, - -- Auto-completion engine - { - "hrsh7th/nvim-cmp", - dependencies = { - "lspkind.nvim", - "hrsh7th/cmp-nvim-lsp", -- lsp auto-completion - "hrsh7th/cmp-buffer", -- buffer auto-completion - "hrsh7th/cmp-path", -- path auto-completion - "hrsh7th/cmp-cmdline", -- cmdline auto-completion - }, - config = function() - require("config.nvim-cmp") - end, + -- Code snippet engine + { + "L3MON4D3/LuaSnip", + version = "v2.*", + }, + + -- LSP manager + "williamboman/mason.nvim", + "williamboman/mason-lspconfig.nvim", + "neovim/nvim-lspconfig", + + -- neogit setup + { + "NeogitOrg/neogit", + dependencies = { + "nvim-lua/plenary.nvim", -- required + "sindrets/diffview.nvim", -- optional - Diff integration + + -- Only one of these is needed, not both. + -- "nvim-telescope/telescope.nvim", -- optional + "ibhagwan/fzf-lua", -- optional }, + config = true + }, - -- Code snippet engine - { - "L3MON4D3/LuaSnip", - version = "v2.*", - }, + -- org-mode + { + 'nvim-orgmode/orgmode', + event = 'VeryLazy', + ft = { 'org' }, + config = function() + -- Setup orgmode + require('orgmode').setup({ + org_agenda_files = '~/orgfiles/**/*', + org_default_notes_file = '~/orgfiles/refile.org', + }) - -- LSP manager - "williamboman/mason.nvim", - "williamboman/mason-lspconfig.nvim", - "neovim/nvim-lspconfig", + -- NOTE: If you are using nvim-treesitter with ~ensure_installed = "all"~ option + -- add ~org~ to ignore_install + -- require('nvim-treesitter.configs').setup({ + -- ensure_installed = 'all', + -- ignore_install = { 'org' }, + -- }) + end, + }, - -- neogit setup - { - "NeogitOrg/neogit", - dependencies = { - "nvim-lua/plenary.nvim", -- required - "sindrets/diffview.nvim", -- optional - Diff integration + -- fzf-lua + { + "ibhagwan/fzf-lua", + -- optional for icon support + dependencies = { "nvim-tree/nvim-web-devicons" }, + config = function() + -- calling `setup` is optional for customization + require("fzf-lua").setup({}) + end + }, - -- Only one of these is needed, not both. - -- "nvim-telescope/telescope.nvim", -- optional - "ibhagwan/fzf-lua", -- optional - }, - config = true - }, - - -- org-mode - { - 'nvim-orgmode/orgmode', - event = 'VeryLazy', - ft = { 'org' }, - config = function() - -- Setup orgmode - require('orgmode').setup({ - org_agenda_files = '~/orgfiles/**/*', - org_default_notes_file = '~/orgfiles/refile.org', - }) - - -- NOTE: If you are using nvim-treesitter with ~ensure_installed = "all"~ option - -- add ~org~ to ignore_install - -- require('nvim-treesitter.configs').setup({ - -- ensure_installed = 'all', - -- ignore_install = { 'org' }, - -- }) - end, - }, - - -- fzf-lua - { - "ibhagwan/fzf-lua", - -- optional for icon support - dependencies = { "nvim-tree/nvim-web-devicons" }, - config = function() - -- calling `setup` is optional for customization - require("fzf-lua").setup({}) - end - }, - - -- whichkey - { - "folke/which-key.nvim", - event = "VeryLazy", - opts = { - -- your configuration comes here - -- or leave it empty to use the default settings - -- refer to the configuration section below - preset = 'helix', - expand = 4, - keys = { - scroll_down = "", -- binding to scroll down inside the popup - scroll_up = "", -- binding to scroll up inside the popup - }, - }, - keys = { - { - "?", - function() - require("which-key").show({ global = false }) - end, - desc = "Buffer Local Keymaps (which-key)", - }, - }, - }, - - -- treesitter - { - "nvim-treesitter/nvim-treesitter", - build = ":TSUpdate", - config = function() - local configs = require("nvim-treesitter.configs") - - configs.setup({ - ensure_installed = { "c", "lua", "vim", "vimdoc", "query", "elixir", "heex", "javascript", "html", "diff", "go", "rust", "python" }, - sync_install = false, - highlight = { enable = true }, - indent = { enable = true }, - }) - end - }, - - -- lualine statusline plugin - { - 'nvim-lualine/lualine.nvim', - dependencies = { 'nvim-tree/nvim-web-devicons' }, - config = function() - require("lualine").setup { - options = { - icons_enabled = false, - theme = 'papercolor_light', - component_separators = {}, - section_separators = {}, - disabled_filetypes = { - statusline = {}, - winbar = {}, - }, - ignore_focus = {}, - always_divide_middle = true, - globalstatus = false, - refresh = { - statusline = 1000, - tabline = 1000, - winbar = 1000, - } - }, - sections = { - lualine_a = { 'filename' }, - lualine_b = { 'branch', 'diff', 'diagnostics' }, - lualine_c = {}, - lualine_x = { 'encoding', 'fileformat', 'filetype' }, - lualine_y = { 'filesize' }, - lualine_z = { 'progress', 'location' } - }, - inactive_sections = { - lualine_a = {}, - lualine_b = {}, - lualine_c = { 'filename' }, - lualine_x = { 'location' }, - lualine_y = {}, - lualine_z = {} - }, - tabline = {}, - winbar = {}, - inactive_winbar = {}, - extensions = {} - } - end - - }, - - -- neo-tree file management - { - "nvim-neo-tree/neo-tree.nvim", - branch = "v3.x", - dependencies = { - "nvim-lua/plenary.nvim", - "nvim-tree/nvim-web-devicons", -- not strictly required, but recommended - "MunifTanjim/nui.nvim", - -- "3rd/image.nvim", -- Optional image support in preview window: See `# Preview Mode` for more information + -- whichkey + { + "folke/which-key.nvim", + event = "VeryLazy", + opts = { + -- your configuration comes here + -- or leave it empty to use the default settings + -- refer to the configuration section below + preset = 'helix', + expand = 4, + keys = { + scroll_down = "", -- binding to scroll down inside the popup + scroll_up = "", -- binding to scroll up inside the popup + }, + plugins = { + presets = { + motions = true, + g = true, } + }, }, - - -- workspaces, lightweight "projects" - { - "natecraddock/workspaces.nvim", - config = function() - require("workspaces").setup { - -- sort the list of workspaces by name after loading from the workspaces path. - sort = true, - - -- sort by recent use rather than by name. requires sort to be true - mru_sort = false, - - -- option to automatically activate workspace when opening neovim in a workspace directory - auto_open = true, - - -- option to automatically activate workspace when changing directory not via this plugin - auto_dir = true, - - hooks = { - open = "FzfLua files" - } - } - end + keys = { + { + "?", + function() + require("which-key").show({ global = false }) + end, + desc = "Buffer Local Keymaps (which-key)", + }, }, + dependencies = { "echasnovski/mini.icons" }, + }, - -- rpn calculator - -- also added as source to cmp - { - "PhilRunninger/cmp-rpncalc", - }, + -- treesitter + { + "nvim-treesitter/nvim-treesitter", + build = ":TSUpdate", + config = function() + local configs = require("nvim-treesitter.configs") - -- comfortable table editing - { 'dhruvasagar/vim-table-mode' }, + configs.setup({ + ensure_installed = { "c", "lua", "vim", "vimdoc", "query", "elixir", "heex", "javascript", "html", "diff", "go", "rust", "python" }, + sync_install = false, + highlight = { enable = true }, + indent = { enable = true }, + }) + end + }, + + -- lualine statusline plugin + { + 'nvim-lualine/lualine.nvim', + dependencies = { 'nvim-tree/nvim-web-devicons' }, + config = function() + require("lualine").setup { + options = { + icons_enabled = false, + theme = 'papercolor_light', + component_separators = {}, + section_separators = {}, + disabled_filetypes = { + statusline = {}, + winbar = {}, + }, + ignore_focus = {}, + always_divide_middle = true, + globalstatus = false, + refresh = { + statusline = 1000, + tabline = 1000, + winbar = 1000, + } + }, + sections = { + lualine_a = { 'filename' }, + lualine_b = { 'branch', 'diff', 'diagnostics' }, + lualine_c = {}, + lualine_x = { 'encoding', 'fileformat', 'filetype' }, + lualine_y = { 'filesize' }, + lualine_z = { 'progress', 'location' } + }, + inactive_sections = { + lualine_a = {}, + lualine_b = {}, + lualine_c = { 'filename' }, + lualine_x = { 'location' }, + lualine_y = {}, + lualine_z = {} + }, + tabline = {}, + winbar = {}, + inactive_winbar = {}, + extensions = {} + } + end + + }, + + -- neo-tree file management + { + "nvim-neo-tree/neo-tree.nvim", + branch = "v3.x", + dependencies = { + "nvim-lua/plenary.nvim", + "nvim-tree/nvim-web-devicons", -- not strictly required, but recommended + "MunifTanjim/nui.nvim", + -- "3rd/image.nvim", -- Optional image support in preview window: See `# Preview Mode` for more information + } + }, + + -- workspaces, lightweight "projects" + { + "natecraddock/workspaces.nvim", + config = function() + require("workspaces").setup { + -- sort the list of workspaces by name after loading from the workspaces path. + sort = true, + + -- sort by recent use rather than by name. requires sort to be true + mru_sort = false, + + -- option to automatically activate workspace when opening neovim in a workspace directory + auto_open = true, + + -- option to automatically activate workspace when changing directory not via this plugin + auto_dir = true, + + hooks = { + open = "FzfLua files" + } + } + end + }, + + -- rpn calculator + -- also added as source to cmp + { + "PhilRunninger/cmp-rpncalc", + }, + + -- comfortable table editing + { 'dhruvasagar/vim-table-mode' }, + + -- TODO, WARN, HACK, PERF, NOTE, TEST and others highlighting and searching + { + "folke/todo-comments.nvim", + dependencies = { "nvim-lua/plenary.nvim" }, + opts = { + -- your configuration comes here + -- or leave it empty to use the default settings + -- refer to the configuration section below + } + }, })