revamped nvim config with lsp.zero

This commit is contained in:
Rahsheen Porter 2023-01-01 16:30:32 -05:00
parent b32fa96788
commit 1f2f336b64
9 changed files with 283 additions and 350 deletions

View file

@ -1,3 +1,3 @@
require("rahcodes.packer")
require("rahcodes.set")
require("rahcodes.remap")
require("rahcodes.packer")

View file

@ -1,18 +1,12 @@
-- This file can be loaded by calling `lua require('plugins')` from your init.vim
local ensure_packer = function()
local fn = vim.fn
local install_path = fn.stdpath("data") .. "/site/pack/packer/start/packer.nvim"
if fn.empty(fn.glob(install_path)) > 0 then
fn.system({ "git", "clone", "--depth", "1", "https://github.com/wbthomason/packer.nvim", install_path })
vim.cmd([[packadd packer.nvim]])
return true
end
return false
local install_path = vim.fn.stdpath("data") .. "/site/pack/packer/start/packer.nvim"
local is_bootstrap = false
if vim.fn.empty(vim.fn.glob(install_path)) > 0 then
is_bootstrap = true
vim.fn.system({ "git", "clone", "--depth", "1", "https://github.com/wbthomason/packer.nvim", install_path })
vim.cmd([[packadd packer.nvim]])
end
local packer_bootstrap = ensure_packer()
return require("packer").startup(function(use)
require("packer").startup(function(use)
-- Packer can manage itself
use("wbthomason/packer.nvim")
use("folke/tokyonight.nvim")
@ -35,21 +29,29 @@ return require("packer").startup(function(use)
ts_update()
end,
})
use({ "williamboman/mason.nvim" })
use({ "williamboman/mason-lspconfig.nvim" })
-- configure lsp servers
use("neovim/nvim-lspconfig")
use("hrsh7th/cmp-nvim-lsp")
use("hrsh7th/cmp-buffer")
use("hrsh7th/nvim-cmp")
-- use("tzachar/cmp-tabnine", { run = "./install.sh" })
use("onsails/lspkind-nvim")
use("nvim-lua/lsp_extensions.nvim")
use("glepnir/lspsaga.nvim")
use("simrat39/symbols-outline.nvim")
use("L3MON4D3/LuaSnip")
use("saadparwaiz1/cmp_luasnip")
-- LSP
use({
"VonHeikemen/lsp-zero.nvim",
requires = {
-- LSP Support
{ "neovim/nvim-lspconfig" },
{ "williamboman/mason.nvim" },
{ "williamboman/mason-lspconfig.nvim" },
-- Autocompletion
{ "hrsh7th/nvim-cmp" },
{ "hrsh7th/cmp-buffer" },
{ "hrsh7th/cmp-path" },
{ "saadparwaiz1/cmp_luasnip" },
{ "hrsh7th/cmp-nvim-lsp" },
{ "hrsh7th/cmp-nvim-lua" },
-- Snippets
{ "L3MON4D3/LuaSnip" },
{ "rafamadriz/friendly-snippets" },
},
})
-- formatting & linting
use("jose-elias-alvarez/null-ls.nvim")
@ -92,9 +94,32 @@ return require("packer").startup(function(use)
end,
})
use("theprimeagen/harpoon")
-- Automatically set up your configuration after cloning packer.nvim
-- Put this at the end after all plugins
if packer_bootstrap then
if is_bootstrap then
require("packer").sync()
end
end)
-- When we are bootstrapping a configuration, it doesn't
-- make sense to execute the rest of the init.lua.
--
-- You'll need to restart nvim, and then it will work.
if is_bootstrap then
print("==================================")
print(" Plugins are being installed")
print(" Wait until Packer completes,")
print(" then restart nvim")
print("==================================")
return
end
-- Automatically source and re-compile packer whenever you save this init.lua
local packer_group = vim.api.nvim_create_augroup("Packer", { clear = true })
vim.api.nvim_create_autocmd("BufWritePost", {
command = "source <afile> | silent! LspStop | silent! LspStart | PackerCompile",
group = packer_group,
pattern = vim.fn.expand("$MYVIMRC"),
})

View file

@ -1,74 +1,61 @@
local Remap = require("rahcodes.keymap")
local nnoremap = Remap.nnoremap
local vnoremap = Remap.vnoremap
local inoremap = Remap.inoremap
local nmap = Remap.nmap
nnoremap("<leader>pv", "<cmd>Ex<CR>")
local builtin = require("telescope.builtin")
vim.keymap.set("n", "<leader>ff", builtin.find_files, {})
vim.keymap.set("n", "<leader>/", builtin.live_grep, {})
vim.keymap.set("n", "<leader>*", builtin.grep_string, {})
vim.keymap.set("n", "<leader>fb", builtin.buffers, {})
vim.keymap.set("n", "<leader>fh", builtin.help_tags, {})
vim.keymap.set("n", "<leader>pv", vim.cmd.Ex)
vim.keymap.set("n", "<leader>m", builtin.oldfiles, {})
vim.keymap.set("n", "<leader>gb", builtin.git_branches, {})
-- vim.keymap.set('n', '<leader>gs', builtin.git_status, {})
vim.keymap.set("n", "<leader><leader>", builtin.git_files, {})
vim.keymap.set("v", "J", ":m '>+1<CR>gv=gv")
vim.keymap.set("v", "K", ":m '<-2<CR>gv=gv")
-- Null Ls
nnoremap("<leader>lf", ":lua vim.lsp.buf.format({ timeout_ms = 10000 })<CR>")
nnoremap("<leader>lF", ":lua vim.lsp.buf.range_format({ timeout_ms = 2000 })<CR>")
vim.keymap.set("n", "<C-d>", "<C-d>zz")
vim.keymap.set("n", "<C-u>", "<C-u>zz")
-- Git Fugitive
nnoremap("<leader>gs", ":G<CR>")
nnoremap("<leader>gh", ":diffget //3<CR>")
nnoremap("<leader>gu", ":diffget //2<CR>")
nnoremap("<leader>gc", ":GCheckout<CR>")
nnoremap("<leader>ga", ":G add %:p<CR><CR>")
nnoremap("<leader>gc", ":G commit -v -q<CR>")
nnoremap("<leader>gt", ":G commit -v -q %:p<CR>")
nnoremap("<leader>gca", ":G commit --amend --no-edit<CR>")
nnoremap("<leader>gff", ":G ff<CR>")
nnoremap("<leader>gfo", ":G fetch origin<CR>")
nnoremap("<leader>gd", ":Gdiff<CR>")
nnoremap("<leader>ge", ":Gedit<CR>")
nnoremap("<leader>gr", ":Gread<CR>")
nnoremap("<leader>gw", ":Gwrite<CR><CR>")
nnoremap("<leader>gl", ":silent! Glog<CR>:bot copen<CR>")
nnoremap("<leader>gp", ":Ggrep<Space>")
nnoremap("<leader>gm", ":Gmove<Space>")
-- nnoremap("<leader>gb", ":G branch<Space>")
nnoremap("<leader>go", ":G checkout<Space>")
nnoremap("<leader>gps", ":Dispatch! git push<CR>")
nnoremap("<leader>gpl", ":Dispatch! git pull<CR>")
vim.keymap.set("n", "n", "nzzzv")
vim.keymap.set("n", "N", "Nzzzv")
vnoremap("J", ":m '>+1<CR>gv=gv")
vnoremap("K", ":m '<-2<CR>gv=gv")
-- don't bork paste buffer when pasting
vim.keymap.set("x", "<leader>p", '"_dP')
-- nnoremap("/", "/\v")
-- vnoremap("/", "/\v")
nnoremap("<leader>`", ":noh<cr>")
vim.keymap.set("i", "<C-c>", "<Esc>")
-- vim.keymap.set("n", "/", "/\v")
-- vim.keymap.set("v", "/", "/\v")
vim.keymap.set("n", "<leader>`", ":noh<cr>")
-- No Cheating
nnoremap("<up>", "<nop>")
nnoremap("<down>", "<nop>")
nnoremap("<left>", "<nop>")
nnoremap("<right>", "<nop>")
inoremap("<up>", "<nop>")
inoremap("<down>", "<nop>")
inoremap("<left>", "<nop>")
inoremap("<right>", "<nop>")
vim.keymap.set("n", "<up>", "<nop>")
vim.keymap.set("n", "<down>", "<nop>")
vim.keymap.set("n", "<left>", "<nop>")
vim.keymap.set("n", "<right>", "<nop>")
vim.keymap.set("i", "<up>", "<nop>")
vim.keymap.set("i", "<down>", "<nop>")
vim.keymap.set("i", "<left>", "<nop>")
vim.keymap.set("i", "<right>", "<nop>")
-- No weird line jumps
nnoremap("j", "gj")
nnoremap("k", "gk")
vim.keymap.set("n", "j", "gj")
vim.keymap.set("n", "k", "gk")
-- Copy to system clipboard
vnoremap("<leader>y", '"*y')
vnoremap("<leader>yy", '"+y')
vim.keymap.set("n", "<leader>y", '"*y')
vim.keymap.set("v", "<leader>y", '"*y')
vim.keymap.set("n", "<leader>yy", '"+y')
vim.keymap.set("v", "<leader>yy", '"+y')
vim.keymap.set("n", "<C-f>", "<cmd>silent !tmux neww tmux-sessionizer<CR>")
-- Move buffers
nmap("sp", ":bprev<Return>")
nmap("sn", ":bnext<Return>")
vim.keymap.set("n", "<leader>f", function()
vim.lsp.buf.format()
end)
vim.keymap.set("n", "<leader>F", function()
vim.lsp.buf.range_format()
end)
-- Quickfix list navigation
vim.keymap.set("n", "<C-k>", "<cmd>cnext<CR>zz")
vim.keymap.set("n", "<C-j>", "<cmd>cprev<CR>zz")
vim.keymap.set("n", "<leader>k", "<cmd>lnext<CR>zz")
vim.keymap.set("n", "<leader>j", "<cmd>lprev<CR>zz")

View file

@ -3,20 +3,33 @@ vim.opt.guicursor = ""
vim.opt.nu = true
vim.opt.relativenumber = true
vim.opt.tabstop = 2
vim.opt.softtabstop = 2
vim.opt.shiftwidth = 2
vim.opt.tabstop = 4
vim.opt.softtabstop = 4
vim.opt.shiftwidth = 4
vim.opt.expandtab = true
vim.opt.hlsearch = false
vim.opt.incsearch = true
vim.opt.smartindent = true
vim.opt.wrap = false
vim.opt.swapfile = false
vim.opt.backup = false
vim.opt.undodir = os.getenv("HOME") .. "/.vim/undodir"
vim.opt.undofile = true
vim.opt.hlsearch = false
vim.opt.incsearch = true
vim.opt.termguicolors = true
vim.opt.scrolloff = 8
vim.opt.signcolumn = "yes"
vim.opt.isfname:append("@-@")
vim.opt.updatetime = 50
vim.opt.colorcolumn = "80"
vim.opt.mouse = ""
vim.g.mapleader = " "
vim.g.netrw_browse_split = 0
vim.g.netrw_banner = 0
vim.g.netrw_winsize = 25