updated neovim configuration
added telescop and fuzzy finding along with lsp and git integration
This commit is contained in:
@@ -39,3 +39,10 @@ require('p-tree')
|
|||||||
require('colorscheme')
|
require('colorscheme')
|
||||||
require('keymaps')
|
require('keymaps')
|
||||||
require('bar')
|
require('bar')
|
||||||
|
require('teleop')
|
||||||
|
require('nvimcmp')
|
||||||
|
require('gitsign')
|
||||||
|
require('lsp.mason')
|
||||||
|
require('lsp.lspsaga')
|
||||||
|
require('lsp.lspconfig')
|
||||||
|
require('lsp.null-ls')
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
local setup, gitsigns = pcall(require, "gitsigns")
|
||||||
|
if not setup then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
gitsigns.setup()
|
||||||
@@ -12,3 +12,20 @@ keymap.set("n","<leader>sv","<C-w>v") -- split window vertically
|
|||||||
keymap.set("n","<leader>sh","<C-w>s") -- split window horizontally
|
keymap.set("n","<leader>sh","<C-w>s") -- split window horizontally
|
||||||
keymap.set("n","<leader>se","<C-w>=") -- make split windows equal width
|
keymap.set("n","<leader>se","<C-w>=") -- make split windows equal width
|
||||||
keymap.set("n","<leader>sx",":close<CR>") -- close current split window
|
keymap.set("n","<leader>sx",":close<CR>") -- close current split window
|
||||||
|
|
||||||
|
-- nvim-tree
|
||||||
|
keymap.set("n", "<leader>e", ":NvimTreeToggle<CR>") -- toggle file explorer
|
||||||
|
|
||||||
|
-- telescope
|
||||||
|
keymap.set("n","<leader>ff", "<cmd>Telescope find_files<cr>")
|
||||||
|
keymap.set("n","<leader>fs", "<cmd>Telescope live_grep<cr>")
|
||||||
|
keymap.set("n","<leader>fc", "<cmd>Telescope grep_string<cr>")
|
||||||
|
keymap.set("n","<leader>fb", "<cmd>Telescope buffers<cr>")
|
||||||
|
keymap.set("n","<leader>fh", "<cmd>Telescope help_tags<cr>")
|
||||||
|
keymap.set("n", "<leader>gc", "<cmd>Telescope git_commits<cr>")
|
||||||
|
keymap.set("n", "<leader>gfc", "<cmd>Telescope git_bcommits<cr>")
|
||||||
|
keymap.set("n", "<leader>gb", "<cmd>Telescope git_branches<cr>")
|
||||||
|
keymap.set("n", "<leader>gs", "<cmd>Telescope git_status<cr>")
|
||||||
|
|
||||||
|
-- restart lsp server
|
||||||
|
keymap.set("n", "<leader>rs", ":LspRestart<CR>") -- mapping to restart lsp if necessary
|
||||||
|
|||||||
@@ -0,0 +1,111 @@
|
|||||||
|
-- import lspconfig plugin safely
|
||||||
|
local lspconfig_status, lspconfig = pcall(require, "lspconfig")
|
||||||
|
if not lspconfig_status then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
-- import cmp-nvim-lsp plugin safely
|
||||||
|
local cmp_nvim_lsp_status, cmp_nvim_lsp = pcall(require, "cmp_nvim_lsp")
|
||||||
|
if not cmp_nvim_lsp_status then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
-- import typescript plugin safely
|
||||||
|
local typescript_setup, typescript = pcall(require, "typescript")
|
||||||
|
if not typescript_setup then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local keymap = vim.keymap -- for conciseness
|
||||||
|
|
||||||
|
-- enable keybinds only for when lsp server available
|
||||||
|
local on_attach = function(client, bufnr)
|
||||||
|
-- keybind options
|
||||||
|
local opts = { noremap = true, silent = true, buffer = bufnr }
|
||||||
|
|
||||||
|
-- set keybinds
|
||||||
|
keymap.set("n", "gf", "<cmd>Lspsaga lsp_finder<CR>", opts) -- show definition, references
|
||||||
|
keymap.set("n", "gD", "<Cmd>lua vim.lsp.buf.declaration()<CR>", opts) -- got to declaration
|
||||||
|
keymap.set("n", "gd", "<cmd>Lspsaga peek_definition<CR>", opts) -- see definition and make edits in window
|
||||||
|
keymap.set("n", "gi", "<cmd>lua vim.lsp.buf.implementation()<CR>", opts) -- go to implementation
|
||||||
|
keymap.set("n", "<leader>ca", "<cmd>Lspsaga code_action<CR>", opts) -- see available code actions
|
||||||
|
keymap.set("n", "<leader>rn", "<cmd>Lspsaga rename<CR>", opts) -- smart rename
|
||||||
|
keymap.set("n", "<leader>D", "<cmd>Lspsaga show_line_diagnostics<CR>", opts) -- show diagnostics for line
|
||||||
|
keymap.set("n", "<leader>d", "<cmd>Lspsaga show_cursor_diagnostics<CR>", opts) -- show diagnostics for cursor
|
||||||
|
keymap.set("n", "[d", "<cmd>Lspsaga diagnostic_jump_prev<CR>", opts) -- jump to previous diagnostic in buffer
|
||||||
|
keymap.set("n", "]d", "<cmd>Lspsaga diagnostic_jump_next<CR>", opts) -- jump to next diagnostic in buffer
|
||||||
|
keymap.set("n", "K", "<cmd>Lspsaga hover_doc<CR>", opts) -- show documentation for what is under cursor
|
||||||
|
keymap.set("n", "<leader>o", "<cmd>LSoutlineToggle<CR>", opts) -- see outline on right hand side
|
||||||
|
|
||||||
|
-- typescript specific keymaps (e.g. rename file and update imports)
|
||||||
|
if client.name == "tsserver" then
|
||||||
|
keymap.set("n", "<leader>rf", ":TypescriptRenameFile<CR>") -- rename file and update imports
|
||||||
|
keymap.set("n", "<leader>oi", ":TypescriptOrganizeImports<CR>") -- organize imports (not in youtube nvim video)
|
||||||
|
keymap.set("n", "<leader>ru", ":TypescriptRemoveUnused<CR>") -- remove unused variables (not in youtube nvim video)
|
||||||
|
end
|
||||||
|
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
|
||||||
|
|
||||||
|
-- configure html server
|
||||||
|
lspconfig["html"].setup({
|
||||||
|
capabilities = capabilities,
|
||||||
|
on_attach = on_attach,
|
||||||
|
})
|
||||||
|
|
||||||
|
-- configure typescript server with plugin
|
||||||
|
typescript.setup({
|
||||||
|
server = {
|
||||||
|
capabilities = capabilities,
|
||||||
|
on_attach = on_attach,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
-- configure css server
|
||||||
|
lspconfig["cssls"].setup({
|
||||||
|
capabilities = capabilities,
|
||||||
|
on_attach = on_attach,
|
||||||
|
})
|
||||||
|
|
||||||
|
-- configure tailwindcss server
|
||||||
|
lspconfig["tailwindcss"].setup({
|
||||||
|
capabilities = capabilities,
|
||||||
|
on_attach = on_attach,
|
||||||
|
})
|
||||||
|
|
||||||
|
-- configure emmet language server
|
||||||
|
lspconfig["emmet_ls"].setup({
|
||||||
|
capabilities = capabilities,
|
||||||
|
on_attach = on_attach,
|
||||||
|
filetypes = { "html", "typescriptreact", "javascriptreact", "css", "sass", "scss", "less", "svelte" },
|
||||||
|
})
|
||||||
|
|
||||||
|
-- configure lua server (with special settings)
|
||||||
|
lspconfig["sumneko_lua"].setup({
|
||||||
|
capabilities = capabilities,
|
||||||
|
on_attach = on_attach,
|
||||||
|
settings = { -- custom settings for lua
|
||||||
|
Lua = {
|
||||||
|
-- make the language server recognize "vim" global
|
||||||
|
diagnostics = {
|
||||||
|
globals = { "vim" },
|
||||||
|
},
|
||||||
|
workspace = {
|
||||||
|
-- make language server aware of runtime files
|
||||||
|
library = {
|
||||||
|
[vim.fn.expand("$VIMRUNTIME/lua")] = true,
|
||||||
|
[vim.fn.stdpath("config") .. "/lua"] = true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
local saga_status, saga = pcall(require, "lspsaga")
|
||||||
|
if not saga_status then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
saga.setup({
|
||||||
|
scroll_preview = {
|
||||||
|
scroll_down = "<C-f>",
|
||||||
|
scroll_up = "<C-b>"
|
||||||
|
},
|
||||||
|
definition = {
|
||||||
|
edit = "<CR>"
|
||||||
|
},
|
||||||
|
ui = {
|
||||||
|
colors = {
|
||||||
|
normal_bg = "#022746",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
require("mason").setup({
|
||||||
|
ui = {
|
||||||
|
icons = {
|
||||||
|
package_installed = "✓",
|
||||||
|
package_pending = "➜",
|
||||||
|
package_uninstalled = "✗",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
require("mason-lspconfig").setup({
|
||||||
|
ensure_installed = {
|
||||||
|
"sumneko_lua",
|
||||||
|
"clangd",
|
||||||
|
"rust_analyzer",
|
||||||
|
"vls",
|
||||||
|
},
|
||||||
|
automatic_installation = true,
|
||||||
|
})
|
||||||
|
|
||||||
|
require("mason-null-ls").setup({
|
||||||
|
ensure_installed = {
|
||||||
|
"prettier",
|
||||||
|
"stylua",
|
||||||
|
"eslint_d",
|
||||||
|
},
|
||||||
|
automatic_installation = true,
|
||||||
|
})
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
local setup, null_ls = pcall(require, "null-ls")
|
||||||
|
if not setup then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local formatting = null_ls.builtins.formatting
|
||||||
|
local diagnostics = null_ls.builtins.diagnostics
|
||||||
|
|
||||||
|
local augroup = vim.api.nvim_create_augroup("LspFormatting", {})
|
||||||
|
|
||||||
|
null_ls.setup({
|
||||||
|
sources = {
|
||||||
|
formatting.prettier,
|
||||||
|
formatting.stylua,
|
||||||
|
formatting.eslint_d.with({
|
||||||
|
condition = function(utils)
|
||||||
|
return utils.root_has_file('.eslintrc.js')
|
||||||
|
end,
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
on_attach = function(current_client, bufnr)
|
||||||
|
if current_client.supports_method("textDocument/formatting") then
|
||||||
|
vim.api.nvim_clear_autocmds({
|
||||||
|
group = augroup,
|
||||||
|
buffer = bufnr
|
||||||
|
})
|
||||||
|
vim.api.nvim_create_autocmd("BufWritePre", {
|
||||||
|
group = augroup,
|
||||||
|
buffer = bufnr,
|
||||||
|
callback = function()
|
||||||
|
vim.lsp.buf.format({
|
||||||
|
filter = function(client)
|
||||||
|
return client.name == "null-ls"
|
||||||
|
end,
|
||||||
|
bufnr = bufnr,
|
||||||
|
})
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
})
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
local cmp_status, cmp = pcall(require, "cmp")
|
||||||
|
if not cmp_status then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local luasnip_status, luasnip = pcall(require, "luasnip")
|
||||||
|
if not luasnip_status then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
-- load friendly-snippets
|
||||||
|
require("luasnip/loaders/from_vscode").lazy_load()
|
||||||
|
|
||||||
|
vim.opt.completeopt = "menu,menuone,noselect"
|
||||||
|
|
||||||
|
cmp.setup({
|
||||||
|
snippet = {
|
||||||
|
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 = cmp.config.sources({
|
||||||
|
{ name = "luasnip" },
|
||||||
|
{ name = "buffer" },
|
||||||
|
{ name = "path" },
|
||||||
|
}),
|
||||||
|
})
|
||||||
@@ -36,5 +36,3 @@ require("nvim-tree").setup({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
vim.keymap.set('n','<c-e>','<cmd>NvimTreeToggle<cr>')
|
|
||||||
|
|||||||
@@ -2,12 +2,41 @@ vim.cmd [[packadd packer.nvim]]
|
|||||||
|
|
||||||
return require('packer').startup(function(use)
|
return require('packer').startup(function(use)
|
||||||
use 'wbthomason/packer.nvim'
|
use 'wbthomason/packer.nvim'
|
||||||
use 'folke/tokyonight.nvim'
|
|
||||||
|
-- better bar
|
||||||
use 'nvim-lualine/lualine.nvim'
|
use 'nvim-lualine/lualine.nvim'
|
||||||
|
|
||||||
|
-- autocpompletion
|
||||||
|
use 'hrsh7th/nvim-cmp'
|
||||||
|
use 'hrsh7th/cmp-buffer'
|
||||||
|
use 'hrsh7th/cmp-path'
|
||||||
|
|
||||||
|
-- snippets
|
||||||
|
use 'L3MON4D3/LuaSnip'
|
||||||
|
use 'saadparwaiz1/cmp_luasnip'
|
||||||
|
use 'rafamadriz/friendly-snippets'
|
||||||
|
|
||||||
|
-- fuzzy finding
|
||||||
|
use {
|
||||||
|
'nvim-telescope/telescope.nvim',
|
||||||
|
tag = '0.1.1',
|
||||||
|
requires = {
|
||||||
|
'nvim-lua/plenary.nvim',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
use {
|
||||||
|
'nvim-telescope/telescope-fzf-native.nvim',
|
||||||
|
run = 'make'
|
||||||
|
}
|
||||||
|
|
||||||
|
-- colorschemes
|
||||||
|
use 'folke/tokyonight.nvim'
|
||||||
use {
|
use {
|
||||||
'catppuccin/nvim',
|
'catppuccin/nvim',
|
||||||
as = 'catppuccin'
|
as = 'catppuccin'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
-- neovim explorer
|
||||||
use {
|
use {
|
||||||
'nvim-tree/nvim-tree.lua',
|
'nvim-tree/nvim-tree.lua',
|
||||||
requires = {
|
requires = {
|
||||||
@@ -15,4 +44,20 @@ return require('packer').startup(function(use)
|
|||||||
},
|
},
|
||||||
tag = 'nightly'
|
tag = 'nightly'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
-- managing & installing lsp servers
|
||||||
|
use 'williamboman/mason.nvim'
|
||||||
|
use 'williamboman/mason-lspconfig.nvim'
|
||||||
|
-- configuring lsp servers
|
||||||
|
use 'neovim/nvim-lspconfig'
|
||||||
|
use 'hrsh7th/cmp-nvim-lsp'
|
||||||
|
use 'onsails/lspkind.nvim'
|
||||||
|
use { 'glepnir/lspsaga.nvim', branch = main}
|
||||||
|
|
||||||
|
-- formatting & linting
|
||||||
|
use 'jose-elias-alvarez/null-ls.nvim' -- configure formatters & linters
|
||||||
|
use 'jayp0521/mason-null-ls.nvim' -- bridges gap b/w mason & null-ls
|
||||||
|
|
||||||
|
-- git integration
|
||||||
|
use 'lewis6991/gitsigns.nvim'
|
||||||
end)
|
end)
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
local telescope_setup, telescope = pcall(require, "telescope")
|
||||||
|
if not telescope_setup then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local actions_setup, actions = pcall(require, "telescope.actions")
|
||||||
|
if not actions_setup then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
telescope.setup({
|
||||||
|
defaults = {
|
||||||
|
mappings = {
|
||||||
|
i = {
|
||||||
|
["<C-k>"] = actions.move_selection_previous,
|
||||||
|
["<C-j>"] = actions.move_selection_next,
|
||||||
|
["<C-q>"] = actions.send_selected_to_qflist + actions.open_qflist,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
telescope.load_extension("fzf")
|
||||||
Reference in New Issue
Block a user