From fe0e677564995c25119beb8238234c24ef6e592c Mon Sep 17 00:00:00 2001 From: Max Christian Pohle Date: Sun, 1 Sep 2024 02:00:46 +0200 Subject: refactored the entire config --- init.lua | 242 +++++++-------------------------------------- lua/plugins/cmp.lua | 166 +++++++++++++++++++++++++++++-- lua/plugins/colorizer.lua | 6 ++ lua/plugins/devicons.lua | 11 +++ lua/plugins/gitsigns.lua | 6 ++ lua/plugins/orgmode.lua | 6 -- lua/plugins/popup.lua | 5 + lua/plugins/telescope.lua | 13 ++- lua/plugins/treesitter.lua | 20 ++++ vimrc | 10 +- 10 files changed, 257 insertions(+), 228 deletions(-) create mode 100644 lua/plugins/colorizer.lua create mode 100644 lua/plugins/devicons.lua create mode 100644 lua/plugins/gitsigns.lua create mode 100644 lua/plugins/popup.lua create mode 100644 lua/plugins/treesitter.lua diff --git a/init.lua b/init.lua index 5152093..a68778d 100644 --- a/init.lua +++ b/init.lua @@ -1,59 +1,46 @@ -------------------------------------------------------------------------------- --- lazy plugin manager +-- vim options, first sourced from vimrc, then appended by Neovim specific stuff +-------------------------------------------------------------------------------- +local configdir = vim.fn.fnamemodify(vim.fn.expand("$MYVIMRC"), ":p:h") +vim.cmd('source ' .. configdir .. '/vimrc') + +vim.opt.encoding='utf-8' +vim.opt.inccommand = "nosplit" -- Neovim only: preview substitute and such things in real time +vim.opt.shadafile = configdir .. "/shada.file" + +-------------------------------------------------------------------------------- +-- Bootstrap lazy.nvim -------------------------------------------------------------------------------- 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, - }) + local lazyrepo = "https://github.com/folke/lazy.nvim.git" + local out = vim.fn.system({ "git", "clone", "--filter=blob:none", "--branch=stable", lazyrepo, lazypath }) + if vim.v.shell_error ~= 0 then + vim.api.nvim_echo({ + { "Failed to clone lazy.nvim:\n", "ErrorMsg" }, + { out, "WarningMsg" }, + { "\nPress any key to exit..." }, + }, true, {}) + vim.fn.getchar() + os.exit(1) + end end vim.opt.rtp:prepend(lazypath) require("lazy").setup({ spec = { { import = "plugins", }, - 'nvim-tree/nvim-web-devicons', - 'lewis6991/gitsigns.nvim', - 'folke/neodev.nvim', - -- treesitter is experimental and breaks indentation on xml, html with `=` - 'nvim-treesitter/nvim-treesitter', - 'nvim-lua/popup.nvim', - 'nvim-lua/plenary.nvim', 'coderonline/vim-fancy-line', 'coderonline/vim-recently-used', - 'norcalli/nvim-colorizer.lua', - 'folke/trouble.nvim', } }) --------------------------------------------------------------------------------- --- vim options, first sourced from vimrc, then appended by Neovim specific stuff --------------------------------------------------------------------------------- -local configdir = vim.fn.fnamemodify(vim.fn.expand("$MYVIMRC"), ":p:h") -vim.cmd('source ' .. configdir .. '/vimrc') --- vim.cmd.colorscheme "base16-rebecca" --- vim.cmd.colorscheme "base16-katy" - -vim.opt.encoding = 'utf-8' -vim.opt.number = true -vim.opt.number = true -vim.opt.shiftwidth = 2 -vim.opt.tabstop = 2 -vim.opt.softtabstop = 2 -vim.opt.inccommand = "nosplit" -- Neovim only: preview substitute and such things in real time -vim.opt.termguicolors = true -vim.opt.shadafile = configdir .. "/shada.file" - -- Restore cursor position vim.api.nvim_create_autocmd({ "BufReadPost" }, { callback = function() vim.cmd('silent! normal! g`"zv') end }) +-- LSP says 'fix available', but there is no such command? Let us fix that: vim.api.nvim_create_user_command( 'LspFix', function() @@ -61,13 +48,21 @@ vim.api.nvim_create_user_command( end, {} ) +-- speaking of lsp, lets enable logging (TODO: remove if you remove +-- `lua/cmp.lua`, but why would you?) +vim.g.lsp_log_verbose = 1 +vim.g.lsp_log_file = configdir .. ('/vim-lsp.log') +vim.lsp.set_log_level 'error' +if vim.fn.has 'nvim-0.5.1' == 1 then + require('vim.lsp.log').set_format_func(vim.inspect) +end + +-- If you need scoop for some dependencies on Windows machines this may come +-- handy: if vim.fn.has("win32") then vim.opt.rtp:append(vim.fn.expand("$HOME\\scoop\\shims")) end -vim.g.lsp_log_verbose = 1 -vim.g.lsp_log_file = configdir .. ('/vim-lsp.log') - if vim.g.neovide then vim.guifont = "monospace:h11:b" vim.g.neovide_cursor_animation_length = 0.03 @@ -82,173 +77,4 @@ if vim.g.neovide then vim.g.neovide_scale_factor = 1.0 end --------------------------------------------------------------------------------- --- plugin setup and options --------------------------------------------------------------------------------- --- require'nvim-treesitter.configs'.setup { --- -- A list of parser names, or "all" (the five listed parsers should always be installed) --- ensure_installed = { "c", "lua", "vim", "vimdoc", "query" }, --- modules = {}, --- -- Install parsers synchronously (only applied to `ensure_installed`) --- sync_install = false, --- -- Automatically install missing parsers when entering buffer --- -- Recommendation: set to false if you don't have `tree-sitter` CLI installed locally --- auto_install = true, --- ignore_install = { "javascript" }, --- highlight = { --- enable = true, --- -- NOTE: these are the names of the parsers and not the filetype. (for example if you want to --- -- disable highlighting for the `tex` filetype, you need to include `latex` in this list as this is --- -- the name of the parser) --- -- list of language that will be disabled --- disable = function(_, buf) --- local max_filesize = 100 * 1024 -- 100 KB --- local ok, stats = pcall(vim.loop.fs_stat, vim.api.nvim_buf_get_name(buf)) --- if ok and stats and stats.size > max_filesize then --- return true --- end --- end, --- -- Setting this to true will run `:h syntax` and tree-sitter at the same time. --- -- Set this to `true` if you depend on 'syntax' being enabled (like for indentation). --- -- Using this option may slow down your editor, and you may see some duplicate highlights. --- -- Instead of true it can also be a list of languages --- additional_vim_regex_highlighting = false, --- }, --- } - --- vim.wo.foldtext = 'v:lua.vim.treesitter.foldtext()' -- not available yet in my installation -vim.wo.foldexpr = 'v:lua.vim.treesitter.foldexpr()' -vim.wo.foldlevel = 1 - -require('telescope').load_extension('media_files') - -vim.lsp.set_log_level 'error' -if vim.fn.has 'nvim-0.5.1' == 1 then - require('vim.lsp.log').set_format_func(vim.inspect) -end -require'nvim-web-devicons'.setup { - color_icons = true; - default = true; - strict = true; -} -require('colorizer').setup() -require('gitsigns').setup() -require('trouble').setup() -require('neodev').setup() - -local builtin = require('telescope.builtin') -vim.keymap.set('n', 'ff', builtin.find_files, {}) -vim.keymap.set('n', 'fg', builtin.live_grep, {}) -vim.keymap.set('n', 'fb', builtin.buffers, {}) -vim.keymap.set('n', 'fh', builtin.help_tags, {}) - -vim.keymap.set({"i", "s"}, "", function() require('luasnip').jump(1) end, {silent = true}) -vim.keymap.set({"i", "s"}, "", function() require('luasnip').jump(-1) end, {silent = true}) - -local cmp = require'cmp' -cmp.setup({ - snippet = { - -- REQUIRED - you must specify a snippet engine - expand = function(args) - require('luasnip').lsp_expand(args.body) -- For `luasnip` users. - -- vim.snippet.expand(args.body) -- For native neovim snippets (Neovim v0.10+) - end, - }, - window = { - completion = cmp.config.window.bordered(), - documentation = cmp.config.window.bordered(), - }, - mapping = cmp.mapping.preset.insert({ - [''] = cmp.mapping.scroll_docs(-4), - [''] = cmp.mapping.scroll_docs(4), - [''] = cmp.mapping.complete(), - [''] = cmp.mapping.abort(), - [''] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. - }), - sources = cmp.config.sources({ - { name = 'nvim_lsp' }, - { name = 'luasnip' }, -- For luasnip users. - }, { - { name = 'buffer' }, - }) -}) - --- Set up lspconfig. -local cmp_nvim_lsp = require "cmp_nvim_lsp" - -require("lspconfig").clangd.setup { - on_attach = on_attach, - capabilities = cmp_nvim_lsp.default_capabilities(), - cmd = { - "clangd", - "--offset-encoding=utf-16", - }, -} --- local capabilities = require('cmp_nvim_lsp').default_capabilities() - --- # Language Servers --- https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md - --- C/C++ | clang --- require('lspconfig')['bitbake_language_server'].setup{} --- require('lspconfig')['clangd'].setup{} --- -- lua (but not init.lua entirely, hence why neodev) --- require('lspconfig')['lua_ls'].setup { } --- -- require('lspconfig')['java_language_server'].setup{ cmd = { "/usr/share/java/java-language-server/lang_server_linux.sh" }, root_dir = function () return vim.fn.getcwd() end } --- require'lspconfig'.jdtls.setup{} --- -- bash | bash-language-server --- require('lspconfig')['bashls'].setup{} --- -- ccs | vscode-css-languageserver --- require('lspconfig')['cssls'].setup{} --- -- rust | rust-analyzer --- require('lspconfig')['rust_analyzer'].setup{} --- -- javascript | eslint --- require('lspconfig')['eslint'].setup{} --- -- javascript | typescript-language-server --- require('lspconfig')['tsserver'].setup{} --- -- vimscript | vim-language-server --- require('lspconfig')['vimls'].setup{} --- -- html --- require('lspconfig')['html'].setup{} --- -- jsonls --- require('lspconfig')['jsonls'].setup{} --- -- C/C++ | clang --- require('lspconfig')['clangd'].setup{} --- -- bash | bash-language-server --- require('lspconfig')['bashls'].setup{} --- -- ccs | vscode-css-languageserver --- require('lspconfig')['cssls'].setup{} --- -- rust | rust-analyzer --- require('lspconfig')['rust_analyzer'].setup{} --- -- javascript | eslint --- require('lspconfig')['eslint'].setup{} --- -- javascript | typescript-language-server --- require('lspconfig')['tsserver'].setup{} --- -- vimscript | vim-language-server --- require('lspconfig')['vimls'].setup{} --- -- configure html server --- require('lspconfig')["html"].setup({ --- -- on_attach = on_attach, --- init_options = { --- configurationSection = { "html", "css", "javascript" }, --- embeddedLanguages = { --- css = true, --- javascript = true, --- }, --- provideFormatter = true, --- }, --- }) --- require('lspconfig')['pylsp'].setup{ --- settings = { --- pylsp = { --- plugins = { --- pycodestyle = { --- ignore = {'W391'}, --- maxLineLength = 100 --- } --- } --- } --- } --- } - -- vim: tabstop=2 shiftwidth=2 softtabstop=2 diff --git a/lua/plugins/cmp.lua b/lua/plugins/cmp.lua index fed96e4..f4766db 100644 --- a/lua/plugins/cmp.lua +++ b/lua/plugins/cmp.lua @@ -1,11 +1,159 @@ return { - 'neovim/nvim-lspconfig', - 'hrsh7th/cmp-nvim-lsp', - 'hrsh7th/cmp-buffer', - 'hrsh7th/cmp-path', - 'hrsh7th/nvim-cmp', - 'hrsh7th/vim-vsnip', - 'L3MON4D3/LuaSnip', - 'octaltree/cmp-look', - 'saadparwaiz1/cmp_luasnip', + { + 'hrsh7th/nvim-cmp', + dependencies = { + 'nvim-lua/popup.nvim', + 'nvim-lua/plenary.nvim', + 'saadparwaiz1/cmp_luasnip', + "hrsh7th/cmp-emoji", + 'hrsh7th/cmp-nvim-lsp', + 'hrsh7th/cmp-buffer', + 'hrsh7th/cmp-path', + 'hrsh7th/vim-vsnip', + 'octaltree/cmp-look', + 'folke/trouble.nvim', + 'folke/lazydev.nvim', + { + 'L3MON4D3/LuaSnip', + config = function() + vim.keymap.set( + {"i", "s"}, + "", + function() require('luasnip').jump(1) end, + {silent = true} + ) + vim.keymap.set( + {"i", "s"}, + "", + function() require('luasnip').jump(-1) end, + {silent = true} + ) + end, + }, + }, + + config = function() + require('trouble').setup() + require('lazydev').setup() + + local cmp = require'cmp' + cmp.setup({ + snippet = { + -- REQUIRED - you must specify a snippet engine + expand = function(args) + require('luasnip').lsp_expand(args.body) -- For `luasnip` users. + -- vim.snippet.expand(args.body) -- For native neovim snippets (Neovim v0.10+) + end, + }, + window = { + completion = cmp.config.window.bordered(), + documentation = cmp.config.window.bordered(), + }, + mapping = cmp.mapping.preset.insert({ + [''] = cmp.mapping.scroll_docs(-4), + [''] = cmp.mapping.scroll_docs(4), + [''] = cmp.mapping.complete(), + [''] = cmp.mapping.abort(), + [''] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. + }), + sources = cmp.config.sources({ + { name = 'nvim_lsp' }, + { name = 'luasnip' }, -- For luasnip users. + }, { + { name = 'buffer' }, + }) + }) + end + }, + { + 'neovim/nvim-lspconfig', + dependencies = { + { "folke/neodev.nvim" } + }, + config = function() + -- Set up lspconfig. + local keymap = vim.keymap + local on_attach = function(client, bufnr) + local opts = { noremap = true, silent = true, buffer = bufnr } + keymap.set("n", "gf", "Lspsaga lsp_finder", opts) -- show definition, references + keymap.set("n", "gD", "Lspsaga goto_definition", opts) -- got to declaration + keymap.set("n", "gd", "Lspsaga peek_definition", opts) -- see definition and make edits in window + keymap.set("n", "gi", "lua vim.lsp.buf.implementation()", opts) -- go to implementation + keymap.set("n", "ca", "Lspsaga code_action", opts) -- see available code actions + keymap.set("n", "rn", "Lspsaga rename", opts) -- smart rename + keymap.set("n", "D", "Lspsaga show_line_diagnostics", opts) -- show diagnostics for line + keymap.set("n", "d", "Lspsaga show_cursor_diagnostics", opts) -- show diagnostics for cursor + keymap.set("n", "[d", "Lspsaga diagnostic_jump_prev", opts) -- jump to previous diagnostic in buffer + keymap.set("n", "]d", "Lspsaga diagnostic_jump_next", opts) -- jump to next diagnostic in buffer + keymap.set("n", "K", "Lspsaga hover_doc", opts) -- show documentation for what is under cursor + keymap.set("n", "o", "LSoutlineToggle", opts) -- see outline on right hand side + keymap.set("n", "gr", "lua vim.lsp.buf.references()", opts) + vim.keymap.set("n", "", ":cnext") + vim.keymap.set("n", "", ":cprev") + end + + local capabilities = require("cmp_nvim_lsp").default_capabilities() + + -- # Language Servers + -- https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md + for _,server in ipairs({ + 'bitbake_language_server', + "clangd", -- C/C++ | clang + "tsserver", -- javascript | typescript-language-server + "lua_ls", -- lua (but not init.lua entirely, hence why neodev) + "jdtls", + "html", + "cssls", -- ccs | vscode-css-languageserver + "rust_analyzer", -- rust | rust-analyzer + "eslint", -- javascript | eslint + 'vimls', -- vimscript | vim-language-server + 'html', -- html + 'jsonls', -- jsonls + "pyright", -- python + "bashls", -- bash | bash-language-server + "gopls", + "emmet_ls", + "marksman"}) do + require("lspconfig")[server].setup({ + capabilities = capabilities, + on_attach = on_attach + }) + end + + -- # specialized config for some LSPs which have non-ideal defaults + -- + -- require('lspconfig')['java_language_server'].setup{ cmd = { "/usr/share/java/java-language-server/lang_server_linux.sh" }, root_dir = function () return vim.fn.getcwd() end } + -- configure html server + require('lspconfig')["html"].setup({ + init_options = { + configurationSection = { "html", "css", "javascript" }, + embeddedLanguages = { + css = true, + javascript = true, + }, + provideFormatter = true, + }, + }) + require('lspconfig')['pylsp'].setup{ + settings = { + pylsp = { + plugins = { + pycodestyle = { + ignore = {'W391'}, + maxLineLength = 100 + } + } + } + } + } + require("lspconfig").clangd.setup { + on_attach = on_attach, + capabilities = capabilities, + cmd = { + "clangd", + "--offset-encoding=utf-16", + }, + } + end + } } diff --git a/lua/plugins/colorizer.lua b/lua/plugins/colorizer.lua new file mode 100644 index 0000000..416f2d1 --- /dev/null +++ b/lua/plugins/colorizer.lua @@ -0,0 +1,6 @@ +return { + 'norcalli/nvim-colorizer.lua', + config = function() + require('colorizer').setup() + end, +} diff --git a/lua/plugins/devicons.lua b/lua/plugins/devicons.lua new file mode 100644 index 0000000..9e69c5f --- /dev/null +++ b/lua/plugins/devicons.lua @@ -0,0 +1,11 @@ + +return { + 'nvim-tree/nvim-web-devicons', + config = function() + require'nvim-web-devicons'.setup { + color_icons = true; + default = true; + strict = true; + } + end, +} diff --git a/lua/plugins/gitsigns.lua b/lua/plugins/gitsigns.lua new file mode 100644 index 0000000..d88bf68 --- /dev/null +++ b/lua/plugins/gitsigns.lua @@ -0,0 +1,6 @@ +return { + 'lewis6991/gitsigns.nvim', + config = function() + require('gitsigns').setup() + end, +} diff --git a/lua/plugins/orgmode.lua b/lua/plugins/orgmode.lua index fe09f3e..a9d6ea0 100644 --- a/lua/plugins/orgmode.lua +++ b/lua/plugins/orgmode.lua @@ -3,15 +3,9 @@ return { event = 'VeryLazy', ft = { 'org' }, config = function() - -- Setup orgmode require('orgmode').setup({ org_agenda_files = '~/orgfiles/**/*', org_default_notes_file = '~/orgfiles/refile.org', }) - require('cmp').setup({ - sources = { - { name = 'orgmode' } - } - }) end, } diff --git a/lua/plugins/popup.lua b/lua/plugins/popup.lua new file mode 100644 index 0000000..0ff2e3a --- /dev/null +++ b/lua/plugins/popup.lua @@ -0,0 +1,5 @@ +return { + 'nvim-lua/plenary.nvim', + 'nvim-lua/popup.nvim', +} + diff --git a/lua/plugins/telescope.lua b/lua/plugins/telescope.lua index ed65c3f..fee09df 100644 --- a/lua/plugins/telescope.lua +++ b/lua/plugins/telescope.lua @@ -1,4 +1,15 @@ return { 'nvim-telescope/telescope.nvim', - 'nvim-telescope/telescope-media-files.nvim', + dependencies = { + 'nvim-telescope/telescope-media-files.nvim' + }, + config = function() + require('telescope').load_extension('media_files') + + local builtin = require('telescope.builtin') + vim.keymap.set('n', 'ff', builtin.find_files, {}) + vim.keymap.set('n', 'fg', builtin.live_grep, {}) + vim.keymap.set('n', 'fb', builtin.buffers, {}) + vim.keymap.set('n', 'fh', builtin.help_tags, {}) + end, } diff --git a/lua/plugins/treesitter.lua b/lua/plugins/treesitter.lua new file mode 100644 index 0000000..9673f63 --- /dev/null +++ b/lua/plugins/treesitter.lua @@ -0,0 +1,20 @@ +return { + -- treesitter is experimental and breaks indentation on xml, html with `=` + -- treesitter is optional for orgmode, but without it syntax highlighting in + -- org files is broken + 'nvim-treesitter/nvim-treesitter', + config = function() + require'nvim-treesitter.configs'.setup { + ensure_installed = {"c", "html", "css", "javascript", "org"}, + sync_install = false, + auto_install = true, + ignore_install = {}, + disable = { }, + modules = { "all" }, + highlight = { + enable = true, + } + } + end +} + diff --git a/vimrc b/vimrc index f3b1833..3d96799 100644 --- a/vimrc +++ b/vimrc @@ -1,6 +1,7 @@ "======================================================================================================================= " GENERAL "======================================================================================================================= +set termguicolors filetype on filetype plugin on @@ -24,9 +25,10 @@ set hlsearch incsearch | " highlight pattern while entering i " set cindent cinoptions+=(0 | " indents at the level of parentheses -- if desired set expandtab | " replace tabs with spaces set textwidth=0 | " should be set file type specific, colorcolumns is there to assist anyways -set tabstop=4 -set shiftwidth=4 -set softtabstop=4 + +set tabstop=2 | " I am sorry, but 2 is simply better +set shiftwidth=2 | " . +set softtabstop=2 | " . "======================================================================================================================= " PATH -- where to search for includes (e.g. `gf` or `:find`) @@ -386,4 +388,4 @@ augroup END "======================================================================================================================= " v modeline, do not chnage v -" vim: noai:ts=2:sw=2:sts=2 iskeyword+=\:,\<,\>,\-,\& number +" vim: noai:ts=2:sw=2:sts=2 iskeyword+=\:\<,\>,\-,\& number -- cgit v1.2.3