refacto: migrate from packer to lazy for plugin management

This commit is contained in:
Nydragon 2024-04-01 20:07:18 +09:00
parent 19eb865542
commit 97ccdab2a8
13 changed files with 318 additions and 311 deletions

View file

@ -1,16 +1,14 @@
vim.g.ale_fixers = { vim.g.ale_fixers = {
['*'] = { ["*"] = {
'remove_trailing_lines', "remove_trailing_lines",
'trim_whitespace' "trim_whitespace",
}, },
["lua"] = { ["lua"] = {
"lua-format" "lua-format",
}, },
["rust"] = { ["rust"] = {
"rustfmt" "rustfmt",
},
} }
}
vim.g.ale_fix_on_save = 1 vim.g.ale_fix_on_save = 1

View file

@ -1,5 +1,4 @@
require('autoclose').setup( return {
{
keys = { keys = {
["("] = { escape = false, close = true, pair = "()" }, ["("] = { escape = false, close = true, pair = "()" },
["["] = { escape = false, close = true, pair = "[]" }, ["["] = { escape = false, close = true, pair = "[]" },
@ -23,4 +22,3 @@ require('autoclose').setup(
disable_command_mode = false, disable_command_mode = false,
}, },
} }
)

View file

@ -2,15 +2,15 @@ local map = vim.api.nvim_set_keymap
local opts = { noremap = true, silent = true } local opts = { noremap = true, silent = true }
-- Move to previous/next -- Move to previous/next
map('n', '<A-,>', '<Cmd>BufferPrevious<CR>', opts) map("n", "<A-,>", "<Cmd>BufferPrevious<CR>", opts)
-- Goto buffer in position... -- Goto buffer in position...
map('n', '<A-1>', '<Cmd>BufferGoto 1<CR>', opts) map("n", "<A-1>", "<Cmd>BufferGoto 1<CR>", opts)
map('n', '<A-2>', '<Cmd>BufferGoto 2<CR>', opts) map("n", "<A-2>", "<Cmd>BufferGoto 2<CR>", opts)
map('n', '<A-3>', '<Cmd>BufferGoto 3<CR>', opts) map("n", "<A-3>", "<Cmd>BufferGoto 3<CR>", opts)
map('n', '<A-4>', '<Cmd>BufferGoto 4<CR>', opts) map("n", "<A-4>", "<Cmd>BufferGoto 4<CR>", opts)
map('n', '<A-5>', '<Cmd>BufferGoto 5<CR>', opts) map("n", "<A-5>", "<Cmd>BufferGoto 5<CR>", opts)
map('n', '<A-6>', '<Cmd>BufferGoto 6<CR>', opts) map("n", "<A-6>", "<Cmd>BufferGoto 6<CR>", opts)
map('n', '<A-7>', '<Cmd>BufferGoto 7<CR>', opts) map("n", "<A-7>", "<Cmd>BufferGoto 7<CR>", opts)
map('n', '<A-8>', '<Cmd>BufferGoto 8<CR>', opts) map("n", "<A-8>", "<Cmd>BufferGoto 8<CR>", opts)
map('n', '<A-9>', '<Cmd>BufferGoto 9<CR>', opts) map("n", "<A-9>", "<Cmd>BufferGoto 9<CR>", opts)
map('n', '<A-0>', '<Cmd>BufferLast<CR>', opts) map("n", "<A-0>", "<Cmd>BufferLast<CR>", opts)

View file

@ -1,8 +0,0 @@
integration = {
telescope = {
enable = true,
-- Optional, you can use any telescope supported theme
theme = require("telescope.themes").commander,
},
},
})

View file

@ -1,6 +1,9 @@
local util = require("formatter.util") local util = require("formatter.util")
require("formatter").setup({ local M = {}
local function build()
return {
logging = true, logging = true,
log_level = vim.log.levels.WARN, log_level = vim.log.levels.WARN,
filetype = { filetype = {
@ -20,4 +23,9 @@ require("formatter").setup({
require("formatter.filetypes.any").remove_trailing_whitespace, require("formatter.filetypes.any").remove_trailing_whitespace,
}, },
}, },
}) }
end
M.build = build
return M

View file

@ -1,21 +1,21 @@
local ht = require('haskell-tools') local ht = require("haskell-tools")
local def_opts = { noremap = true, silent = true, } local def_opts = { noremap = true, silent = true }
ht.setup { ht.setup({
hls = { hls = {
on_attach = function(client, bufnr) on_attach = function(client, bufnr)
local opts = vim.tbl_extend('keep', def_opts, { buffer = bufnr, }) local opts = vim.tbl_extend("keep", def_opts, { buffer = bufnr })
-- haskell-language-server relies heavily on codeLenses, -- haskell-language-server relies heavily on codeLenses,
-- so auto-refresh (see advanced configuration) is enabled by default -- so auto-refresh (see advanced configuration) is enabled by default
vim.keymap.set('n', '<space>ca', vim.lsp.codelens.run, opts) vim.keymap.set("n", "<space>ca", vim.lsp.codelens.run, opts)
vim.keymap.set('n', '<space>hs', ht.hoogle.hoogle_signature, opts) vim.keymap.set("n", "<space>hs", ht.hoogle.hoogle_signature, opts)
end, end,
}, },
} })
-- Suggested keymaps that do not depend on haskell-language-server -- Suggested keymaps that do not depend on haskell-language-server
-- Toggle a GHCi repl for the current package -- Toggle a GHCi repl for the current package
vim.keymap.set('n', '<leader>rr', ht.repl.toggle, def_opts) vim.keymap.set("n", "<leader>rr", ht.repl.toggle, def_opts)
-- Toggle a GHCi repl for the current buffer -- Toggle a GHCi repl for the current buffer
vim.keymap.set('n', '<leader>rf', function() vim.keymap.set("n", "<leader>rf", function()
ht.repl.toggle(vim.api.nvim_buf_get_name(0)) ht.repl.toggle(vim.api.nvim_buf_get_name(0))
end, def_opts) end, def_opts)
vim.keymap.set('n', '<leader>rq', ht.repl.quit, def_opts) vim.keymap.set("n", "<leader>rq", ht.repl.quit, def_opts)

View file

@ -1,11 +1,11 @@
require('nightfox').setup({ require("nightfox").setup({
options = { options = {
styles = { styles = {
comments = "italic", comments = "italic",
keywords = "bold", keywords = "bold",
types = "italic,bold", types = "italic,bold",
} },
} },
}) })
vim.cmd("colorscheme carbonfox") vim.cmd("colorscheme carbonfox")

View file

@ -1,10 +1,10 @@
local has_words_before = function() local has_words_before = function()
unpack = unpack or table.unpack unpack = unpack or table.unpack
local line, col = unpack(vim.api.nvim_win_get_cursor(0)) local line, col = unpack(vim.api.nvim_win_get_cursor(0))
return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match('%s') == nil return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil
end end
local cmp = require 'cmp' local cmp = require("cmp")
cmp.setup({ cmp.setup({
snippet = { snippet = {
@ -21,14 +21,14 @@ cmp.setup({
-- documentation = cmp.config.window.bordered(), -- documentation = cmp.config.window.bordered(),
}, },
mapping = cmp.mapping.preset.insert({ mapping = cmp.mapping.preset.insert({
['<C-Space>'] = cmp.mapping.confirm { ["<C-Space>"] = cmp.mapping.confirm({
behavior = cmp.ConfirmBehavior.Insert, behavior = cmp.ConfirmBehavior.Insert,
select = true, select = true,
}, }),
['<Tab>'] = function(fallback) ["<Tab>"] = function(fallback)
if not cmp.select_next_item() then if not cmp.select_next_item() then
if vim.bo.buftype ~= 'prompt' and has_words_before() then if vim.bo.buftype ~= "prompt" and has_words_before() then
cmp.complete() cmp.complete()
else else
fallback() fallback()
@ -36,9 +36,9 @@ cmp.setup({
end end
end, end,
['<S-Tab>'] = function(fallback) ["<S-Tab>"] = function(fallback)
if not cmp.select_prev_item() then if not cmp.select_prev_item() then
if vim.bo.buftype ~= 'prompt' and has_words_before() then if vim.bo.buftype ~= "prompt" and has_words_before() then
cmp.complete() cmp.complete()
else else
fallback() fallback()
@ -47,46 +47,46 @@ cmp.setup({
end, end,
}), }),
sources = cmp.config.sources({ sources = cmp.config.sources({
{ name = 'nvim_lsp' }, { name = "nvim_lsp" },
{ name = 'vsnip' }, -- For vsnip users. { name = "vsnip" }, -- For vsnip users.
-- { name = 'luasnip' }, -- For luasnip users. -- { name = 'luasnip' }, -- For luasnip users.
-- { name = 'ultisnips' }, -- For ultisnips users. -- { name = 'ultisnips' }, -- For ultisnips users.
-- { name = 'snippy' }, -- For snippy users. -- { name = 'snippy' }, -- For snippy users.
}, { }, {
{ name = 'buffer' }, { name = "buffer" },
}) }),
}) })
-- Set configuration for specific filetype. -- Set configuration for specific filetype.
cmp.setup.filetype('gitcommit', { cmp.setup.filetype("gitcommit", {
sources = cmp.config.sources({ sources = cmp.config.sources({
{ name = 'cmp_git' }, -- You can specify the `cmp_git` source if you were installed it. { name = "cmp_git" }, -- You can specify the `cmp_git` source if you were installed it.
}, { }, {
{ name = 'buffer' }, { name = "buffer" },
}) }),
}) })
-- Use buffer source for `/` and `?` (if you enabled `native_menu`, this won't work anymore). -- Use buffer source for `/` and `?` (if you enabled `native_menu`, this won't work anymore).
cmp.setup.cmdline({ '/', '?' }, { cmp.setup.cmdline({ "/", "?" }, {
mapping = cmp.mapping.preset.cmdline(), mapping = cmp.mapping.preset.cmdline(),
sources = { sources = {
{ name = 'buffer' } { name = "buffer" },
} },
}) })
-- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore). -- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore).
cmp.setup.cmdline(':', { cmp.setup.cmdline(":", {
mapping = cmp.mapping.preset.cmdline(), mapping = cmp.mapping.preset.cmdline(),
sources = cmp.config.sources({ sources = cmp.config.sources({
{ name = 'path' } { name = "path" },
}, { }, {
{ name = 'cmdline' } { name = "cmdline" },
}) }),
}) })
-- Set up lspconfig. -- Set up lspconfig.
local capabilities = require('cmp_nvim_lsp').default_capabilities() local capabilities = require("cmp_nvim_lsp").default_capabilities()
-- Replace <YOUR_LSP_SERVER> with each lsp server you've enabled. -- Replace <YOUR_LSP_SERVER> with each lsp server you've enabled.
require('lspconfig')['pyright'].setup { require("lspconfig")["pyright"].setup({
capabilities = capabilities capabilities = capabilities,
} })

View file

@ -1,45 +1,46 @@
-- Mappings. -- Mappings.
-- See `:help vim.diagnostic.*` for documentation on any of the below functions -- See `:help vim.diagnostic.*` for documentation on any of the below functions
local opts = { noremap = true, silent = true } local opts = { noremap = true, silent = true }
vim.keymap.set('n', '<space>e', vim.diagnostic.open_float, opts) vim.keymap.set("n", "<space>e", vim.diagnostic.open_float, opts)
vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, opts) vim.keymap.set("n", "[d", vim.diagnostic.goto_prev, opts)
vim.keymap.set('n', ']d', vim.diagnostic.goto_next, opts) vim.keymap.set("n", "]d", vim.diagnostic.goto_next, opts)
vim.keymap.set('n', '<space>q', vim.diagnostic.setloclist, opts) vim.keymap.set("n", "<space>q", vim.diagnostic.setloclist, opts)
-- Use an on_attach function to only map the following keys -- Use an on_attach function to only map the following keys
-- after the language server attaches to the current buffer -- after the language server attaches to the current buffer
local on_attach = function(client, bufnr) local on_attach = function(client, bufnr)
-- Enable completion triggered by <c-x><c-o> -- Enable completion triggered by <c-x><c-o>
vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc') vim.api.nvim_buf_set_option(bufnr, "omnifunc", "v:lua.vim.lsp.omnifunc")
-- Mappings. -- Mappings.
-- See `:help vim.lsp.*` for documentation on any of the below functions -- See `:help vim.lsp.*` for documentation on any of the below functions
local bufopts = { noremap = true, silent = true, buffer = bufnr } 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.declaration, bufopts)
vim.keymap.set('n', 'gd', vim.lsp.buf.definition, 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", "K", vim.lsp.buf.hover, bufopts)
vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, bufopts) vim.keymap.set("n", "gi", vim.lsp.buf.implementation, bufopts)
vim.keymap.set('n', '<C-k>', vim.lsp.buf.signature_help, bufopts) vim.keymap.set("n", "<C-k>", vim.lsp.buf.signature_help, bufopts)
vim.keymap.set('n', '<space>wa', vim.lsp.buf.add_workspace_folder, bufopts) vim.keymap.set("n", "<space>wa", vim.lsp.buf.add_workspace_folder, bufopts)
vim.keymap.set('n', '<space>wr', vim.lsp.buf.remove_workspace_folder, bufopts) vim.keymap.set("n", "<space>wr", vim.lsp.buf.remove_workspace_folder, bufopts)
vim.keymap.set('n', '<space>wl', function() vim.keymap.set("n", "<space>wl", function()
print(vim.inspect(vim.lsp.buf.list_workspace_folders())) print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
end, bufopts) end, bufopts)
vim.keymap.set('n', '<space>D', vim.lsp.buf.type_definition, bufopts) vim.keymap.set("n", "<space>D", vim.lsp.buf.type_definition, bufopts)
vim.keymap.set('n', '<space>rn', vim.lsp.buf.rename, bufopts) vim.keymap.set("n", "<space>rn", vim.lsp.buf.rename, bufopts)
vim.keymap.set('n', '<space>ca', vim.lsp.buf.code_action, bufopts) vim.keymap.set("n", "<space>ca", vim.lsp.buf.code_action, bufopts)
vim.keymap.set('n', 'gr', vim.lsp.buf.references, bufopts) vim.keymap.set("n", "gr", vim.lsp.buf.references, bufopts)
vim.keymap.set('n', '<space>f', function() vim.lsp.buf.format { async = true } end, bufopts) vim.keymap.set("n", "<space>f", function()
vim.lsp.buf.format({ async = true })
end, bufopts)
end end
local lsp_flags = { local lsp_flags = {
-- This is the default in Nvim 0.7+ -- This is the default in Nvim 0.7+
debounce_text_changes = 150, debounce_text_changes = 150,
} }
require('lspconfig')['pyright'].setup { require("lspconfig")["pyright"].setup({
on_attach = on_attach, on_attach = on_attach,
flags = lsp_flags, flags = lsp_flags,
} })
require 'lspconfig'.clangd.setup {} require("lspconfig").clangd.setup({})

View file

@ -1,12 +1,6 @@
vim.g.loaded_netrw = 1 vim.g.loaded_netrw = 1
vim.g.loaded_netrwPlugin = 1 vim.g.loaded_netrwPlugin = 1
require("nvim-tree").setup({
filters = {
dotfiles = false,
git_ignored = false,
},
})
local function open_nvim_tree(data) local function open_nvim_tree(data)
-- buffer is a real file on the disk -- buffer is a real file on the disk

View file

@ -1,104 +1,129 @@
local ensure_packer = function() local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
local fn = vim.fn if not (vim.uv or vim.loop).fs_stat(lazypath) then
local install_path = fn.stdpath("data") .. "/site/pack/packer/start/packer.nvim" vim.fn.system({
if fn.empty(fn.glob(install_path)) > 0 then "git",
fn.system({ "git", "clone", "--depth", "1", "https://github.com/wbthomason/packer.nvim", install_path }) "clone",
vim.cmd([[packadd packer.nvim]]) "--filter=blob:none",
return true "https://github.com/folke/lazy.nvim.git",
end "--branch=stable", -- latest stable release
return false lazypath,
})
end end
vim.opt.rtp:prepend(lazypath)
local packer_bootstrap = ensure_packer() require("lazy").setup({
require("keybinding") {
return require("packer").startup(function(use)
use("wbthomason/packer.nvim")
use({
"nvim-tree/nvim-tree.lua", "nvim-tree/nvim-tree.lua",
requires = { dependencies = {
"nvim-tree/nvim-web-devicons", -- optional, for file icons "nvim-tree/nvim-web-devicons", -- optional, for file icons
}, },
}) init = function()
require("nvim-tree-config")
use({ end,
"nvim-lualine/lualine.nvim", opts = {
requires = { filters = {
dotfiles = false,
git_ignored = false,
},
},
},
{
"nvim-tree/nvim-tree.lua",
dependencies = {
"nvim-tree/nvim-web-devicons", -- optional, for file icons "nvim-tree/nvim-web-devicons", -- optional, for file icons
}, },
}) init = function()
require("nvim-tree-config")
use({ end,
},
{
"romgrk/barbar.nvim", "romgrk/barbar.nvim",
requires = { "nvim-web-devicons", "lewis6991/gitsigns.nvim" }, dependencies = {
}) "nvim-tree/nvim-web-devicons", -- optional, for file icons
"lewis6991/gitsigns.nvim",
use("nvim-treesitter/nvim-treesitter") },
init = function()
use("neovim/nvim-lspconfig") -- Configurations for Nvim LSP require("barbar-config")
use("simrat39/rust-tools.nvim") end,
},
-- (batch)commenting tool "nvim-treesitter/nvim-treesitter",
use("preservim/nerdcommenter") {
use("m4xshen/autoclose.nvim") "neovim/nvim-lspconfig", -- Configurations for Nvim LSP
use("lukas-reineke/indent-blankline.nvim") init = function()
require("nvim-lsp-config")
-- themeing end,
use("EdenEast/nightfox.nvim") },
"simrat39/rust-tools.nvim",
-- thin bar indicating an arbitray character limit "preservim/nerdcommenter", -- (batch)commenting tool
use("lukas-reineke/virt-column.nvim") {
"m4xshen/autoclose.nvim",
-- fuzzy file finder opts = require("autoclose-config"),
use("nvim-telescope/telescope.nvim") },
"lukas-reineke/indent-blankline.nvim",
-- autocompletion engine, plugs into lsp {
use({ "EdenEast/nightfox.nvim", -- themeing
init = function()
vim.cmd("colorscheme carbonfox")
end,
opts = {
options = {
styles = {
comments = "italic",
keywords = "bold",
types = "italic,bold",
},
},
},
},
"lukas-reineke/virt-column.nvim", -- thin bar indicating an arbitray character limit
{
"nvim-telescope/telescope.nvim", -- fuzzy file finder
opts = {
pickers = {
find_files = {
-- `hidden = true` will still show the inside of `.git/` as it's not `.gitignore`d.
find_command = { "rg", "--files", "--hidden", "--no-ignore", "--glob", "!**/.git/*" },
},
},
},
init = function()
require("telescope-config")
end,
},
{
"hrsh7th/nvim-cmp", "hrsh7th/nvim-cmp",
requires = { dependencies = {
"hrsh7th/cmp-buffer", "hrsh7th/cmp-buffer",
"hrsh7th/cmp-nvim-lsp", "hrsh7th/cmp-nvim-lsp",
"hrsh7th/cmp-cmdline", "hrsh7th/cmp-cmdline",
"hrsh7th/cmp-path", "hrsh7th/cmp-path",
"hrsh7th/cmp-nvim-lua", "hrsh7th/cmp-nvim-lua",
}, },
}) init = function()
require("nvim-cmp-config")
--use 'dense-analysis/ale' end,
use("mhartington/formatter.nvim") },
{
use({ "mhartington/formatter.nvim",
config = function()
opts = require("formatter-config").build()
require("formatter").setup(opts)
end,
},
{
"sudormrfbin/cheatsheet.nvim", "sudormrfbin/cheatsheet.nvim",
dependencies = {
requires = { "nvim-telescope/telescope.nvim",
{ "nvim-telescope/telescope.nvim" }, "nvim-lua/popup.nvim",
{ "nvim-lua/popup.nvim" }, "nvim-lua/plenary.nvim",
{ "nvim-lua/plenary.nvim" }, },
}, },
}) })
vim.cmd([[ local augroup = vim.api.nvim_create_augroup
augroup packer_user_config local autocmd = vim.api.nvim_create_autocmd
autocmd! augroup("__formatter__", { clear = true })
autocmd BufWritePost plugins.lua source <afile> | PackerCompile autocmd("BufWritePost", {
augroup end group = "__formatter__",
]]) command = ":FormatWrite",
})
-- init configs
require("nightfox-config")
require("nvim-lsp-config")
require("nvim-tree-config")
require("nvim-cmp-config")
require("autoclose-config")
require("barbar-config")
--require("image-config")
require("telescope-config")
-- require('ale-config')
require("formatter-config")
require("lualine").setup()
require("virt-column").setup()
if packer_bootstrap then
require("packer").sync()
end
end)

View file

@ -1,12 +1,3 @@
require("telescope").setup({
pickers = {
find_files = {
-- `hidden = true` will still show the inside of `.git/` as it's not `.gitignore`d.
find_command = { "rg", "--files", "--hidden", "--no-ignore", "--glob", "!**/.git/*" },
},
},
})
local builtin = require("telescope.builtin") local builtin = require("telescope.builtin")
vim.keymap.set("n", "<leader>ff", builtin.find_files, {}) vim.keymap.set("n", "<leader>ff", builtin.find_files, {})