From a35b743b6244991bb05a5b42ce4dd6930c3e105c Mon Sep 17 00:00:00 2001 From: Vladan Popovic Date: Wed, 20 Mar 2024 12:49:43 +0100 Subject: [PATCH] remove obsolete config and autoformat --- init.lua | 1 - lua/filetypes.lua | 4 - lua/lsp.lua | 23 +++--- lua/plugins/cmp.lua | 36 ++++----- lua/plugins/gitsigns.lua | 76 +++++++++--------- lua/plugins/init.lua | 144 +++++++++++++++++------------------ lua/plugins/neogit.lua | 2 +- lua/plugins/packer_setup.lua | 4 +- lua/plugins/venn.lua | 19 ++--- lua/settings.lua | 6 ++ lua/utils.lua | 10 +-- 11 files changed, 165 insertions(+), 160 deletions(-) delete mode 100644 lua/filetypes.lua diff --git a/init.lua b/init.lua index dc312bd..195a73d 100644 --- a/init.lua +++ b/init.lua @@ -5,6 +5,5 @@ vim.g.mapleader = ' ' require('settings') require('plugins') require('lsp') -require('filetypes') require('theme') require('keymappings') diff --git a/lua/filetypes.lua b/lua/filetypes.lua deleted file mode 100644 index d29f858..0000000 --- a/lua/filetypes.lua +++ /dev/null @@ -1,4 +0,0 @@ -vim.cmd([[ - autocmd BufRead,BufNewFile *.bu set filetype=yaml - autocmd BufRead,BufNewFile *.ign set filetype=json -]]) diff --git a/lua/lsp.lua b/lua/lsp.lua index 0263b8d..e133dfa 100644 --- a/lua/lsp.lua +++ b/lua/lsp.lua @@ -13,6 +13,9 @@ local on_attach = function(client, bufnr) utils.map("n", "wa", "lua vim.lsp.buf.add_workspace_folder()") utils.map("n", "wr", "lua vim.lsp.buf.remove_workspace_folder()") + -- use vim's default coloring + client.server_capabilities.semanticTokensProvider = nil + if client.supports_method("textDocument/formatting") then vim.api.nvim_clear_autocmds({ group = augroup, buffer = bufnr }) vim.api.nvim_create_autocmd("BufWritePre", { @@ -30,18 +33,18 @@ local capabilities = vim.lsp.protocol.make_client_capabilities() -- LSPs local servers = { - "clangd", - "gleam", - "lua_ls", - "ocamllsp", - "pyright", - "rnix", - "ruff_lsp", - "terraformls", - "vimls", + "clangd", + "gleam", + "lua_ls", + "ocamllsp", + "pyright", + "rnix", + "ruff_lsp", + "terraformls", + "vimls", } for _, lsp in ipairs(servers) do - nvim_lsp[lsp].setup {capabilities = capabilities, on_attach = on_attach} + nvim_lsp[lsp].setup { capabilities = capabilities, on_attach = on_attach } end nvim_lsp.rust_analyzer.setup({ diff --git a/lua/plugins/cmp.lua b/lua/plugins/cmp.lua index d5829df..ac714a6 100644 --- a/lua/plugins/cmp.lua +++ b/lua/plugins/cmp.lua @@ -58,35 +58,37 @@ cmp.setup({ end, }, window = { - completion = cmp.config.window.bordered(), - documentation = cmp.config.window.bordered(), + completion = cmp.config.window.bordered(), + documentation = cmp.config.window.bordered(), }, completion = { autocomplete = false, }, 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 = false }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. + [''] = cmp.mapping.scroll_docs(-4), + [''] = cmp.mapping.scroll_docs(4), + [''] = cmp.mapping.complete(), + [''] = cmp.mapping.abort(), + -- Accept currently selected item. + -- Set `select` to `false` to only confirm explicitly selected items. + [''] = cmp.mapping.confirm({ select = false }), }), sources = cmp.config.sources({ - { name = 'nvim_lsp' }, - { name = 'luasnip' }, -- For luasnip users. + { name = 'nvim_lsp' }, + { name = 'luasnip' }, }, { - { name = 'buffer' }, + { name = 'buffer' }, }) }) -- Set configuration for specific filetype. ---cmp.setup.filetype('gitcommit', { --- sources = cmp.config.sources({ --- { name = 'git' }, -- You can specify the `git` source if [you were installed it](https://github.com/petertriho/cmp-git). --- }, { --- { name = 'buffer' }, --- }) ---}) +cmp.setup.filetype('gitcommit', { + sources = cmp.config.sources({ + { name = 'git' }, + }, { + { name = 'buffer' }, + }) +}) -- Use buffer source for `/` and `?` (if you enabled `native_menu`, this won't work anymore). cmp.setup.cmdline({ '/', '?' }, { diff --git a/lua/plugins/gitsigns.lua b/lua/plugins/gitsigns.lua index 6a4f422..8b5ba0a 100644 --- a/lua/plugins/gitsigns.lua +++ b/lua/plugins/gitsigns.lua @@ -1,42 +1,42 @@ require('gitsigns').setup { - on_attach = function(bufnr) - local gs = package.loaded.gitsigns + on_attach = function(bufnr) + local gs = package.loaded.gitsigns - local function map(mode, l, r, opts) - opts = opts or {} - opts.buffer = bufnr - vim.keymap.set(mode, l, r, opts) + local function map(mode, l, r, opts) + opts = opts or {} + opts.buffer = bufnr + vim.keymap.set(mode, l, r, opts) + end + + -- Navigation + map('n', ']c', function() + if vim.wo.diff then return ']c' end + vim.schedule(function() gs.next_hunk() end) + return '' + end, { expr = true }) + + map('n', '[c', function() + if vim.wo.diff then return '[c' end + vim.schedule(function() gs.prev_hunk() end) + return '' + end, { expr = true }) + + -- Actions + map('n', 'hs', gs.stage_hunk) + map('n', 'hr', gs.reset_hunk) + map('v', 'hs', function() gs.stage_hunk { vim.fn.line('.'), vim.fn.line('v') } end) + map('v', 'hr', function() gs.reset_hunk { vim.fn.line('.'), vim.fn.line('v') } end) + map('n', 'hS', gs.stage_buffer) + map('n', 'hu', gs.undo_stage_hunk) + map('n', 'hR', gs.reset_buffer) + map('n', 'hp', gs.preview_hunk) + map('n', 'hb', function() gs.blame_line { full = true } end) + map('n', 'tb', gs.toggle_current_line_blame) + map('n', 'hd', gs.diffthis) + map('n', 'hD', function() gs.diffthis('~') end) + map('n', 'td', gs.toggle_deleted) + + -- Text object + map({ 'o', 'x' }, 'ih', ':Gitsigns select_hunk') end - - -- Navigation - map('n', ']c', function() - if vim.wo.diff then return ']c' end - vim.schedule(function() gs.next_hunk() end) - return '' - end, {expr=true}) - - map('n', '[c', function() - if vim.wo.diff then return '[c' end - vim.schedule(function() gs.prev_hunk() end) - return '' - end, {expr=true}) - - -- Actions - map('n', 'hs', gs.stage_hunk) - map('n', 'hr', gs.reset_hunk) - map('v', 'hs', function() gs.stage_hunk {vim.fn.line('.'), vim.fn.line('v')} end) - map('v', 'hr', function() gs.reset_hunk {vim.fn.line('.'), vim.fn.line('v')} end) - map('n', 'hS', gs.stage_buffer) - map('n', 'hu', gs.undo_stage_hunk) - map('n', 'hR', gs.reset_buffer) - map('n', 'hp', gs.preview_hunk) - map('n', 'hb', function() gs.blame_line{full=true} end) - map('n', 'tb', gs.toggle_current_line_blame) - map('n', 'hd', gs.diffthis) - map('n', 'hD', function() gs.diffthis('~') end) - map('n', 'td', gs.toggle_deleted) - - -- Text object - map({'o', 'x'}, 'ih', ':Gitsigns select_hunk') - end } diff --git a/lua/plugins/init.lua b/lua/plugins/init.lua index 0fdfe46..27b2b4f 100644 --- a/lua/plugins/init.lua +++ b/lua/plugins/init.lua @@ -1,88 +1,86 @@ require('plugins.packer_setup') require('packer').startup(function() + -- Packer can manage itself as an optional plugin + use { 'wbthomason/packer.nvim', opt = true } - -- Packer can manage itself as an optional plugin - use {'wbthomason/packer.nvim', opt = true } + -- Fuzzy finder + use { + 'nvim-telescope/telescope.nvim', + requires = { + { 'nvim-lua/popup.nvim' }, + { 'nvim-lua/plenary.nvim' }, + } + } - -- Fuzzy finder - use { - 'nvim-telescope/telescope.nvim', - requires = { - {'nvim-lua/popup.nvim'}, - {'nvim-lua/plenary.nvim'}, - } - } + -- Autocomplete and snippets + use { + 'hrsh7th/nvim-cmp', + requires = { + { 'hrsh7th/cmp-nvim-lsp' }, + { 'hrsh7th/cmp-buffer' }, + { 'hrsh7th/cmp-path' }, + { 'hrsh7th/cmp-cmdline' }, + } + } + use { 'L3MON4D3/LuaSnip', + config = function() + local snippet_path = os.getenv("HOME") .. "/.config/nvim/snippets/" + if not vim.tbl_contains(vim.opt.rtp:get(), snippet_path) then + vim.opt.rtp:append(snippet_path) + end - -- Autocomplete and snippets - use { - 'hrsh7th/nvim-cmp', - requires = { - { 'hrsh7th/cmp-nvim-lsp' }, - { 'hrsh7th/cmp-buffer' }, - { 'hrsh7th/cmp-path' }, - { 'hrsh7th/cmp-cmdline' }, - } - } - use { 'L3MON4D3/LuaSnip', - config = function () - local snippet_path = os.getenv("HOME") .. "/.config/nvim/snippets/" - if not vim.tbl_contains(vim.opt.rtp:get(), snippet_path) then - vim.opt.rtp:append(snippet_path) - end + require("luasnip").config.set_config({ + history = true, + updateevents = "TextChanged,TextChangedI", + delete_check_events = "TextChanged,InsertLeave", + }) + require("luasnip.loaders.from_lua").lazy_load() + require("luasnip.loaders.from_vscode").lazy_load() + require("luasnip.loaders.from_snipmate").lazy_load() + end, + requires = { + { "rafamadriz/friendly-snippets" }, + { 'saadparwaiz1/cmp_luasnip' }, + { "benfowler/telescope-luasnip.nvim" }, + }, + } - require("luasnip").config.set_config({ - history = true, - updateevents = "TextChanged,TextChangedI", - delete_check_events = "TextChanged,InsertLeave", - }) - require("luasnip.loaders.from_lua").lazy_load() - require("luasnip.loaders.from_vscode").lazy_load() - require("luasnip.loaders.from_snipmate").lazy_load() - end, - requires = { - { "rafamadriz/friendly-snippets" }, - { 'saadparwaiz1/cmp_luasnip' }, - { "benfowler/telescope-luasnip.nvim" }, - }, - } + -- Statusbar, colors and syntax + use { 'vim-airline/vim-airline' } + use { 'vim-airline/vim-airline-themes' } - -- Statusbar, colors and syntax - use { 'vim-airline/vim-airline' } - use { 'vim-airline/vim-airline-themes' } + -- LSP and related + use { 'neovim/nvim-lspconfig' } + use { 'aznhe21/actions-preview.nvim', + config = function() + vim.keymap.set("n", "ca", require("actions-preview").code_actions) + end, + } + use { 'folke/trouble.nvim' } -- lsp diagnostics - -- LSP and related - use { 'neovim/nvim-lspconfig' } - use { 'aznhe21/actions-preview.nvim', - config = function() - vim.keymap.set("n", "ca", require("actions-preview").code_actions) - end, - } - use { 'folke/trouble.nvim' } -- lsp diagnostics + -- Plugins to extend builtin language support + use { 'cespare/vim-toml' } + use { 'gleam-lang/gleam.vim' } + use { 'rust-lang/rust.vim' } + use { 'folke/neodev.nvim' } - -- Plugins to extend builtin language support - use { 'cespare/vim-toml' } - use { 'gleam-lang/gleam.vim' } - use { 'rust-lang/rust.vim' } - use { 'folke/neodev.nvim' } + -- Git + use { + 'NeogitOrg/neogit', + requires = { + { "nvim-lua/plenary.nvim" }, + { "sindrets/diffview.nvim" }, + }, + } + use { "lewis6991/gitsigns.nvim" } - -- Git - use { - 'NeogitOrg/neogit', - requires = { - { "nvim-lua/plenary.nvim" }, - { "sindrets/diffview.nvim" }, - }, - } - use { "lewis6991/gitsigns.nvim" } - - -- Filesystem browser - use { 'stevearc/oil.nvim' } - - -- Misc - use { 'jbyuki/venn.nvim' } -- ascii diagrams - use { 'hashivim/vim-terraform' } + -- Filesystem browser + use { 'stevearc/oil.nvim' } + -- Misc + use { 'jbyuki/venn.nvim' } -- ascii diagrams + use { 'hashivim/vim-terraform' } end) require('plugins.cmp') diff --git a/lua/plugins/neogit.lua b/lua/plugins/neogit.lua index b08d583..605e648 100644 --- a/lua/plugins/neogit.lua +++ b/lua/plugins/neogit.lua @@ -1,5 +1,5 @@ local neogit = require('neogit') -neogit.setup { } +neogit.setup {} vim.keymap.set('n', '', neogit.open, {}) diff --git a/lua/plugins/packer_setup.lua b/lua/plugins/packer_setup.lua index 12ddb2a..9d1f10b 100644 --- a/lua/plugins/packer_setup.lua +++ b/lua/plugins/packer_setup.lua @@ -1,7 +1,7 @@ -- Auto install packer.nvim if not exists -local install_path = vim.fn.stdpath('data')..'/site/pack/packer/opt/packer.nvim' +local install_path = vim.fn.stdpath('data') .. '/site/pack/packer/opt/packer.nvim' if vim.fn.empty(vim.fn.glob(install_path)) > 0 then - vim.api.nvim_command('!git clone https://github.com/wbthomason/packer.nvim '..install_path) + vim.api.nvim_command('!git clone https://github.com/wbthomason/packer.nvim ' .. install_path) end vim.cmd [[packadd packer.nvim]] diff --git a/lua/plugins/venn.lua b/lua/plugins/venn.lua index 1a808b9..ee4f49c 100644 --- a/lua/plugins/venn.lua +++ b/lua/plugins/venn.lua @@ -3,19 +3,20 @@ function _G.Toggle_venn() local venn_enabled = vim.inspect(vim.b.venn_enabled) if venn_enabled == "nil" then vim.b.venn_enabled = true - vim.cmd[[setlocal ve=all]] + vim.cmd [[setlocal ve=all]] -- draw a line on HJKL keystokes - vim.api.nvim_buf_set_keymap(0, "n", "J", "j:VBox", {noremap = true}) - vim.api.nvim_buf_set_keymap(0, "n", "K", "k:VBox", {noremap = true}) - vim.api.nvim_buf_set_keymap(0, "n", "L", "l:VBox", {noremap = true}) - vim.api.nvim_buf_set_keymap(0, "n", "H", "h:VBox", {noremap = true}) + vim.api.nvim_buf_set_keymap(0, "n", "J", "j:VBox", { noremap = true }) + vim.api.nvim_buf_set_keymap(0, "n", "K", "k:VBox", { noremap = true }) + vim.api.nvim_buf_set_keymap(0, "n", "L", "l:VBox", { noremap = true }) + vim.api.nvim_buf_set_keymap(0, "n", "H", "h:VBox", { noremap = true }) -- draw a box by pressing "f" with visual selection - vim.api.nvim_buf_set_keymap(0, "v", "f", ":VBox", {noremap = true}) + vim.api.nvim_buf_set_keymap(0, "v", "f", ":VBox", { noremap = true }) else - vim.cmd[[setlocal ve=]] - vim.cmd[[mapclear ]] + vim.cmd [[setlocal ve=]] + vim.cmd [[mapclear ]] vim.b.venn_enabled = nil end end + -- toggle keymappings for venn using v -vim.api.nvim_set_keymap('n', 'v', ":lua Toggle_venn()", { noremap = true}) +vim.api.nvim_set_keymap('n', 'v', ":lua Toggle_venn()", { noremap = true }) diff --git a/lua/settings.lua b/lua/settings.lua index 0f52b6a..589094e 100644 --- a/lua/settings.lua +++ b/lua/settings.lua @@ -33,3 +33,9 @@ vim.opt.undofile = true -- Enable vimrc files per project and disable unsafe commands in project vimrc vim.opt.exrc = true vim.opt.secure = true + +-- unknown filetypes mappings +vim.cmd([[ + autocmd BufRead,BufNewFile *.bu set filetype=yaml + autocmd BufRead,BufNewFile *.ign set filetype=json +]]) diff --git a/lua/utils.lua b/lua/utils.lua index 846e425..8411ee5 100644 --- a/lua/utils.lua +++ b/lua/utils.lua @@ -1,6 +1,6 @@ -local utils = { } +local utils = {} -local scopes = {o = vim.o, b = vim.bo, w = vim.wo} +local scopes = { o = vim.o, b = vim.bo, w = vim.wo } function utils.opt(scope, key, value) scopes[scope][key] = value @@ -8,9 +8,9 @@ function utils.opt(scope, key, value) end function utils.map(mode, lhs, rhs, opts) - local options = { noremap = true, silent = true } - if opts then options = vim.tbl_extend('force', options, opts) end - vim.api.nvim_set_keymap(mode, lhs, rhs, options) + local options = { noremap = true, silent = true } + if opts then options = vim.tbl_extend('force', options, opts) end + vim.api.nvim_set_keymap(mode, lhs, rhs, options) end return utils