New neovim config.
I've been using neovim for a while but the config got messy so here is a cleaner config. Signed-off-by: Louis Hollingworth <louis@hollingworth.nl>
This commit is contained in:
commit
c5000e27eb
135
after/plugin/lsp.lua
Normal file
135
after/plugin/lsp.lua
Normal file
|
@ -0,0 +1,135 @@
|
|||
local keymap = vim.keymap.set
|
||||
|
||||
require('mason').setup({
|
||||
ui = {
|
||||
icons = {
|
||||
server = " ",
|
||||
lsp = " ",
|
||||
linter = " ",
|
||||
formatter = " ",
|
||||
|
||||
package_installed = "✓",
|
||||
package_pending = "➜",
|
||||
package_uninstalled = "✗"
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
require("mason-lspconfig").setup({
|
||||
automatic_installation = true,
|
||||
})
|
||||
|
||||
local lsp = require('lspconfig')
|
||||
|
||||
local cmp = require('cmp')
|
||||
local cmp_select = {behavior = cmp.SelectBehavior.Select}
|
||||
|
||||
local opts = { noremap=true, silent=true }
|
||||
--keymap('i', '<C-Space>', vim.diagnostic.open_float, opts)
|
||||
--keymap('i', '<C-p>', vim.diagnostic.goto_prev, opts)
|
||||
--keymap('i', '<C-n>', vim.diagnostic.goto_next, opts)
|
||||
--keymap('i', '<C-Space>', cmp.mapping.complete(), opts)
|
||||
--keymap('i', '<CR>', vim.diagnostic.setloclist, opts)
|
||||
keymap('n', '<C-Space>', vim.diagnostic.open_float, opts)
|
||||
keymap('n', '<C-p>', vim.diagnostic.goto_prev, opts)
|
||||
keymap('n', '<C-n>', vim.diagnostic.goto_next, opts)
|
||||
--keymap('i', '<C-Space>', cmp.mapping.complete(), opts)
|
||||
keymap('n', '<CR>', vim.diagnostic.setloclist, opts)
|
||||
|
||||
cmp.setup({
|
||||
snippet = {
|
||||
expand = function(args)
|
||||
require('luasnip').lsp_expand(args.body)
|
||||
end,
|
||||
},
|
||||
mapping = {
|
||||
['<C-p>'] = cmp.mapping.select_prev_item(cmp_select),
|
||||
['<C-n>'] = cmp.mapping.select_next_item(cmp_select),
|
||||
['<C-Space>'] = cmp.mapping.complete(cmp_select),
|
||||
['<C-e>'] = cmp.mapping.close(),
|
||||
['<CR>'] = cmp.mapping.confirm({
|
||||
behavior = cmp.ConfirmBehavior.Replace,
|
||||
select = true,
|
||||
}),
|
||||
},
|
||||
sources = {
|
||||
{ name = 'nvim_lsp' },
|
||||
{ name = 'luasnip' },
|
||||
{ name = 'buffer' },
|
||||
},
|
||||
})
|
||||
|
||||
vim.diagnostic.config({
|
||||
virtual_text = true,
|
||||
})
|
||||
|
||||
local on_attach = function(client, bufnr)
|
||||
local function buf_set_keymap(...)
|
||||
vim.api.nvim_buf_set_keymap(bufnr, ...)
|
||||
end
|
||||
|
||||
-- Mappings.
|
||||
local opts = { noremap = true, silent = true, buffer = bufnr}
|
||||
|
||||
-- See `:help vim.lsp.*` for documentation on any of the below functions
|
||||
vim.keymap.set("n", "gd", "<cmd>Telescope lsp_definitions<CR>", opts)
|
||||
vim.keymap.set("n", "gr", "<cmd>Telescope lsp_references<CR>", opts)
|
||||
|
||||
vim.keymap.set("n", "<C-j>", "<cmd>Telescope lsp_document_symbols<CR>", opts)
|
||||
vim.keymap.set("n", "<C-k>", "<cmd>lua vim.lsp.buf.signature_help()<CR>", opts)
|
||||
|
||||
vim.keymap.set("n", "gi", "<cmd>Telescope lsp_implementations<CR>", opts)
|
||||
vim.keymap.set("n", "K", "<cmd>lua vim.lsp.buf.hover()<CR>", opts)
|
||||
vim.keymap.set("n", "<leader>D", "<cmd>Telescope lsp_type_definitions<CR>", opts)
|
||||
vim.keymap.set("n", "<leader>rn", "<cmd>lua vim.lsp.buf.rename()<CR>", opts)
|
||||
vim.keymap.set("n", "<leader>ca", "<cmd>Telescope lsp_code_actions<CR>", opts)
|
||||
vim.keymap.set("n", "gt", vim.lsp.buf.type_definition, {buffer=0})
|
||||
vim.keymap.set("n", "gi", vim.lsp.buf.implementation, {buffer=0})
|
||||
vim.keymap.set("n", "<leader>dj", vim.diagnostic.goto_next, {buffer=0})
|
||||
vim.keymap.set("n", "<leader>dk", vim.diagnostic.goto_prev, {buffer=0})
|
||||
vim.keymap.set("n", "<leader>dl", "<cmd>Telescope diagnostics<cr>", {buffer=0})
|
||||
vim.keymap.set("n", "<leader>r", vim.lsp.buf.rename, {buffer=0})
|
||||
vim.keymap.set("n", "<leader>ca", vim.lsp.buf.code_action, {buffer=0})
|
||||
|
||||
-- Set autocommands conditional on server_capabilities
|
||||
if client.server_capabilities.document_highlight then
|
||||
vim.cmd([[
|
||||
augroup lsp_document_highlight
|
||||
autocmd! * <buffer>
|
||||
autocmd CursorHold <buffer> lua vim.lsp.buf.document_highlight()
|
||||
autocmd CursorMoved <buffer> lua vim.lsp.buf.clear_references()
|
||||
augroup END
|
||||
]])
|
||||
end
|
||||
end
|
||||
|
||||
lsp.gopls.setup({
|
||||
on_attach = on_attach,
|
||||
flags = lsp_flags,
|
||||
settings = {
|
||||
gopls = {
|
||||
analyses = {
|
||||
unusedparams = true,
|
||||
},
|
||||
staticcheck = true,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
lsp['lua_ls'].setup{
|
||||
on_attach = on_attach,
|
||||
flags = lsp_flags,
|
||||
}
|
||||
|
||||
lsp['rust_analyzer'].setup{
|
||||
on_attach = on_attach,
|
||||
flags = lsp_flags,
|
||||
cmd = {
|
||||
"rustup", "run", "stable", "rust-analyzer",
|
||||
}
|
||||
}
|
||||
|
||||
lsp.tsserver.setup{
|
||||
on_attach = on_attach,
|
||||
flags = lsp_flags,
|
||||
}
|
31
lazy-lock.json
Normal file
31
lazy-lock.json
Normal file
|
@ -0,0 +1,31 @@
|
|||
{
|
||||
"LuaSnip": { "branch": "master", "commit": "f3b3d3446bcbfa62d638b1903ff00a78b2b730a1" },
|
||||
"cmp-buffer": { "branch": "main", "commit": "3022dbc9166796b644a841a02de8dd1cc1d311fa" },
|
||||
"cmp-nvim-lsp": { "branch": "main", "commit": "5af77f54de1b16c34b23cba810150689a3a90312" },
|
||||
"cmp-path": { "branch": "main", "commit": "91ff86cd9c29299a64f968ebb45846c485725f23" },
|
||||
"cmp_luasnip": { "branch": "master", "commit": "05a9ab28b53f71d1aece421ef32fee2cb857a843" },
|
||||
"editorconfig-vim": { "branch": "master", "commit": "0956bc257ca4eaa3e087e0ba2253a3e980805820" },
|
||||
"formatter.nvim": { "branch": "master", "commit": "cb4778b8432f1ae86dae4634c0b611cb269a4c2f" },
|
||||
"friendly-snippets": { "branch": "main", "commit": "dcd4a586439a1c81357d5b9d26319ae218cc9479" },
|
||||
"glow.nvim": { "branch": "main", "commit": "238070a686c1da3bccccf1079700eb4b5e19aea4" },
|
||||
"lazy.nvim": { "branch": "main", "commit": "aedcd79811d491b60d0a6577a9c1701063c2a609" },
|
||||
"lspkind.nvim": { "branch": "master", "commit": "1735dd5a5054c1fb7feaf8e8658dbab925f4f0cf" },
|
||||
"lspsaga.nvim": { "branch": "main", "commit": "b1b140aa20a0cf353cd3e282870429b48b30a169" },
|
||||
"lualine.nvim": { "branch": "master", "commit": "7d131a8d3ba5016229e8a1d08bf8782acea98852" },
|
||||
"mason-lspconfig.nvim": { "branch": "main", "commit": "21d33d69a81f6351e5a5f49078b2e4f0075c8e73" },
|
||||
"mason.nvim": { "branch": "main", "commit": "3b5068f0fc565f337d67a2d315d935f574848ee7" },
|
||||
"nvim-cmp": { "branch": "main", "commit": "04e0ca376d6abdbfc8b52180f8ea236cbfddf782" },
|
||||
"nvim-dap": { "branch": "master", "commit": "fc880e82059eb21c0fa896be60146e5f17680648" },
|
||||
"nvim-dap-ui": { "branch": "master", "commit": "9720eb5fa2f41988e8770f973cd11b76dd568a5d" },
|
||||
"nvim-lint": { "branch": "master", "commit": "e824adb9bc01647f71e55457353a68f0f37f9931" },
|
||||
"nvim-lspconfig": { "branch": "master", "commit": "9553725789be682ecd945a527ec552e489ea8534" },
|
||||
"nvim-treesitter": { "branch": "master", "commit": "a47540fd737eb5c03ee21ee69eb8134ce5568fb6" },
|
||||
"nvim-web-devicons": { "branch": "master", "commit": "0bb67ef952ea3eb7b1bac9c011281471d99a27bc" },
|
||||
"plenary.nvim": { "branch": "master", "commit": "4f71c0c4a196ceb656c824a70792f3df3ce6bb6d" },
|
||||
"telescope-fzf-native.nvim": { "branch": "main", "commit": "6c921ca12321edaa773e324ef64ea301a1d0da62" },
|
||||
"telescope.nvim": { "branch": "master", "commit": "aa83606299c5beeaf80e656efbf07bde258db7be" },
|
||||
"todo-comments.nvim": { "branch": "main", "commit": "833d8dd8b07eeda37a09e99460f72a02616935cb" },
|
||||
"tokyonight.nvim": { "branch": "main", "commit": "610179f7f12db3d08540b6cc61434db2eaecbcff" },
|
||||
"undotree": { "branch": "master", "commit": "9dbbf3b7d19dda0d22ceca461818e4739ad8154d" },
|
||||
"vim-wakatime": { "branch": "master", "commit": "285c2e4e48fb0c63ced233c00fb10a2edb3b6c94" }
|
||||
}
|
43
lua/lucxjo/init.lua
Normal file
43
lua/lucxjo/init.lua
Normal file
|
@ -0,0 +1,43 @@
|
|||
require("lucxjo.keys")
|
||||
require("lucxjo.lazy")
|
||||
require("lucxjo.opts")
|
||||
|
||||
local augroup = vim.api.nvim_create_augroup
|
||||
local lucxjo_group = augroup('lucxjo', {})
|
||||
|
||||
local aucmd = vim.api.nvim_create_autocmd
|
||||
local yank_group = augroup('HlYank', {})
|
||||
|
||||
aucmd('TextYankPost', {
|
||||
group = yank_group,
|
||||
pattern = '*',
|
||||
callback = function()
|
||||
vim.highlight.on_yank({
|
||||
higroup = 'IncSearch',
|
||||
timeout = 40,
|
||||
})
|
||||
end,
|
||||
})
|
||||
|
||||
aucmd({"BufWritePre"}, {
|
||||
group = lucxjo_group,
|
||||
pattern = "*",
|
||||
command = [[%s/\s\+$//e]],
|
||||
})
|
||||
|
||||
aucmd('LspAttach', {
|
||||
group = lucxjo,
|
||||
callback = function(e)
|
||||
local opts = { buffer = e.buf }
|
||||
vim.keymap.set("n", "gd", function() vim.lsp.buf.definition() end, opts)
|
||||
vim.keymap.set("n", "K", function() vim.lsp.buf.hover() end, opts)
|
||||
vim.keymap.set("n", "<leader>vws", function() vim.lsp.buf.workspace_symbol() end, opts)
|
||||
vim.keymap.set("n", "<leader>vd", function() vim.diagnostic.open_float() end, opts)
|
||||
vim.keymap.set("n", "<leader>vca", function() vim.lsp.buf.code_action() end, opts)
|
||||
vim.keymap.set("n", "<leader>vrr", function() vim.lsp.buf.references() end, opts)
|
||||
vim.keymap.set("n", "<leader>vrn", function() vim.lsp.buf.rename() end, opts)
|
||||
vim.keymap.set("i", "<C-h>", function() vim.lsp.buf.signature_help() end, opts)
|
||||
vim.keymap.set("n", "[d", function() vim.diagnostic.goto_next() end, opts)
|
||||
vim.keymap.set("n", "]d", function() vim.diagnostic.goto_prev() end, opts)
|
||||
end
|
||||
})
|
13
lua/lucxjo/keys.lua
Normal file
13
lua/lucxjo/keys.lua
Normal file
|
@ -0,0 +1,13 @@
|
|||
vim.g.mapleader = " "
|
||||
|
||||
local map = vim.api.nvim_set_keymap
|
||||
|
||||
map("n", "<leader>p", ":Glow<cr>", {})
|
||||
map("n", "<leader>ch", ":nohl<cr>", { silent = true })
|
||||
|
||||
-- File management
|
||||
map("n", "<leader>s", ":w<cr>", { silent = true})
|
||||
map("n", "<leader>q", ":q<cr>", {})
|
||||
map("n", "<leader>Q", ":q!<cr>", {})
|
||||
map("n", "<leader>S", ":wq<cr>", {})
|
||||
map("n", "<leader>fp", ":Ex<cr>", {})
|
14
lua/lucxjo/lazy.lua
Normal file
14
lua/lucxjo/lazy.lua
Normal file
|
@ -0,0 +1,14 @@
|
|||
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
|
||||
if not vim.loop.fs_stat(lazypath) then
|
||||
vim.fn.system({
|
||||
"git",
|
||||
"clone",
|
||||
"--filter=blob:none",
|
||||
"https://github.com/folke/lazy.nvim.git",
|
||||
"--branch=stable", -- latest stable release
|
||||
lazypath,
|
||||
})
|
||||
end
|
||||
vim.opt.rtp:prepend(lazypath)
|
||||
|
||||
require("lazy").setup("lucxjo.plugins")
|
39
lua/lucxjo/opts.lua
Normal file
39
lua/lucxjo/opts.lua
Normal file
|
@ -0,0 +1,39 @@
|
|||
local opt = vim.opt
|
||||
|
||||
-- Context
|
||||
opt.colorcolumn = "80"
|
||||
opt.number = true
|
||||
opt.relativenumber = true
|
||||
opt.scrolloff = 4
|
||||
opt.signcolumn = "yes"
|
||||
|
||||
-- Filetypes
|
||||
opt.encoding = "utf8"
|
||||
opt.fileencoding = "utf8"
|
||||
|
||||
-- Theme
|
||||
opt.syntax = "ON"
|
||||
opt.termguicolors = true
|
||||
|
||||
-- Search
|
||||
opt.ignorecase = true
|
||||
opt.smartcase = true
|
||||
opt.incsearch = true
|
||||
opt.hlsearch = true
|
||||
|
||||
-- Whitespace
|
||||
opt.expandtab = true
|
||||
opt.shiftwidth = 4
|
||||
opt.softtabstop = 4
|
||||
opt.tabstop = 4
|
||||
opt.smartindent = true
|
||||
|
||||
-- Undo
|
||||
opt.undodir = os.getenv("HOME") .. "/.vim/undodir"
|
||||
opt.undofile = true
|
||||
|
||||
-- Misc
|
||||
opt.backspace = "indent,eol,start"
|
||||
opt.clipboard:append("unnamedplus")
|
||||
opt.iskeyword:append("-")
|
||||
vim.cmd[[colorscheme tokyonight]]
|
32
lua/lucxjo/plugins/init.lua
Normal file
32
lua/lucxjo/plugins/init.lua
Normal file
|
@ -0,0 +1,32 @@
|
|||
return {
|
||||
{
|
||||
"folke/tokyonight.nvim",
|
||||
lazy = false,
|
||||
priority = 1000,
|
||||
opts = {
|
||||
transparent = true,
|
||||
},
|
||||
},
|
||||
"editorconfig/editorconfig-vim",
|
||||
{
|
||||
"ellisonleao/glow.nvim",
|
||||
config = function() require("glow").setup() end,
|
||||
},
|
||||
{
|
||||
"nvim-lualine/lualine.nvim",
|
||||
dependencies = { "nvim-tree/nvim-web-devicons" },
|
||||
config = function() require("lualine").setup{
|
||||
options = {
|
||||
theme = "tokyonight",
|
||||
},
|
||||
} end,
|
||||
},
|
||||
"wakatime/vim-wakatime",
|
||||
{
|
||||
"folke/todo-comments.nvim",
|
||||
dependencies = { "nvim-lua/plenary.nvim" },
|
||||
opts = {},
|
||||
},
|
||||
"nvim-tree/nvim-web-devicons",
|
||||
"mbbill/undotree",
|
||||
}
|
57
lua/lucxjo/plugins/lsp.lua
Normal file
57
lua/lucxjo/plugins/lsp.lua
Normal file
|
@ -0,0 +1,57 @@
|
|||
return {
|
||||
-- Autocomplete
|
||||
"hrsh7th/nvim-cmp",
|
||||
"hrsh7th/cmp-buffer",
|
||||
"hrsh7th/cmp-path",
|
||||
|
||||
-- Snippets
|
||||
{
|
||||
"L3MON4D3/LuaSnip",
|
||||
build = "make install_jsregexp",
|
||||
},
|
||||
"saadparwaiz1/cmp_luasnip",
|
||||
"rafamadriz/friendly-snippets",
|
||||
|
||||
-- Manage
|
||||
{
|
||||
"williamboman/mason.nvim",
|
||||
config = function() require("mason").setup() end,
|
||||
},
|
||||
{
|
||||
"williamboman/mason-lspconfig.nvim",
|
||||
config = function() require("mason-lspconfig").setup() end,
|
||||
},
|
||||
|
||||
-- Configure
|
||||
"neovim/nvim-lspconfig",
|
||||
"hrsh7th/cmp-nvim-lsp",
|
||||
"glepnir/lspsaga.nvim",
|
||||
"onsails/lspkind.nvim",
|
||||
|
||||
-- Lint
|
||||
{
|
||||
"mfussenegger/nvim-lint",
|
||||
config = function()
|
||||
require("lint").linters_by_ft = {
|
||||
go = {'golangclient'},
|
||||
lua = {'luacheck'},
|
||||
sh = {'shellcheck'},
|
||||
c = {'cpplint'}
|
||||
}
|
||||
end,
|
||||
},
|
||||
|
||||
-- Format
|
||||
{
|
||||
"mhartington/formatter.nvim",
|
||||
config = function()
|
||||
require("formatter").setup()
|
||||
end,
|
||||
},
|
||||
|
||||
-- DAP
|
||||
{
|
||||
"rcarriga/nvim-dap-ui",
|
||||
dependencies = {"mfussenegger/nvim-dap"}
|
||||
},
|
||||
}
|
20
lua/lucxjo/plugins/telescope.lua
Normal file
20
lua/lucxjo/plugins/telescope.lua
Normal file
|
@ -0,0 +1,20 @@
|
|||
return {
|
||||
{
|
||||
'nvim-telescope/telescope.nvim',
|
||||
dependencies = {
|
||||
'nvim-lua/plenary.nvim',
|
||||
'nvim-telescope/telescope-fzf-native.nvim',
|
||||
},
|
||||
config = function()
|
||||
local builtin = require('telescope.builtin')
|
||||
vim.keymap.set('n', '<leader>ff', builtin.find_files, {})
|
||||
vim.keymap.set('n', '<leader>fg', builtin.live_grep, {})
|
||||
vim.keymap.set('n', '<leader>fb', builtin.buffers, {})
|
||||
vim.keymap.set('n', '<leader>fh', builtin.help_tags, {})
|
||||
end,
|
||||
},
|
||||
{
|
||||
'nvim-telescope/telescope-fzf-native.nvim',
|
||||
build = 'cmake -S. -Bbuild -DCMAKE_BUILD_TYPE=Release && cmake --build build --config Release && cmake --install build --prefix build'
|
||||
},
|
||||
}
|
4
lua/lucxjo/plugins/treesitter.lua
Normal file
4
lua/lucxjo/plugins/treesitter.lua
Normal file
|
@ -0,0 +1,4 @@
|
|||
return {
|
||||
"nvim-treesitter/nvim-treesitter",
|
||||
config = function() require('nvim-treesitter.install').update({ with_sync = true }) end,
|
||||
}
|
Loading…
Reference in a new issue