neovim-config/init.lua

200 lines
6.2 KiB
Lua
Raw Permalink Normal View History

2024-01-08 17:56:30 +01:00
-- External tools:
-- ripgrep https://github.com/BurntSushi/ripgrep
-- bat https://github.com/sharkdp/bat
-- fd https://github.com/sharkdp/fd
--
-- Debian: apt install ripgrep bat fdfind
-- ln -s $(which fdfind) /home/timo/bin/fd
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
-- bootstrap lazy if it is not installed
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", lazypath })
end
vim.opt.rtp:prepend(vim.env.LAZY or lazypath)
-- remap leader
vim.g.mapleader = ' '
vim.g.maplocalleader = ' '
vim.keymap.set({ 'n', 'v' }, '<Space>', '<Nop>')
-- plugins
require("lazy").setup({
{ "chriskempson/base16-vim", lazy = true },
{ "nvim-tree/nvim-web-devicons", lazy = true },
{ "catppuccin/nvim", lazy = true, name = "catppuccin", priority=1000 },
{ "akinsho/toggleterm.nvim", event = "VeryLazy", version = "*",
opts = {
size = 10,
open_mapping = "<c-s>",
}
},
{
'nvim-lualine/lualine.nvim',
dependencies = { 'nvim-tree/nvim-web-devicons' }
},
{'akinsho/bufferline.nvim', version = "*", dependencies = 'nvim-tree/nvim-web-devicons'},
{ 'echasnovski/mini.nvim', version = false },
{ 'echasnovski/mini.nvim', version = false },
{ "lukas-reineke/indent-blankline.nvim", main = "ibl", opts = {} },
{ "neovim/nvim-lspconfig",
dependencies = {
"williamboman/mason.nvim",
"williamboman/mason-lspconfig.nvim",
},
config = function()
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities)
require('mason').setup()
local mason_lspconfig = require 'mason-lspconfig'
mason_lspconfig.setup {
ensure_installed = { "pyright" }
}
require("lspconfig").pyright.setup {
capabilities = capabilities,
}
end
},
{ "hrsh7th/nvim-cmp",
dependencies = {
"hrsh7th/cmp-nvim-lsp",
"L3MON4D3/LuaSnip",
"saadparwaiz1/cmp_luasnip"
},
config = function()
local has_words_before = function()
unpack = unpack or table.unpack
local line, col = unpack(vim.api.nvim_win_get_cursor(0))
return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil
end
local cmp = require('cmp')
local luasnip = require('luasnip')
cmp.setup({
snippet = {
expand = function(args)
luasnip.lsp_expand(args.body)
end
},
completion = {
autocomplete = false
},
mapping = cmp.mapping.preset.insert ({
["<Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
elseif has_words_before() then
cmp.complete()
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" }),
["<c-e>"] = cmp.mapping.abort(),
["<CR>"] = cmp.mapping.confirm({ select=true }),
}),
sources = {
{ name = "nvim_lsp" },
{ name = "luasnip" },
}
})
end
},
{ "nvim-treesitter/nvim-treesitter", version = false,
build = function()
require("nvim-treesitter.install").update({ with_sync = true })
end,
config = function()
require("nvim-treesitter.configs").setup({
ensure_installed = { "c", "lua", "vim", "vimdoc", "query", "python", "javascript" },
auto_install = false,
highlight = { enable = true, additional_vim_regex_highlighting = false },
incremental_selection = {
enable = true,
keymaps = {
init_selection = "<C-n>",
node_incremental = "<C-n>",
scope_incremental = "<C-s>",
node_decremental = "<C-m>",
}
}
})
end
},
{ "nvim-telescope/telescope.nvim", cmd = "Telescope", version = false,
dependencies = { "nvim-lua/plenary.nvim" },
keys = {
{ "<leader>sf", "<cmd>Telescope git_files<cr>", desc = "Find Files (root dir)" },
{ "<leader><space>", "<cmd>Telescope buffers<cr>", desc = "Find Buffers" },
{ "<leader>sg", "<cmd>Telescope live_grep<cr>", desc = "Search Project" },
{ "<leader>ss", "<cmd>Telescope lsp_document_symbols<cr>", desc = "Search Document Symbols" },
{ "<leader>sw", "<cmd>Telescope lsp_dynamic_workspace_symbols<cr>", desc = "Search Workspace Symbols" },
},
opts = {
extensions = {
fzf = {
fuzzy = true,
override_generic_sorter = true,
override_file_sorter = true,
case_mode = "smart_case"
}
}
}
},
{ "nvim-telescope/telescope-fzf-native.nvim",
build = "make",
config = function()
require('telescope').load_extension('fzf')
end
},
{ "jose-elias-alvarez/null-ls.nvim",
dependencies = { "nvim-lua/plenary.nvim" },
config = function()
local null_ls = require("null-ls")
null_ls.setup({
sources = {
null_ls.builtins.diagnostics.ruff,
null_ls.builtins.formatting.black,
}
})
end
},
})
-- theme
vim.cmd [[colorscheme catppuccin]]
-- LSP
vim.keymap.set('n', '<leader>rn', vim.lsp.buf.rename, {desc = 'Rename Symbol'})
vim.keymap.set('n', '<leader>gd', vim.lsp.buf.definition, {desc = 'Goto Definition'})
vim.keymap.set('n', '<leader>ca', vim.lsp.buf.code_action, {desc = 'Code Action'})
vim.keymap.set('n', 'K', vim.lsp.buf.hover, {desc = 'Hover Documentation'})
vim.keymap.set('n', '<leader>ff', vim.lsp.buf.format, {desc = 'Format Code'})