nvim: Completely rewrite nvim plugin configs

This commit is contained in:
histalek 2022-12-07 08:31:17 +01:00
parent 46353b43d7
commit eabb9593bf
No known key found for this signature in database
GPG key ID: ED1D6449704FDE03
23 changed files with 600 additions and 148 deletions

View file

@ -0,0 +1,2 @@
indent_type = "Spaces"
indent_width = 2

View file

@ -1,28 +1,26 @@
-- Basic vim options
vim.opt.clipboard = 'unnamedplus' -- System clipboard
vim.opt.cursorcolumn = true
vim.opt.cursorline = true
vim.opt.expandtab = true
vim.opt.hidden = true
vim.opt.history = 30
vim.opt.ignorecase = true
vim.opt.list = true
vim.opt.listchars = 'trail:•,tab:🡺 ,'
vim.opt.number = true
vim.opt.relativenumber = false
vim.opt.shiftwidth = 2
vim.opt.showmode = true
vim.opt.smartcase = true
vim.opt.swapfile = false
vim.opt.tabstop = 2
vim.opt.termguicolors = true
vim.opt.timeoutlen = 200
vim.opt.wrap = true
-- Load configuration from different lua files
-- Switch to <Space> as global mapleader and load keymapping config
vim.g.mapleader = ' '
require('keymap')
--- Basic options
require("core.options")
-- Require lua/plugins.lua config
require('plugins')
-- Keymap config
require("core.keymaps")
-- Plugin configs, setup has to come first
require("plugin-setup")
require("plugins.comment")
require("plugins.nvim-autopairs")
require("plugins.nvim-tree")
require("plugins.gitsigns")
require("plugins.treesitter")
require("plugins.lualine")
require("plugins.toggleterm")
require("plugins.autopairs")
require("plugins.which-key")
require("plugins.telescope")
require("plugins.nvim-cmp")
require("plugins.lsp.mason")
require("plugins.lsp.lspsaga")
require("plugins.lsp.lspconfig")
require("plugins.lsp.null-ls")
require("plugins.leap")

View file

@ -0,0 +1,23 @@
-- Convenience function. description parameter is used by `whichkey`
local function map(mode, keybind, command, description)
vim.api.nvim_set_keymap(mode, keybind, command, { desc = description, silent = true, noremap = true })
end
-- Switch to <space> as global mapleader
vim.g.mapleader = " "
-- Don't place single deleted characters in a buffer
map("n", "x", '"_x')
-- Increment and decrement numbers
map("n", "<leader>+", "<C-a>", "Increment number under cursor")
map("n", "<leader>-", "<C-x>", "Decrement number under cursor")
-- File explorer
map("n", "<leader>e", ":NvimTreeToggle<CR>", "Toggle file explorer")
-- telescope
map("n", "<leader>ff", "<cmd>Telescope find_files<cr>", "Find files within cwd") -- respects .gitignore
map("n", "<leader>fs", "<cmd>Telescope live_grep<cr>", "Find string in cwd")
map("n", "<leader>fb", "<cmd>Telescope buffers<cr>", "List open buffers in current neovim instance")
map("n", "<leader>fh", "<cmd>Telescope help_tags<cr>", "List available help tags")

View file

@ -0,0 +1,46 @@
local opt = vim.opt
-- clipboard
opt.clipboard = "unnamedplus" -- System clipboard
-- cursor
opt.cursorcolumn = true
opt.cursorline = true
-- linenumbers
opt.number = true
opt.relativenumber = false
-- tabs / indentation
opt.autoindent = true
opt.expandtab = true
opt.shiftwidth = 2
opt.tabstop = 2
opt.wrap = true
-- undo / buffers
opt.swapfile = false
opt.undofile = true
-- search
opt.ignorecase = true
opt.smartcase = true
-- appearance
opt.list = true
opt.listchars = "trail:•,tab:⭾ ,"
opt.showmode = true
opt.signcolumn = "yes"
opt.termguicolors = true
-- split windows
opt.splitright = true
opt.splitbelow = true
-- timeout (e.g. after which time 'which-key' shows up)
opt.timeoutlen = 400
-- other
opt.hidden = true
opt.history = 30
opt.backspace = "indent,eol,start"

View file

@ -1,8 +0,0 @@
-- Convenience function. description parameter is used by `whichkey`
local function map(mode, keybind, command, description)
vim.api.nvim_set_keymap(mode, keybind, command, { desc = description, silent = true, noremap = true })
end
map('n', '<leader>fr', ':History<CR>', 'Show recently used files')
map('n', '<leader>ff', ':e %:h/<C-d>', 'Show files in directory')

View file

@ -0,0 +1,106 @@
-- Autocommand to reload neovim plugins when this file gets saved
vim.cmd([[
augroup packer_user_config
autocmd!
autocmd BufWritePost plugin-setup.lua source <afile> | PackerCompile
augroup end
]])
-- Guard if packer can't be found
local status, packer = pcall(require, "packer")
if not status then
return
end
return packer.startup({
function(use)
use("wbthomason/packer.nvim")
-- Lua functions used by many plugins
use("nvim-lua/plenary.nvim")
-- Theming - one for all package. autocomplete :colorscheme to see what is available
use("RRethy/nvim-base16")
vim.cmd([[colorscheme base16-espresso]])
-- Completion and linting
use("williamboman/mason.nvim")
use("williamboman/mason-lspconfig.nvim")
-- Configuring lsp servers
use("neovim/nvim-lspconfig")
use("hrsh7th/cmp-nvim-lsp")
use({ "glepnir/lspsaga.nvim", branch = "main" })
use("jose-elias-alvarez/typescript.nvim")
use("onsails/lspkind.nvim")
use("jose-elias-alvarez/null-ls.nvim")
use("jayp0521/mason-null-ls.nvim")
-- Autopairs
use("windwp/nvim-autopairs")
-- git
use("lewis6991/gitsigns.nvim")
use("tpope/vim-surround")
-- Highlight colors
use({
"norcalli/nvim-colorizer.lua",
ft = { "css", "javascript", "vim", "html" },
config = [[require('colorizer').setup {'css', 'javascript', 'vim', 'html'}]],
})
-- Syntax highlighting
use({
"nvim-treesitter/nvim-treesitter",
run = function()
local ts_update = require("nvim-treesitter.install").update({ with_sync = true })
ts_update()
end,
})
-- Lualine statusline
use("nvim-lualine/lualine.nvim")
-- fuzzy finding with telescope
use({ "nvim-telescope/telescope-fzf-native.nvim", run = "make" })
use({ "nvim-telescope/telescope.nvim", branch = "0.1.x" })
-- autocompletion
use("hrsh7th/nvim-cmp")
use("hrsh7th/cmp-buffer")
use("hrsh7th/cmp-path")
-- snippets
use("L3MON4D3/LuaSnip")
use("saadparwaiz1/cmp_luasnip")
use("rafamadriz/friendly-snippets")
-- toggleterm
use({ "akinsho/toggleterm.nvim", tag = "v2.*" })
-- easier commenting
use("numToStr/Comment.nvim")
-- File explorer
use("nvim-tree/nvim-tree.lua")
use("nvim-tree/nvim-web-devicons")
-- Popup for available keybinds
use("folke/which-key.nvim")
-- Fast onscreen navigation
use("ggandor/leap.nvim")
if packer.bootstrap then
require("packer").sync()
end
end,
config = {
display = {
open_fn = require("packer.util").float,
},
},
})

View file

@ -1,115 +0,0 @@
-- Automatically run :PackerCompile whenever plugins.lua is updated
vim.api.nvim_create_autocmd('BufWritePost', {
group = vim.api.nvim_create_augroup('PACKER', { clear = true }),
pattern = 'plugins.lua',
command = 'source <afile> | PackerCompile',
})
vim.cmd [[packadd packer.nvim]]
return require('packer').startup({function(use)
use 'wbthomason/packer.nvim'
-- Theming - one for all package. autocomplete :colorscheme to see what is available
use 'RRethy/nvim-base16'
vim.cmd [[colorscheme base16-espresso]]
-- Pretty symbols
use 'kyazdani42/nvim-web-devicons'
-- Completion and linting
use 'neovim/nvim-lspconfig'
-- Autopairs
use 'windwp/nvim-autopairs'
require("nvim-autopairs").setup()
-- Highlight colors
use {
'norcalli/nvim-colorizer.lua',
ft = { 'css', 'javascript', 'vim', 'html' },
config = [[require('colorizer').setup {'css', 'javascript', 'vim', 'html'}]],
}
-- Syntax highlighting
use { 'nvim-treesitter/nvim-treesitter', run = ':TSUpdate' }
require'nvim-treesitter.configs'.setup {
ensure_installed = {
"bash",
"c",
"css",
"dockerfile",
"go",
"html",
"javascript",
"json",
"latex",
"lua",
"make",
"python",
"rust",
"vue",
"yaml",
},
sync_install = false,
auto_install = true, -- Recommendation: set to false if you don't have `tree-sitter` CLI installed locally
highlight = {
enable = true,
-- disable = { "c", "rust" },
},
}
-- Lualine statusline
use 'nvim-lualine/lualine.nvim'
require('lualine').setup {
options = {
icon_enabled = true,
theme = 'auto',
}
}
-- fzf
use 'junegunn/fzf'
use 'junegunn/fzf.vim'
-- toggleterm
use { "akinsho/toggleterm.nvim", tag = 'v2.*' }
require("toggleterm").setup{
open_mapping = [[<c-\>]],
hide_numbers = true,
persist_size = true,
persist_mode = true,
direction = 'horizontal', -- 'float',
close_on_exit = true,
shell = vim.o.shell,
auto_scroll = true,
float_opts = {
border = 'curved',
},
winbar = {
enabled = false,
name_formatter = function(term)
return term.name
end
},
}
-- Popup for available keybinds
use {
"folke/which-key.nvim",
config = function()
require("which-key").setup{
window = {
border = "double",
position = "bottom",
},
}
end
}
end,
config = {
display = {
open_fn = require('packer.util').float,
}
}})

View file

@ -0,0 +1,23 @@
local status, autopairs = pcall(require, "nvim-autopairs")
if not status then
return
end
autopairs.setup({
check_ts = true,
ts_config = {
lua = { "string" },
},
})
local cmp_autopairs_setup, cmp_autopairs = pcall(require, "nvim-autopairs.completion.cmp")
if not cmp_autopairs_setup then
return
end
local cmp_setup, cmp = pcall(require, "cmp")
if not cmp_setup then
return
end
cmp.event:on("confirm_done", cmp_autopairs.on_confirm_done())

View file

@ -0,0 +1,6 @@
local status, comment = pcall(require, "Comment")
if not status then
return
end
comment.setup()

View file

@ -0,0 +1,6 @@
local status, gitsigns = pcall(require, "gitsigns")
if not status then
return
end
gitsigns.setup()

View file

@ -0,0 +1,6 @@
local status, leap = pcall(require, "leap")
if not status then
return
end
leap.add_default_mappings()

View file

@ -0,0 +1,94 @@
local status_lspconfig, lspconfig = pcall(require, "lspconfig")
if not status_lspconfig then
return
end
local status_cmp_nvim_lsp, cmp_nvim_lsp = pcall(require, "cmp_nvim_lsp")
if not status_cmp_nvim_lsp then
return
end
local status_typescript, typescript = pcall(require, "typescript")
if not status_typescript then
return
end
local keymap = vim.keymap
-- enable keybinds only for when lsp server available
local on_attach = function(client, bufnr)
local opts = { noremap = true, silent = true, buffer = bufnr }
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
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
local capabilities = cmp_nvim_lsp.default_capabilities()
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
lspconfig["html"].setup({
capabilities = capabilities,
on_attach = on_attach,
})
typescript.setup({
server = {
capabilities = capabilities,
on_attach = on_attach,
},
})
lspconfig["cssls"].setup({
capabilities = capabilities,
on_attach = on_attach,
})
lspconfig["tailwindcss"].setup({
capabilities = capabilities,
on_attach = on_attach,
})
lspconfig["emmet_ls"].setup({
capabilities = capabilities,
on_attach = on_attach,
filetypes = { "html", "typescriptreact", "javascriptreact", "css", "sass", "scss", "less", "svelte" },
})
lspconfig["sumneko_lua"].setup({
capabilities = capabilities,
on_attach = on_attach,
settings = {
Lua = {
diagnostics = {
globals = { "vim" },
},
workspace = {
library = {
[vim.fn.expand("$VIMRUNTIME/lua")] = true,
[vim.fn.stdpath("config") .. "/lua"] = true,
},
},
},
},
})

View file

@ -0,0 +1,14 @@
local status_saga, saga = pcall(require, "lspsaga")
if not status_saga then
return
end
saga.init_lsp_saga({
move_in_saga = { prev = "<C-k>", next = "<C-j>" },
finder_action_keys = {
open = "<CR>",
},
definition_action_keys = {
edit = "<CR>",
},
})

View file

@ -0,0 +1,37 @@
local status_mason, mason = pcall(require, "mason")
if not status_mason then
return
end
local status_lspconfig, mason_lspconfig = pcall(require, "mason-lspconfig")
if not status_lspconfig then
return
end
local status_null_ls, mason_null_ls = pcall(require, "mason-null-ls")
if not status_null_ls then
return
end
mason.setup()
mason_lspconfig.setup({
ensure_installed = {
"tsserver",
"html",
"cssls",
"tailwindcss",
"sumneko_lua",
"emmet_ls",
},
automatic_installation = true,
})
mason_null_ls.setup({
ensure_installed = {
"prettier",
"stylua",
"eslint_d",
},
automatic_installation = true,
})

View file

@ -0,0 +1,38 @@
local status, null_ls = pcall(require, "null-ls")
if not status 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,
diagnostics.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,
})

View file

@ -0,0 +1,11 @@
local status, lualine = pcall(require, "lualine")
if not status then
return
end
lualine.setup({
options = {
icon_enabled = true,
theme = "auto",
},
})

View file

@ -0,0 +1,25 @@
local status, autopairs = pcall(require, "nvim-autopairs")
if not status then
return
end
autopairs.setup({
check_ts = true,
ts_config = {
lua = { "string" },
javascript = { "template_string" },
java = false,
},
})
local cmp_autopairs_status, cmp_autopairs = pcall(require, "nvim-autopairs.completion.cmp")
if not cmp_autopairs_status then
return
end
local cmp_status, cmp = pcall(require, "cmp")
if not cmp_status then
return
end
cmp.event:on("confirm_done", cmp_autopairs.on_confirm_done())

View file

@ -0,0 +1,45 @@
local status_cmp, cmp = pcall(require, "cmp")
if not status_cmp then
return
end
local status_luasnip, luasnip = pcall(require, "luasnip")
if not status_luasnip then
return
end
local status_lspkind, lspkind = pcall(require, "lspkind")
if not status_lspkind then
return
end
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(),
["<C-j>"] = cmp.mapping.select_next_item(),
["<C-Space>"] = cmp.mapping.complete(),
["<C-e>"] = cmp.mapping.abort(),
["<CR>"] = cmp.mapping.confirm({ select = false }),
}),
sources = cmp.config.sources({
{ name = "nvim_lsp" },
{ name = "luasnip" },
{ name = "buffer" },
{ name = "path" },
}),
formatting = {
format = lspkind.cmp_format({
maxwidth = 50,
ellipsis_char = "...",
}),
},
})

View file

@ -0,0 +1,10 @@
local status, nvimtree = pcall(require, "nvim-tree")
if not status then
return
end
-- recommended settings by nvim-tree documentation
vim.g.loaded_netrw = 1
vim.g.loaded_netrwPlugin = 1
nvimtree.setup()

View file

@ -0,0 +1,21 @@
local status_telescope, telescope = pcall(require, "telescope")
if not status_telescope then
return
end
local status_actions, actions = pcall(require, "telescope.actions")
if not status_actions 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,
},
},
},
})

View file

@ -0,0 +1,24 @@
local status, toggleterm = pcall(require, "toggleterm")
if not status then
return
end
toggleterm.setup({
open_mapping = [[<c-\>]],
hide_numbers = true,
persist_size = true,
persist_mode = true,
direction = "float",
close_on_exit = true,
shell = vim.o.shell,
auto_scroll = true,
float_opts = {
border = "curved",
},
winbar = {
enabled = false,
name_formatter = function(term)
return term.name
end,
},
})

View file

@ -0,0 +1,29 @@
local status, treesitter = pcall(require, "nvim-treesitter.configs")
if not status then
return
end
treesitter.setup({
ensure_installed = {
"bash",
"c",
"css",
"dockerfile",
"go",
"html",
"javascript",
"json",
"latex",
"lua",
"make",
"python",
"rust",
"vue",
"yaml",
},
sync_install = false,
auto_install = true, -- Recommendation: set to false if you don't have `tree-sitter` CLI installed locally
highlight = { enable = true },
indent = { enable = true },
autotag = { enabled = true },
})

View file

@ -0,0 +1,11 @@
local status, whichkey = pcall(require, "which-key")
if not status then
return
end
whichkey.setup({
window = {
border = "double",
position = "bottom",
},
})