216 lines
6.5 KiB
Lua
216 lines
6.5 KiB
Lua
local Plug = vim.fn['plug#']
|
|
|
|
vim.call('plug#begin')
|
|
|
|
Plug 'nvim-tree/nvim-web-devicons'
|
|
Plug 'nvim-tree/nvim-tree.lua'
|
|
|
|
Plug 'ellisonleao/gruvbox.nvim'
|
|
|
|
Plug 'williamboman/mason.nvim'
|
|
Plug 'williamboman/mason-lspconfig.nvim'
|
|
Plug 'neovim/nvim-lspconfig'
|
|
|
|
Plug 'hrsh7th/cmp-nvim-lsp'
|
|
Plug 'hrsh7th/cmp-buffer'
|
|
Plug 'hrsh7th/cmp-path'
|
|
Plug 'hrsh7th/cmp-cmdline'
|
|
Plug 'hrsh7th/nvim-cmp'
|
|
|
|
Plug 'nvim-lua/plenary.nvim'
|
|
Plug 'nvim-telescope/telescope.nvim'
|
|
|
|
vim.call('plug#end')
|
|
|
|
vim.g.loaded_netrw = 1
|
|
vim.g.loaded_netrwPlugin = 1
|
|
|
|
vim.opt.termguicolors = true
|
|
vim.o.background = "dark"
|
|
require("gruvbox").setup({
|
|
contrast = "hard",
|
|
})
|
|
vim.cmd("colorscheme gruvbox")
|
|
|
|
require("mason").setup()
|
|
require("mason-lspconfig").setup({
|
|
ensure_installed = {"ts_ls", "gopls"}
|
|
})
|
|
require("nvim-tree").setup({
|
|
view = {
|
|
number = false,
|
|
relativenumber = false,
|
|
},
|
|
renderer = {
|
|
indent_markers = {
|
|
enable = true,
|
|
},
|
|
icons = {
|
|
show = {
|
|
git = false,
|
|
},
|
|
},
|
|
highlight_git = "name",
|
|
highlight_opened_files = "name",
|
|
},
|
|
filters = {
|
|
dotfiles = false,
|
|
},
|
|
git = {
|
|
ignore = false,
|
|
},
|
|
actions = {
|
|
open_file = {
|
|
quit_on_open = true,
|
|
},
|
|
},
|
|
})
|
|
|
|
-- Global statuscolumn (line 190-ish) bakes in line numbers; nvim-tree doesn't
|
|
-- manage statuscolumn itself, so strip it locally for the tree buffer.
|
|
-- Must hook BufWinEnter (not FileType): nvim-tree sets 'filetype' on the
|
|
-- buffer before moving it into its own split, so a FileType autocmd fires
|
|
-- in the wrong window and opt_local misses the tree's actual window.
|
|
vim.api.nvim_create_autocmd("BufWinEnter", {
|
|
pattern = "NvimTree_*",
|
|
callback = function()
|
|
vim.opt_local.statuscolumn = ""
|
|
end,
|
|
})
|
|
|
|
vim.opt.number = true
|
|
vim.opt.swapfile = true
|
|
vim.opt.autoindent = true
|
|
vim.opt.shiftwidth = 4
|
|
vim.opt.confirm = true
|
|
|
|
local cmp = require'cmp'
|
|
|
|
cmp.setup({
|
|
snippet = {
|
|
expand = function(args)
|
|
vim.snippet.expand(args.body) -- native neovim snippets (Neovim v0.10+)
|
|
end,
|
|
},
|
|
window = {
|
|
completion = cmp.config.window.bordered(),
|
|
documentation = cmp.config.window.bordered(),
|
|
},
|
|
mapping = cmp.mapping.preset.insert({
|
|
['<C-b>'] = cmp.mapping.scroll_docs(-4),
|
|
['<C-f>'] = cmp.mapping.scroll_docs(4),
|
|
['<C-Space>'] = cmp.mapping.complete(),
|
|
['<C-e>'] = cmp.mapping.abort(),
|
|
['<CR>'] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
|
|
}),
|
|
sources = cmp.config.sources({
|
|
{ name = 'nvim_lsp' },
|
|
}, {
|
|
{ name = 'buffer' },
|
|
})
|
|
})
|
|
|
|
-- To use git you need to install the plugin petertriho/cmp-git and uncomment lines below
|
|
-- Set configuration for specific filetype.
|
|
--[[ cmp.setup.filetype('gitcommit', {
|
|
sources = cmp.config.sources({
|
|
{ name = 'git' },
|
|
}, {
|
|
{ name = 'buffer' },
|
|
})
|
|
})
|
|
require("cmp_git").setup() ]]--
|
|
|
|
-- Use buffer source for `/` and `?` (if you enabled `native_menu`, this won't work anymore).
|
|
cmp.setup.cmdline({ '/', '?' }, {
|
|
mapping = cmp.mapping.preset.cmdline(),
|
|
sources = {
|
|
{ name = 'buffer' }
|
|
}
|
|
})
|
|
|
|
-- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore).
|
|
cmp.setup.cmdline(':', {
|
|
mapping = cmp.mapping.preset.cmdline(),
|
|
sources = cmp.config.sources({
|
|
{ name = 'path' }
|
|
}, {
|
|
{ name = 'cmdline' }
|
|
}),
|
|
matching = { disallow_symbol_nonprefix_matching = false }
|
|
})
|
|
|
|
-- Set up lspconfig.
|
|
local capabilities = require('cmp_nvim_lsp').default_capabilities()
|
|
-- Replace <YOUR_LSP_SERVER> with each lsp server you've enabled.
|
|
require('lspconfig')['ts_ls'].setup {
|
|
capabilities = capabilities
|
|
}
|
|
require('lspconfig')['gopls'].setup {
|
|
capabilities = capabilities
|
|
}
|
|
|
|
-- Format Go files on save using the attached LSP server (gopls).
|
|
vim.api.nvim_create_autocmd("BufWritePre", {
|
|
pattern = "*.go",
|
|
callback = function()
|
|
vim.lsp.buf.format()
|
|
end,
|
|
})
|
|
|
|
-- Close any open floating windows (e.g. the hover/signature-help popup).
|
|
local function close_floating_windows()
|
|
for _, win in ipairs(vim.api.nvim_list_wins()) do
|
|
if vim.api.nvim_win_get_config(win).relative ~= "" then
|
|
vim.api.nvim_win_close(win, false)
|
|
end
|
|
end
|
|
end
|
|
vim.keymap.set('n', '<Esc>', close_floating_windows, { noremap = true, silent = true })
|
|
|
|
-- Give all floating windows (hover, signature-help, diagnostics, etc.) a rounded border.
|
|
vim.o.winborder = "rounded"
|
|
|
|
-- Match floating windows' background to the main editor background.
|
|
vim.api.nvim_set_hl(0, "NormalFloat", { link = "Normal" })
|
|
vim.api.nvim_set_hl(0, "FloatBorder", { link = "Normal" })
|
|
|
|
-- LSP keymaps, set up per-buffer whenever a language server attaches.
|
|
vim.api.nvim_create_autocmd("LspAttach", {
|
|
callback = function(args)
|
|
local opts = { noremap = true, silent = true, buffer = args.buf }
|
|
vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts)
|
|
vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, opts)
|
|
vim.keymap.set('n', 'gr', vim.lsp.buf.references, opts)
|
|
vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, opts)
|
|
vim.keymap.set('n', 'K', vim.lsp.buf.hover, opts)
|
|
vim.keymap.set('n', '<leader>rn', vim.lsp.buf.rename, opts)
|
|
vim.keymap.set('n', '<leader>ca', vim.lsp.buf.code_action, opts)
|
|
end,
|
|
})
|
|
|
|
-- set space as leader keymap
|
|
vim.keymap.set('n', ' ', '<Nop>', {noremap = true, silent = true})
|
|
vim.g.mapleader = ' '
|
|
|
|
-- Diagnostic keymaps (not tied to LspAttach; work globally)
|
|
vim.keymap.set('n', '<leader>e', vim.diagnostic.open_float, { noremap = true, silent = true })
|
|
vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, { noremap = true, silent = true })
|
|
vim.keymap.set('n', ']d', vim.diagnostic.goto_next, { noremap = true, silent = true })
|
|
vim.keymap.set('n', '<leader>q', vim.diagnostic.setloclist, { noremap = true, silent = true })
|
|
|
|
vim.keymap.set('n', '<leader>x', ':NvimTreeToggle<CR>', {noremap = true, silent = true})
|
|
vim.keymap.set('n', '<leader>n', ':bnext<CR>', {noremap = true, silent = true})
|
|
vim.keymap.set('n', '<leader>p', ':bprevious<CR>', {noremap = true, silent = true})
|
|
vim.keymap.set('n', '<leader>d', ':bdelete<CR>', {noremap = true, silent = true})
|
|
|
|
require('telescope').setup()
|
|
local telescopeBuiltin = require('telescope.builtin')
|
|
vim.keymap.set('n', '<leader>ff', telescopeBuiltin.find_files, {noremap = true, silent = true})
|
|
vim.keymap.set('n', '<leader>fg', telescopeBuiltin.live_grep, {noremap = true, silent = true})
|
|
vim.keymap.set('n', '<leader>fb', telescopeBuiltin.buffers, {noremap = true, silent = true})
|
|
vim.keymap.set('n', '<leader>fh', telescopeBuiltin.help_tags, {noremap = true, silent = true})
|
|
|
|
vim.opt.statuscolumn = "%s %3{v:lnum} %-3{v:relnum} "
|
|
vim.o.rnu=true
|
|
|