more plugins and their mappings
parent
04543adb05
commit
a097dab167
196
neovim/init.lua
196
neovim/init.lua
|
@ -19,17 +19,17 @@ vim.opt.backup = false
|
||||||
vim.opt.undodir = os.getenv("HOME") .. "/.vim/undodir"
|
vim.opt.undodir = os.getenv("HOME") .. "/.vim/undodir"
|
||||||
vim.opt.undofile = true
|
vim.opt.undofile = true
|
||||||
vim.opt.completeopt = 'menuone,noselect'
|
vim.opt.completeopt = 'menuone,noselect'
|
||||||
|
|
||||||
vim.g.mapleader = ' '
|
vim.g.mapleader = ' '
|
||||||
|
|
||||||
-- basic keymaps
|
-- basic keymaps
|
||||||
vim.keymap.set({'n','v'}, '<Space>', '<Nop>', {silent=true}) -- since we're using space for leader
|
vim.keymap.set({ 'n', 'v' }, '<Space>', '<Nop>', { silent = true }) -- since we're using space for leader
|
||||||
|
vim.keymap.set('t', '<Esc>', '<C-\\><C-n>)') -- make :terminal escape out
|
||||||
|
|
||||||
-- diagnostics (errors/warnings to be shown)
|
-- diagnostics (errors/warnings to be shown)
|
||||||
vim.keymap.set('n', '[d', vim.diagnostic.goto_prev)
|
vim.keymap.set('n', '[d', vim.diagnostic.goto_prev)
|
||||||
vim.keymap.set('n', ']d', vim.diagnostic.goto_next)
|
vim.keymap.set('n', ']d', vim.diagnostic.goto_next)
|
||||||
vim.keymap.set('n', '<leader>e', vim.diagnostic.open_float) -- opens diag in box (floating)
|
vim.keymap.set('n', '<leader>e', vim.diagnostic.open_float) -- opens diag in box (floating)
|
||||||
vim.keymap.set('n', '<leader>q', vim.diagnostic.setloclist)
|
vim.keymap.set('n', '<leader>q', vim.diagnostic.setloclist) -- opens list of diags
|
||||||
|
|
||||||
|
|
||||||
-- vim-plug
|
-- vim-plug
|
||||||
|
@ -49,7 +49,7 @@ Plug('nvim-lua/plenary.nvim')
|
||||||
-- plugins
|
-- plugins
|
||||||
Plug('nvim-treesitter/nvim-treesitter') -- language parser engine
|
Plug('nvim-treesitter/nvim-treesitter') -- language parser engine
|
||||||
Plug('nvim-treesitter/nvim-treesitter-textobjects') -- more text objects
|
Plug('nvim-treesitter/nvim-treesitter-textobjects') -- more text objects
|
||||||
Plug('nvim-telescope/telescope.nvim', {tag = '0.1.0'}) -- fuzzy search thru files
|
Plug('nvim-telescope/telescope.nvim', { tag = '0.1.0' }) -- file browser
|
||||||
-- cmp: auto-complete/suggestions
|
-- cmp: auto-complete/suggestions
|
||||||
Plug('neovim/nvim-lspconfig') -- built-in LSP configurations
|
Plug('neovim/nvim-lspconfig') -- built-in LSP configurations
|
||||||
Plug('hrsh7th/cmp-nvim-lsp')
|
Plug('hrsh7th/cmp-nvim-lsp')
|
||||||
|
@ -57,9 +57,11 @@ Plug('hrsh7th/cmp-buffer')
|
||||||
Plug('hrsh7th/nvim-cmp')
|
Plug('hrsh7th/nvim-cmp')
|
||||||
Plug('onsails/lspkind-nvim')
|
Plug('onsails/lspkind-nvim')
|
||||||
-- DevExp
|
-- DevExp
|
||||||
Plug('numToStr/Comment.nvim') -- "gc" to comment visual regions/lines
|
Plug('numToStr/Comment.nvim') -- "gc" to comment visual regions/lines
|
||||||
Plug('lewis6991/gitsigns.nvim') -- add git info to sign columns
|
Plug('lewis6991/gitsigns.nvim') -- add git info to sign columns
|
||||||
Plug('tpope/vim-fugitive') -- git commands in nvim
|
Plug('tpope/vim-fugitive') -- git commands in nvim
|
||||||
|
Plug('williamboman/mason.nvim') -- LSP, debuggers,... package manager
|
||||||
|
Plug('williamboman/mason-lspconfig.nvim') -- lsp config for mason
|
||||||
|
|
||||||
-- UI & colorscheme
|
-- UI & colorscheme
|
||||||
Plug('gruvbox-community/gruvbox')
|
Plug('gruvbox-community/gruvbox')
|
||||||
|
@ -67,7 +69,9 @@ Plug('nvim-lualine/lualine.nvim') -- fancy status line
|
||||||
Plug('lukas-reineke/indent-blankline.nvim') -- identation lines on blank lines
|
Plug('lukas-reineke/indent-blankline.nvim') -- identation lines on blank lines
|
||||||
|
|
||||||
-- other
|
-- other
|
||||||
Plug('nvim-treesitter/nvim-treesitter', {run = ':TSUpdate'})
|
Plug('nvim-treesitter/nvim-treesitter', { run = ':TSUpdate' })
|
||||||
|
Plug('saadparwaiz1/cmp_luasnip') -- snippet engine
|
||||||
|
Plug('L3MON4D3/LuaSnip') -- snippet engine
|
||||||
|
|
||||||
---------
|
---------
|
||||||
vim.call('plug#end')
|
vim.call('plug#end')
|
||||||
|
@ -76,10 +80,11 @@ vim.call('plug#end')
|
||||||
vim.cmd.colorscheme('gruvbox')
|
vim.cmd.colorscheme('gruvbox')
|
||||||
|
|
||||||
-- plugin keymaps
|
-- plugin keymaps
|
||||||
function remap(mode, key_cmd, binded_fn, opts)
|
local function remap(mode, key_cmd, binded_fn, opts)
|
||||||
opts = opts or {remap = true}
|
opts = opts or { remap = true }
|
||||||
return vim.keymap.set(mode, key_cmd, binded_fn, opts)
|
return vim.keymap.set(mode, key_cmd, binded_fn, opts)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Comment.nvim
|
-- Comment.nvim
|
||||||
require('Comment').setup()
|
require('Comment').setup()
|
||||||
-- lukas-reineke/indent-blankline.nvim
|
-- lukas-reineke/indent-blankline.nvim
|
||||||
|
@ -99,27 +104,27 @@ require('telescope').setup {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pcall(require('telescope').load_extension, 'fzf')
|
pcall(require('telescope').load_extension, 'fzf')
|
||||||
remap('n', '<C-p>','<cmd>Telescope<cr>', {desc = 'Open Telescope general search'})
|
remap('n', '<C-p>', '<cmd>Telescope<cr>', { desc = 'Open Telescope general search' })
|
||||||
remap('n', '<leader>ff',function()
|
remap('n', '<leader>ff', function()
|
||||||
require('telescope.builtin').find_files()
|
require('telescope.builtin').find_files()
|
||||||
end, {desc = '[F]ind [F]iles'})
|
end, { desc = '[F]ind [F]iles' })
|
||||||
remap('n', '<leader>fg',function()
|
remap('n', '<leader>fg', function()
|
||||||
require('telescope.builtin').live_grep()
|
require('telescope.builtin').live_grep()
|
||||||
end, {desc = '[F]ind by [G]rep'})
|
end, { desc = '[F]ind by [G]rep' })
|
||||||
remap('n', '<leader>fb',function()
|
remap('n', '<leader>fb', function()
|
||||||
require('telescope.builtin').buffers()
|
require('telescope.builtin').buffers()
|
||||||
end, {desc = '[F]ind existing [B]uffers'})
|
end, { desc = '[F]ind existing [B]uffers' })
|
||||||
remap('n', '<leader>fh',function()
|
remap('n', '<leader>fh', function()
|
||||||
require('telescope.builtin').help_tags()
|
require('telescope.builtin').help_tags()
|
||||||
end, {desc = '[F]ind [H]elp'})
|
end, { desc = '[F]ind [H]elp' })
|
||||||
remap('n', '<leader>fd',function()
|
remap('n', '<leader>fd', function()
|
||||||
require('telescope.builtin').live_grep()
|
require('telescope.builtin').live_grep()
|
||||||
end, {desc = '[F]ind [D]iagnostics'})
|
end, { desc = '[F]ind [D]iagnostics' })
|
||||||
-- treesitter
|
-- treesitter
|
||||||
require('nvim-treesitter.configs').setup {
|
require('nvim-treesitter.configs').setup {
|
||||||
ensure_installed = {'lua', 'typescript', 'rust', 'go', 'python'},
|
ensure_installed = { 'lua', 'typescript', 'rust', 'go', 'python' },
|
||||||
highlight = {enable = true},
|
highlight = { enable = true },
|
||||||
indent = {enable = true},
|
indent = { enable = true },
|
||||||
incremental_selection = {
|
incremental_selection = {
|
||||||
enable = true,
|
enable = true,
|
||||||
keymap = {
|
keymap = {
|
||||||
|
@ -143,5 +148,152 @@ require('nvim-treesitter.configs').setup {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
-- LSP settings
|
||||||
|
-- This function gets run when an LSP connects to a particular buffer.
|
||||||
|
local on_attach = function(_, bufnr)
|
||||||
|
-- NOTE: Remember that lua is a real programming language, and as such it is possible
|
||||||
|
-- to define small helper and utility functions so you don't have to repeat yourself
|
||||||
|
-- many times.
|
||||||
|
--
|
||||||
|
-- In this case, we create a function that lets us more easily define mappings specific
|
||||||
|
-- for LSP related items. It sets the mode, buffer and description for us each time.
|
||||||
|
local nmap = function(keys, func, desc)
|
||||||
|
if desc then
|
||||||
|
desc = 'LSP: ' .. desc
|
||||||
|
end
|
||||||
|
|
||||||
|
vim.keymap.set('n', keys, func, { buffer = bufnr, desc = desc })
|
||||||
|
end
|
||||||
|
|
||||||
|
nmap('<leader>rn', vim.lsp.buf.rename, '[R]e[n]ame')
|
||||||
|
nmap('<leader>ca', vim.lsp.buf.code_action, '[C]ode [A]ction')
|
||||||
|
|
||||||
|
-- symbols and gotos
|
||||||
|
nmap('gd', vim.lsp.buf.definition, '[G]oto [D]efinition')
|
||||||
|
nmap('gi', vim.lsp.buf.implementation, '[G]oto [I]mplementation')
|
||||||
|
nmap('gr', require('telescope.builtin').lsp_references)
|
||||||
|
nmap('<leader>ds', require('telescope.builtin').lsp_document_symbols, '[D]ocument [S]ymbols')
|
||||||
|
nmap('<leader>ws', require('telescope.builtin').lsp_dynamic_workspace_symbols, '[W]orkspace [S]ymbols')
|
||||||
|
|
||||||
|
-- documentations. See `:help K` for why this keymap
|
||||||
|
nmap('K', vim.lsp.buf.hover, 'Hover Documentation')
|
||||||
|
nmap('<C-k>', vim.lsp.buf.signature_help, 'Signature Documentation')
|
||||||
|
|
||||||
|
-- Lesser used LSP functionality
|
||||||
|
nmap('gD', vim.lsp.buf.declaration, '[G]oto [D]eclaration')
|
||||||
|
nmap('<leader>D', vim.lsp.buf.type_definition, 'Type [D]efinition')
|
||||||
|
nmap('<leader>ja', vim.lsp.buf.add_workspace_folder, '[W]orkspace [A]dd Folder')
|
||||||
|
nmap('<leader>wr', vim.lsp.buf.remove_workspace_folder, '[W]orkspace [R]emove Folder')
|
||||||
|
nmap('<leader>wl', function()
|
||||||
|
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
|
||||||
|
end, '[W]orkspace [L]ist Folders')
|
||||||
|
|
||||||
|
-- Create a command `:Format` local to the LSP buffer
|
||||||
|
vim.api.nvim_buf_create_user_command(bufnr, 'Format', vim.lsp.buf.format or vim.lsp.buf.formatting,
|
||||||
|
{ desc = 'Format current buffer with LSP' })
|
||||||
|
end
|
||||||
|
-- nvim-cmp supports additional completion capabilities
|
||||||
|
local capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities())
|
||||||
|
-- default language servers
|
||||||
|
local servers = { 'clangd', 'rust_analyzer', 'pyright', 'tsserver', 'sumneko_lua' }
|
||||||
|
require("mason").setup({
|
||||||
|
ui = {
|
||||||
|
icons = {
|
||||||
|
package_installed = "✓",
|
||||||
|
package_pending = "➜",
|
||||||
|
package_uninstalled = "✗"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
require('mason-lspconfig').setup({
|
||||||
|
ensure_installed = servers,
|
||||||
|
-- automatic_installation = true
|
||||||
|
})
|
||||||
|
for _, lsp in ipairs(servers) do
|
||||||
|
require('lspconfig')[lsp].setup {
|
||||||
|
on_attach = on_attach,
|
||||||
|
capabilities = capabilities,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
-- config overwrites
|
||||||
|
require('lspconfig').sumneko_lua.setup {
|
||||||
|
on_attach = on_attach,
|
||||||
|
capabilities = capabilities,
|
||||||
|
settings = {
|
||||||
|
Lua = {
|
||||||
|
runtime = {
|
||||||
|
version = "LuaJIT",
|
||||||
|
path = vim.split(package.path, ";"),
|
||||||
|
},
|
||||||
|
diagnostics = {
|
||||||
|
globals = {"vim"}
|
||||||
|
},
|
||||||
|
workspace = {
|
||||||
|
library = vim.api.nvim_get_runtime_file('', true)
|
||||||
|
},
|
||||||
|
telemetry = {enable = false}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
-- nvim-cmp
|
||||||
|
local cmp = require 'cmp'
|
||||||
|
local luasnip = require 'luasnip'
|
||||||
|
|
||||||
|
cmp.setup {
|
||||||
|
snippet = {
|
||||||
|
expand = function(args)
|
||||||
|
luasnip.lsp_expand(args.body)
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
mapping = cmp.mapping.preset.insert {
|
||||||
|
['<C-u>'] = cmp.mapping.scroll_docs(-4),
|
||||||
|
['<C-d>'] = cmp.mapping.scroll_docs(4),
|
||||||
|
['<C-Space>'] = cmp.mapping.complete(),
|
||||||
|
['<CR>'] = cmp.mapping.confirm {
|
||||||
|
behavior = cmp.ConfirmBehavior.Replace,
|
||||||
|
select = true,
|
||||||
|
},
|
||||||
|
['<Tab>'] = cmp.mapping(function(fallback)
|
||||||
|
if cmp.visible() then
|
||||||
|
cmp.select_next_item()
|
||||||
|
elseif luasnip.expand_or_jumpable() then
|
||||||
|
luasnip.expand_or_jump()
|
||||||
|
else
|
||||||
|
fallback()
|
||||||
|
end
|
||||||
|
end, { 'i', 's' }),
|
||||||
|
['<S-Tab>'] = cmp.mapping(function(fallback)
|
||||||
|
if cmp.visible() then
|
||||||
|
cmp.select_prev_item()
|
||||||
|
elseif luasnip.jumpable(-1) then
|
||||||
|
luasnip.jump(-1)
|
||||||
|
else
|
||||||
|
fallback()
|
||||||
|
end
|
||||||
|
end, { 'i', 's' }),
|
||||||
|
},
|
||||||
|
sources = {
|
||||||
|
{ name = 'nvim_lsp' },
|
||||||
|
{ name = 'luasnip' },
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
-- Gitsigns
|
||||||
|
require('gitsigns').setup {
|
||||||
|
signs = {
|
||||||
|
add = { text = '+' },
|
||||||
|
change = { text = '~' },
|
||||||
|
delete = { text = '_' },
|
||||||
|
topdelete = { text = '‾' },
|
||||||
|
changedelete = { text = '~' },
|
||||||
|
}
|
||||||
|
}
|
||||||
|
require('lualine').setup {
|
||||||
|
options = {
|
||||||
|
icons_enabled = true,
|
||||||
|
theme = 'onedark',
|
||||||
|
component_separators = '|',
|
||||||
|
section_separators = '',
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue