adding neovim config, splitting it up
This commit is contained in:
parent
817a08c7e2
commit
b2322f2877
17 changed files with 460 additions and 1 deletions
4
.config/nvim/lua/klowner/plugins/init.lua
Normal file
4
.config/nvim/lua/klowner/plugins/init.lua
Normal file
|
@ -0,0 +1,4 @@
|
|||
return {
|
||||
"nvim-lua/plenary.nvim", -- commonly used lua functions
|
||||
"christoomey/vim-tmux-navigator", -- tmux & split window navigation
|
||||
}
|
19
.config/nvim/lua/klowner/plugins/lazygit.lua
Normal file
19
.config/nvim/lua/klowner/plugins/lazygit.lua
Normal file
|
@ -0,0 +1,19 @@
|
|||
return {
|
||||
"kdheepak/lazygit.nvim",
|
||||
cmd = {
|
||||
"LazyGit",
|
||||
"LazyGitConfig",
|
||||
"LazyGitCurrentFile",
|
||||
"LazyGitFilter",
|
||||
"LazyGitFilterCurrentFile",
|
||||
},
|
||||
-- optional for floating window border decoration
|
||||
dependencies = {
|
||||
"nvim-lua/plenary.nvim",
|
||||
},
|
||||
-- setting the keybinding for LazyGit with 'keys' is recommended in
|
||||
-- order to load the plugin when the command is run for the first time
|
||||
keys = {
|
||||
{ "<leader>lg", "<cmd>LazyGit<cr>", desc = "Open lazy git" },
|
||||
},
|
||||
}
|
137
.config/nvim/lua/klowner/plugins/lsp/lspconfig.lua
Normal file
137
.config/nvim/lua/klowner/plugins/lsp/lspconfig.lua
Normal file
|
@ -0,0 +1,137 @@
|
|||
return {
|
||||
"neovim/nvim-lspconfig",
|
||||
event = { "BufReadPre", "BufNewFile" },
|
||||
dependencies = {
|
||||
"hrsh7th/cmp-nvim-lsp",
|
||||
{ "antosha417/nvim-lsp-file-operations", config = true },
|
||||
{ "folke/neodev.nvim", opts = {} },
|
||||
},
|
||||
config = function()
|
||||
-- import lspconfig plugin
|
||||
local lspconfig = require("lspconfig")
|
||||
|
||||
-- import mason_lspconfig plugin
|
||||
local mason_lspconfig = require("mason-lspconfig")
|
||||
|
||||
-- import cmp-nvim-lsp plugin
|
||||
local cmp_nvim_lsp = require("cmp_nvim_lsp")
|
||||
|
||||
local keymap = vim.keymap -- for conciseness
|
||||
|
||||
vim.api.nvim_create_autocmd("LspAttach", {
|
||||
group = vim.api.nvim_create_augroup("UserLspConfig", {}),
|
||||
callback = function(ev)
|
||||
-- Buffer local mappings.
|
||||
-- See `:help vim.lsp.*` for documentation on any of the below functions
|
||||
local opts = { buffer = ev.buf, silent = true }
|
||||
|
||||
-- set keybinds
|
||||
opts.desc = "Show LSP references"
|
||||
keymap.set("n", "gR", "<cmd>Telescope lsp_references<CR>", opts) -- show definition, references
|
||||
|
||||
opts.desc = "Go to declaration"
|
||||
keymap.set("n", "gD", vim.lsp.buf.declaration, opts) -- go to declaration
|
||||
|
||||
opts.desc = "Show LSP definitions"
|
||||
keymap.set("n", "gd", "<cmd>Telescope lsp_definitions<CR>", opts) -- show lsp definitions
|
||||
|
||||
opts.desc = "Show LSP implementations"
|
||||
keymap.set("n", "gi", "<cmd>Telescope lsp_implementations<CR>", opts) -- show lsp implementations
|
||||
|
||||
opts.desc = "Show LSP type definitions"
|
||||
keymap.set("n", "gt", "<cmd>Telescope lsp_type_definitions<CR>", opts) -- show lsp type definitions
|
||||
|
||||
opts.desc = "See available code actions"
|
||||
keymap.set({ "n", "v" }, "<leader>ca", vim.lsp.buf.code_action, opts) -- see available code actions, in visual mode will apply to selection
|
||||
|
||||
opts.desc = "Smart rename"
|
||||
keymap.set("n", "<leader>rn", vim.lsp.buf.rename, opts) -- smart rename
|
||||
|
||||
opts.desc = "Show buffer diagnostics"
|
||||
keymap.set("n", "<leader>D", "<cmd>Telescope diagnostics bufnr=0<CR>", opts) -- show diagnostics for file
|
||||
|
||||
opts.desc = "Show line diagnostics"
|
||||
keymap.set("n", "<leader>d", vim.diagnostic.open_float, opts) -- show diagnostics for line
|
||||
|
||||
opts.desc = "Go to previous diagnostic"
|
||||
keymap.set("n", "[d", vim.diagnostic.goto_prev, opts) -- jump to previous diagnostic in buffer
|
||||
|
||||
opts.desc = "Go to next diagnostic"
|
||||
keymap.set("n", "]d", vim.diagnostic.goto_next, opts) -- jump to next diagnostic in buffer
|
||||
|
||||
opts.desc = "Show documentation for what is under cursor"
|
||||
keymap.set("n", "K", vim.lsp.buf.hover, opts) -- show documentation for what is under cursor
|
||||
|
||||
opts.desc = "Restart LSP"
|
||||
keymap.set("n", "<leader>rs", ":LspRestart<CR>", opts) -- mapping to restart lsp if necessary
|
||||
end,
|
||||
})
|
||||
|
||||
-- used to enable autocompletion (assign to every lsp server config)
|
||||
local capabilities = cmp_nvim_lsp.default_capabilities()
|
||||
|
||||
-- Change the Diagnostic symbols in the sign column (gutter)
|
||||
-- (not in youtube nvim video)
|
||||
local signs = { Error = " ", Warn = " ", Hint = " ", Info = " " }
|
||||
for type, icon in pairs(signs) do
|
||||
local hl = "DiagnosticSign" .. type
|
||||
vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = "" })
|
||||
end
|
||||
|
||||
mason_lspconfig.setup_handlers({
|
||||
-- default handler for installed servers
|
||||
function(server_name)
|
||||
lspconfig[server_name].setup({
|
||||
capabilities = capabilities,
|
||||
})
|
||||
end,
|
||||
["svelte"] = function()
|
||||
-- configure svelte server
|
||||
lspconfig["svelte"].setup({
|
||||
capabilities = capabilities,
|
||||
on_attach = function(client, bufnr)
|
||||
vim.api.nvim_create_autocmd("BufWritePost", {
|
||||
pattern = { "*.js", "*.ts" },
|
||||
callback = function(ctx)
|
||||
-- Here use ctx.match instead of ctx.file
|
||||
client.notify("$/onDidChangeTsOrJsFile", { uri = ctx.match })
|
||||
end,
|
||||
})
|
||||
end,
|
||||
})
|
||||
end,
|
||||
["graphql"] = function()
|
||||
-- configure graphql language server
|
||||
lspconfig["graphql"].setup({
|
||||
capabilities = capabilities,
|
||||
filetypes = { "graphql", "gql", "svelte", "typescriptreact", "javascriptreact" },
|
||||
})
|
||||
end,
|
||||
["emmet_ls"] = function()
|
||||
-- configure emmet language server
|
||||
lspconfig["emmet_ls"].setup({
|
||||
capabilities = capabilities,
|
||||
filetypes = { "html", "typescriptreact", "javascriptreact", "css", "sass", "scss", "less", "svelte" },
|
||||
})
|
||||
end,
|
||||
["lua_ls"] = function()
|
||||
-- configure lua server (with special settings)
|
||||
lspconfig["lua_ls"].setup({
|
||||
capabilities = capabilities,
|
||||
settings = {
|
||||
Lua = {
|
||||
-- make the language server recognize "vim" global
|
||||
diagnostics = {
|
||||
globals = { "vim" },
|
||||
},
|
||||
completion = {
|
||||
callSnippet = "Replace",
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
end,
|
||||
})
|
||||
end,
|
||||
}
|
||||
|
54
.config/nvim/lua/klowner/plugins/lsp/mason.lua
Normal file
54
.config/nvim/lua/klowner/plugins/lsp/mason.lua
Normal file
|
@ -0,0 +1,54 @@
|
|||
return {
|
||||
"williamboman/mason.nvim",
|
||||
dependencies = {
|
||||
"williamboman/mason-lspconfig.nvim",
|
||||
"WhoIsSethDaniel/mason-tool-installer.nvim",
|
||||
},
|
||||
config = function()
|
||||
-- import mason
|
||||
local mason = require("mason")
|
||||
|
||||
-- import mason-lspconfig
|
||||
local mason_lspconfig = require("mason-lspconfig")
|
||||
|
||||
local mason_tool_installer = require("mason-tool-installer")
|
||||
|
||||
-- enable mason and configure icons
|
||||
mason.setup({
|
||||
ui = {
|
||||
icons = {
|
||||
package_installed = "✓",
|
||||
package_pending = "➜",
|
||||
package_uninstalled = "✗",
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
mason_lspconfig.setup({
|
||||
-- list of servers for mason to install
|
||||
ensure_installed = {
|
||||
"tsserver",
|
||||
"html",
|
||||
"cssls",
|
||||
"tailwindcss",
|
||||
"svelte",
|
||||
"lua_ls",
|
||||
"graphql",
|
||||
"emmet_ls",
|
||||
"prismals",
|
||||
"pyright",
|
||||
},
|
||||
})
|
||||
|
||||
mason_tool_installer.setup({
|
||||
ensure_installed = {
|
||||
"prettier", -- prettier formatter
|
||||
"stylua", -- lua formatter
|
||||
"isort", -- python formatter
|
||||
"black", -- python formatter
|
||||
"pylint",
|
||||
"eslint_d",
|
||||
},
|
||||
})
|
||||
end,
|
||||
}
|
63
.config/nvim/lua/klowner/plugins/nvim-cmp.lua
Normal file
63
.config/nvim/lua/klowner/plugins/nvim-cmp.lua
Normal file
|
@ -0,0 +1,63 @@
|
|||
return {
|
||||
"hrsh7th/nvim-cmp",
|
||||
event = "InsertEnter",
|
||||
dependencies = {
|
||||
"hrsh7th/cmp-buffer", -- source for text in buffer
|
||||
"hrsh7th/cmp-path", -- source for file system paths
|
||||
{
|
||||
"L3MON4D3/LuaSnip",
|
||||
-- follow latest release.
|
||||
version = "v2.*", -- Replace <CurrentMajor> by the latest released major (first number of latest release)
|
||||
-- install jsregexp (optional!).
|
||||
build = "make install_jsregexp",
|
||||
},
|
||||
"saadparwaiz1/cmp_luasnip", -- for autocompletion
|
||||
"rafamadriz/friendly-snippets", -- useful snippets
|
||||
"onsails/lspkind.nvim", -- vs-code like pictograms
|
||||
},
|
||||
config = function()
|
||||
local cmp = require("cmp")
|
||||
|
||||
local luasnip = require("luasnip")
|
||||
|
||||
local lspkind = require("lspkind")
|
||||
|
||||
-- loads vscode style snippets from installed plugins (e.g. friendly-snippets)
|
||||
require("luasnip.loaders.from_vscode").lazy_load()
|
||||
|
||||
cmp.setup({
|
||||
completion = {
|
||||
completeopt = "menu,menuone,preview,noselect",
|
||||
},
|
||||
snippet = { -- configure how nvim-cmp interacts with snippet engine
|
||||
expand = function(args)
|
||||
luasnip.lsp_expand(args.body)
|
||||
end,
|
||||
},
|
||||
mapping = cmp.mapping.preset.insert({
|
||||
["<C-k>"] = cmp.mapping.select_prev_item(), -- previous suggestion
|
||||
["<C-j>"] = cmp.mapping.select_next_item(), -- next suggestion
|
||||
["<C-b>"] = cmp.mapping.scroll_docs(-4),
|
||||
["<C-f>"] = cmp.mapping.scroll_docs(4),
|
||||
["<C-Space>"] = cmp.mapping.complete(), -- show completion suggestions
|
||||
["<C-e>"] = cmp.mapping.abort(), -- close completion window
|
||||
["<CR>"] = cmp.mapping.confirm({ select = false }),
|
||||
}),
|
||||
-- sources for autocompletion
|
||||
sources = cmp.config.sources({
|
||||
{ name = "nvim_lsp"},
|
||||
{ name = "luasnip" }, -- snippets
|
||||
{ name = "buffer" }, -- text within current buffer
|
||||
{ name = "path" }, -- file system paths
|
||||
}),
|
||||
|
||||
-- configure lspkind for vs-code like pictograms in completion menu
|
||||
formatting = {
|
||||
format = lspkind.cmp_format({
|
||||
maxwidth = 50,
|
||||
ellipsis_char = "...",
|
||||
}),
|
||||
},
|
||||
})
|
||||
end,
|
||||
}
|
6
.config/nvim/lua/klowner/plugins/tagbar.lua
Normal file
6
.config/nvim/lua/klowner/plugins/tagbar.lua
Normal file
|
@ -0,0 +1,6 @@
|
|||
return {
|
||||
"preservim/tagbar",
|
||||
keys = {
|
||||
{ '\t', "<cmd>TagbarToggle<CR>", desc = "Toggle tagbar"},
|
||||
},
|
||||
}
|
49
.config/nvim/lua/klowner/plugins/telescope.lua
Normal file
49
.config/nvim/lua/klowner/plugins/telescope.lua
Normal file
|
@ -0,0 +1,49 @@
|
|||
return {
|
||||
"nvim-telescope/telescope.nvim",
|
||||
branch = "0.1.x",
|
||||
dependencies = {
|
||||
"nvim-lua/plenary.nvim",
|
||||
{ "nvim-telescope/telescope-fzf-native.nvim", build = "make" },
|
||||
"nvim-tree/nvim-web-devicons",
|
||||
"folke/todo-comments.nvim",
|
||||
},
|
||||
config = function()
|
||||
local telescope = require("telescope")
|
||||
local actions = require("telescope.actions")
|
||||
local transform_mod = require("telescope.actions.mt").transform_mod
|
||||
|
||||
local trouble = require("trouble")
|
||||
|
||||
-- or create your custom action
|
||||
local custom_actions = transform_mod({
|
||||
open_trouble_qflist = function(prompt_bufnr)
|
||||
trouble.toggle("quickfix")
|
||||
end,
|
||||
})
|
||||
|
||||
telescope.setup({
|
||||
defaults = {
|
||||
path_display = { "smart" },
|
||||
mappings = {
|
||||
i = {
|
||||
["<C-k>"] = actions.move_selection_previous, -- move to prev result
|
||||
["<C-j>"] = actions.move_selection_next, -- move to next result
|
||||
["<C-q>"] = actions.send_selected_to_qflist + custom_actions.open_trouble_qflist,
|
||||
["<C-t>"] = require("trouble.sources.telescope").open,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
telescope.load_extension("fzf")
|
||||
|
||||
-- set keymaps
|
||||
local keymap = vim.keymap -- for conciseness
|
||||
|
||||
keymap.set("n", "<leader>ff", "<cmd>Telescope find_files<cr>", { desc = "Fuzzy find files in cwd" })
|
||||
keymap.set("n", "<leader>fr", "<cmd>Telescope oldfiles<cr>", { desc = "Fuzzy find recent files" })
|
||||
keymap.set("n", "<leader>fs", "<cmd>Telescope live_grep<cr>", { desc = "Find string in cwd" })
|
||||
keymap.set("n", "<leader>fc", "<cmd>Telescope grep_string<cr>", { desc = "Find string under cursor in cwd" })
|
||||
keymap.set("n", "<leader>ft", "<cmd>TodoTelescope<cr>", { desc = "Find todos" })
|
||||
end,
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
return {
|
||||
'tpope/vim-commentary',
|
||||
keys = {
|
||||
{ '<leader>c', '<Plug>Commentary', mode = {'n','o','x'}, desc = "Toggle commented"},
|
||||
{ '<leader>cc', '<Plug>CommentaryLine', mode = 'n', desc = "Toggle commented"},
|
||||
},
|
||||
}
|
8
.config/nvim/lua/klowner/plugins/tpope-vim-fugitive.lua
Normal file
8
.config/nvim/lua/klowner/plugins/tpope-vim-fugitive.lua
Normal file
|
@ -0,0 +1,8 @@
|
|||
return {
|
||||
"tpope/vim-fugitive",
|
||||
keys = {
|
||||
{ "<Bslash>b", "<CMD>Git blame<CR>", desc = "Show git blame" },
|
||||
{ "<Bslash>l", "<CMD>Git log<CR>", desc = "Show git log" },
|
||||
{ "<Bslash>gs", "<CMD>Git status<CR>", desc = "Show git status"},
|
||||
},
|
||||
}
|
12
.config/nvim/lua/klowner/plugins/trouble.lua
Normal file
12
.config/nvim/lua/klowner/plugins/trouble.lua
Normal file
|
@ -0,0 +1,12 @@
|
|||
return {
|
||||
"folke/trouble.nvim",
|
||||
dependencies = { "nvim-tree/nvim-web-devicons", "folke/todo-comments.nvim" },
|
||||
keys = {
|
||||
{ "<leader>xx", "<cmd>TroubleToggle<CR>", desc = "Open/close trouble list" },
|
||||
{ "<leader>xw", "<cmd>TroubleToggle workspace_diagnostics<CR>", desc = "Open trouble workspace diagnostics" },
|
||||
{ "<leader>xd", "<cmd>TroubleToggle document_diagnostics<CR>", desc = "Open trouble document diagnostics" },
|
||||
{ "<leader>xq", "<cmd>TroubleToggle quickfix<CR>", desc = "Open trouble quickfix list" },
|
||||
{ "<leader>xl", "<cmd>TroubleToggle loclist<CR>", desc = "Open trouble location list" },
|
||||
{ "<leader>xt", "<cmd>TodoTrouble<CR>", desc = "Open todos in trouble" },
|
||||
},
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue