443 lines
13 KiB
Lua
443 lines
13 KiB
Lua
local fn = vim.fn
|
|
local opt = vim.opt
|
|
local map = vim.api.nvim_set_keymap
|
|
local buf_map = vim.api.nvim_buf_set_keymap
|
|
local unmap = vim.api.nvim_del_keymap
|
|
local autocmd = vim.api.nvim_create_autocmd
|
|
|
|
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', 'https://github.com/wbthomason/packer.nvim', install_path })
|
|
vim.cmd 'packadd packer.nvim'
|
|
end
|
|
|
|
require('packer').startup(function()
|
|
use 'wbthomason/packer.nvim' -- Package Manager
|
|
use 'nvim-lua/plenary.nvim' -- Lua Library
|
|
use 'neovim/nvim-lspconfig' -- Language Server Config
|
|
use {
|
|
'hrsh7th/nvim-cmp', -- Completion
|
|
requires = {
|
|
'hrsh7th/cmp-buffer', -- Completion source buffer
|
|
'hrsh7th/cmp-nvim-lsp', -- Completion source LSP
|
|
'hrsh7th/cmp-path', -- Completion source filepaths
|
|
'hrsh7th/cmp-cmdline', -- Completion source for commandline
|
|
'saadparwaiz1/cmp_luasnip', -- Completion source snippets
|
|
'ray-x/lsp_signature.nvim' -- Signature when typing
|
|
}
|
|
}
|
|
use { 'L3MON4D3/LuaSnip' } -- Snippets
|
|
use {
|
|
'nvim-treesitter/nvim-treesitter', -- Syntax Highlighting
|
|
run = ':TSUpdate'
|
|
}
|
|
use 'tpope/vim-commentary' -- Commentary
|
|
use 'tpope/vim-surround' -- Surrounding
|
|
use 'tpope/vim-repeat' -- Repeat Surrounding
|
|
use 'tpope/vim-sleuth' -- Detect Spacing
|
|
use 'kdheepak/lazygit.nvim' -- Git Client
|
|
use "tversteeg/registers.nvim" -- Preview Registers
|
|
use 'windwp/nvim-autopairs' -- Autopairs
|
|
use 'windwp/nvim-ts-autotag' -- HTML Autopairs
|
|
use 'nvim-telescope/telescope.nvim' -- Fuzzy Finder
|
|
use 'tamago324/lir.nvim' -- Filebrowser
|
|
use 'jakewvincent/mkdnflow.nvim' -- Notetaking
|
|
use 'norcalli/nvim-colorizer.lua' -- render Color Codes
|
|
use 'aklt/plantuml-syntax' -- Plantuml Syntax, till treesitter supports Plantuml
|
|
use 'ggandor/leap.nvim' -- Jump around in file
|
|
use 'mfussenegger/nvim-dap' -- Debugger Adapter Protocol
|
|
use 'rcarriga/nvim-dap-ui' -- UI for DAP
|
|
use 'nvim-neotest/nvim-nio' -- for nvim-dap-ui
|
|
use 'phha/zenburn.nvim' -- zenburn coloursheme
|
|
use 'rmagatti/auto-session' -- session management
|
|
end)
|
|
|
|
-- General Editor Settings
|
|
require("zenburn").setup()
|
|
|
|
vim.g.mapleader = ","
|
|
opt.mouse = "nv"
|
|
opt.pastetoggle = "ZP"
|
|
|
|
opt.number = true
|
|
opt.relativenumber = true
|
|
|
|
opt.statusline = ' %f %r %m%=%y %{&fileencoding?&fileencoding:&encoding}[%{&fileformat}] %p%% %l:%c '
|
|
|
|
opt.completeopt = 'menuone,noinsert,noselect'
|
|
|
|
map('n', '<Space>w', '<cmd>w<cr>', { noremap = true })
|
|
map('n', '<Space>q', '<cmd>wq<cr>', { noremap = true })
|
|
map('n', '<Esc><Esc>', '<cmd>let @/ = ""<cr>', { noremap = true })
|
|
|
|
-- fix interpreting C-I as Tab
|
|
map('n', '<C-I>', '<C-I>', { noremap = true })
|
|
|
|
-- Splits
|
|
map('n', '<C-h>', '<C-w>h', { noremap = true })
|
|
map('n', '<C-j>', '<C-w>j', { noremap = true })
|
|
map('n', '<C-k>', '<C-w>k', { noremap = true })
|
|
map('n', '<C-l>', '<C-w>l', { noremap = true })
|
|
|
|
opt.splitbelow = true
|
|
opt.splitright = true
|
|
|
|
-- Autocommands
|
|
autocmd({ 'BufNewFile', 'BufRead' }, {
|
|
desc = 'When editing compileable documents, register commands for live preview',
|
|
pattern = { '*.md', '*.tex', '*.puml' },
|
|
callback = function()
|
|
buf_map(0, 'n', '<leader>p', '<cmd>lua require("compileDoc").open_document_preview()<CR>', { noremap = true })
|
|
buf_map(0, 'n', '<leader>P', '<cmd>lua require("compileDoc").close_document_preview()<CR>', { noremap = true })
|
|
end
|
|
})
|
|
|
|
vim.cmd("au BufRead *.yaml,*.yml if search('hosts:\\|tasks:\\|ansible.builtin', 'nw') | set ft=yaml.ansible | endif")
|
|
|
|
-- Spellcheck
|
|
_G.enable_spell = function(lang)
|
|
vim.bo.spelllang = lang
|
|
|
|
if lang ~= "" then
|
|
vim.wo.spell = true
|
|
|
|
map('n', 'ff', ']s', { noremap = true })
|
|
map('n', 'fF', '[s', { noremap = true })
|
|
map('n', 'fa', 'zg', { noremap = true })
|
|
map('n', 'fn', 'z=', { noremap = true })
|
|
map('n', 'fd', 'zuw=', { noremap = true })
|
|
print(lang .. " spellcheck enabled")
|
|
else
|
|
vim.wo.spell = false
|
|
|
|
unmap('n', 'ff')
|
|
unmap('n', 'fF')
|
|
unmap('n', 'fa')
|
|
unmap('n', 'fn')
|
|
unmap('n', 'fd')
|
|
print("spellcheck disabled")
|
|
end
|
|
|
|
return vim.api.nvim_replace_termcodes('<cr>', true, true, true)
|
|
end
|
|
|
|
map('n', 'ZD', 'v:lua.enable_spell("de")', { expr = true, silent = true })
|
|
map('n', 'ZE', 'v:lua.enable_spell("en")', { expr = true, silent = true })
|
|
map('n', 'ZS', 'v:lua.enable_spell("")', { expr = true, silent = true })
|
|
|
|
-- LSP
|
|
local lsp = require('lspconfig')
|
|
|
|
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 }
|
|
|
|
-- See `:help vim.lsp.*` for documentation on any of the below functions
|
|
buf_set_keymap('n', 'gd', '<cmd>lua vim.lsp.buf.definition()<CR>', opts)
|
|
buf_set_keymap('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', opts)
|
|
buf_set_keymap('n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>', opts)
|
|
buf_set_keymap('n', 'K', '<cmd>lua vim.lsp.buf.hover()<CR>', opts)
|
|
buf_set_keymap('n', '<space>rn', '<cmd>lua vim.lsp.buf.rename()<CR>', opts)
|
|
buf_set_keymap('n', '<space>e', '<cmd>lua vim.diagnostic.open_float()<CR>', opts)
|
|
buf_set_keymap('n', '<space>ca', '<cmd>lua vim.lsp.buf.code_action()<CR>', opts)
|
|
vim.keymap.set('n', '<space>f', function() vim.lsp.buf.format { async = true } end, opts)
|
|
|
|
-- Signature
|
|
require('lsp_signature').on_attach({
|
|
hint_enable = false
|
|
}, bufnr)
|
|
end
|
|
|
|
local capabilities = require("cmp_nvim_lsp").default_capabilities()
|
|
|
|
local servers = { 'rust_analyzer', 'texlab', 'pyright', 'tsserver', 'ccls', 'html', 'yamlls', 'ansiblels', 'hls', 'cssls', 'eslint' }
|
|
for _, server in ipairs(servers) do
|
|
lsp[server].setup {
|
|
on_attach = on_attach,
|
|
capabilities = capabilities,
|
|
}
|
|
end
|
|
|
|
lsp.csharp_ls.setup {
|
|
on_attach = on_attach,
|
|
capabilities = capabilities,
|
|
cmd = { '/home/max/.dotnet/tools/csharp-ls' }
|
|
}
|
|
|
|
lsp.lua_ls.setup {
|
|
on_attach = on_attach,
|
|
capabilities = capabilities,
|
|
settings = {
|
|
Lua = {
|
|
runtime = {
|
|
-- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim)
|
|
version = 'LuaJIT',
|
|
},
|
|
diagnostics = {
|
|
-- Get the language server to recognize the `vim` global
|
|
globals = { 'vim' },
|
|
},
|
|
workspace = {
|
|
-- Make the server aware of Neovim runtime files
|
|
library = vim.api.nvim_get_runtime_file("", true),
|
|
},
|
|
-- Do not send telemetry data containing a randomized but unique identifier
|
|
telemetry = {
|
|
enable = false,
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
-- Autopairs
|
|
require 'nvim-ts-autotag'.setup()
|
|
require 'nvim-autopairs'.setup {}
|
|
|
|
-- Snippets
|
|
local ls = require('luasnip')
|
|
local types = require('luasnip.util.types')
|
|
|
|
ls.config.set_config({
|
|
history = true,
|
|
updateevents = "TextChanged,TextChangedI",
|
|
ext_opts = {
|
|
[types.choiceNode] = {
|
|
active = {
|
|
virt_text = { { "●", "Function" } }
|
|
}
|
|
},
|
|
[types.insertNode] = {
|
|
active = {
|
|
virt_text = { { "●", "Comment" } }
|
|
}
|
|
}
|
|
},
|
|
})
|
|
|
|
require("luasnip.loaders.from_lua").load({ paths = "~/.config/nvim/lua/snippets" })
|
|
|
|
-- Completion
|
|
local cmp = require('cmp')
|
|
cmp.setup {
|
|
mapping = {
|
|
['<C-p>'] = cmp.mapping.select_prev_item(),
|
|
['<C-n>'] = cmp.mapping.select_next_item(),
|
|
['<C-u>'] = cmp.mapping.scroll_docs(-4),
|
|
['<C-d>'] = cmp.mapping.scroll_docs(4),
|
|
['<C-x>'] = cmp.mapping.abort(),
|
|
['<CR>'] = cmp.mapping.confirm({ behavior = cmp.ConfirmBehavior.Insert, select = false }),
|
|
['<C-Space>'] = cmp.mapping.confirm({ behavior = cmp.ConfirmBehavior.Insert, select = true }),
|
|
["<Tab>"] = cmp.mapping(function(fallback)
|
|
if ls.expand_or_locally_jumpable() then
|
|
ls.expand_or_jump()
|
|
else
|
|
fallback()
|
|
end
|
|
end, { "i", "s" }),
|
|
["<S-Tab>"] = cmp.mapping(function(fallback)
|
|
if ls.locally_jumpable(-1) then
|
|
ls.jump(-1)
|
|
else
|
|
fallback()
|
|
end
|
|
end, { "i", "s" }),
|
|
['<C-e>'] = cmp.mapping(function(fallback)
|
|
if ls.choice_active() then
|
|
ls.change_choice(1)
|
|
else
|
|
fallback()
|
|
end
|
|
end, { 'i', 's' })
|
|
},
|
|
snippet = {
|
|
expand = function(args)
|
|
require('luasnip').lsp_expand(args.body)
|
|
end
|
|
},
|
|
sources = {
|
|
{ name = 'luasnip' },
|
|
{ name = 'nvim_lsp' },
|
|
{ name = 'path' },
|
|
{ name = 'buffer' },
|
|
}
|
|
}
|
|
|
|
cmp.setup.cmdline({ '/', '?' }, {
|
|
mapping = cmp.mapping.preset.cmdline(),
|
|
sources = {
|
|
{ name = 'buffer' }
|
|
}
|
|
})
|
|
|
|
cmp.setup.cmdline(':', {
|
|
mapping = cmp.mapping.preset.cmdline(),
|
|
sources = cmp.config.sources({
|
|
{ name = 'path' }
|
|
}, {
|
|
{ name = 'cmdline' }
|
|
})
|
|
})
|
|
|
|
-- Treesitter
|
|
require('nvim-treesitter.configs').setup {
|
|
ensure_installed = 'all',
|
|
highlight = {
|
|
enable = true,
|
|
additional_vim_regex_highlighting = false,
|
|
},
|
|
autotag = {
|
|
enable = true
|
|
}
|
|
}
|
|
|
|
-- Telescope
|
|
map('n', '<Leader>ff', '<cmd>lua require("telescope.builtin").find_files()<cr>', { noremap = true })
|
|
map('n', '<leader>fg', '<cmd>lua require("telescope.builtin").live_grep()<cr>', { noremap = true })
|
|
map('n', '<leader>fb', '<cmd>lua require("telescope.builtin").buffers()<cr>', { noremap = true })
|
|
map('n', '<leader>fh', '<cmd>lua require("telescope.builtin").help_tags()<cr>', { noremap = true })
|
|
|
|
-- Vimwiki
|
|
require('mkdnflow').setup({
|
|
modules = {
|
|
bib = false,
|
|
folds = false,
|
|
},
|
|
mappings = {
|
|
MkdnEnter = { { 'i', 'n', 'v' }, '<CR>' },
|
|
MkdnCreateLinkFromClipboard = {{'n', 'v'}, '<leader>l'},
|
|
},
|
|
perspective = {
|
|
priority = 'current',
|
|
},
|
|
links = {
|
|
transform_explicit = function(text)
|
|
return string.lower(text:gsub(' ', ''))
|
|
end
|
|
},
|
|
new_file_template = {
|
|
template = [[
|
|
# {{ title }}
|
|
]],
|
|
}
|
|
})
|
|
|
|
autocmd({ 'BufRead', 'BufNewFile' }, {
|
|
desc = 'Set note taking settings for nvim in wiki directory',
|
|
pattern = { '*/dokumente/wiki/**' },
|
|
callback = function()
|
|
vim.cmd('set awa')
|
|
vim.wo.conceallevel = 2
|
|
map('n', '<Leader>wf', '<cmd>lua require("telescope_customs").find_wiki()<cr>', { noremap = true })
|
|
map('n', '<Leader>wg', '<cmd>lua require("telescope_customs").grep_wiki()<cr>', { noremap = true })
|
|
end
|
|
})
|
|
|
|
-- Lir Filebrowser
|
|
local actions = require('lir.actions')
|
|
|
|
require('lir').setup {
|
|
devicons_enable = false,
|
|
mappings = {
|
|
['l'] = actions.edit,
|
|
['<C-s>'] = actions.split,
|
|
['<C-v>'] = actions.vsplit,
|
|
['<C-t>'] = actions.tabedit,
|
|
|
|
['h'] = actions.up,
|
|
['q'] = actions.quit,
|
|
|
|
['nd'] = actions.mkdir,
|
|
['nf'] = actions.newfile,
|
|
['R'] = actions.rename,
|
|
['@'] = actions.cd,
|
|
['Y'] = actions.yank_path,
|
|
['.'] = actions.toggle_show_hidden,
|
|
['x'] = actions.delete,
|
|
},
|
|
float = {
|
|
winblend = 0,
|
|
win_opts = function()
|
|
local width = math.floor(vim.o.columns * 0.6)
|
|
local height = math.floor(vim.o.lines * 0.6)
|
|
return {
|
|
width = width,
|
|
height = height,
|
|
row = 10,
|
|
col = math.floor((vim.o.columns - width) / 2),
|
|
}
|
|
end,
|
|
},
|
|
hide_cursor = true
|
|
}
|
|
|
|
map('n', '<C-n>', '<cmd>lua require("lir.float").toggle()<cr>', { noremap = true })
|
|
vim.g.loaded_netrw = 1
|
|
vim.g.loaded_netrwPlugin = 1
|
|
|
|
-- Colorizer
|
|
require('colorizer').setup({
|
|
'*';
|
|
}, {
|
|
RGB = true; -- #RGB hex codes
|
|
RRGGBB = true; -- #RRGGBB hex codes
|
|
names = false; -- "Name" codes like Blue
|
|
RRGGBBAA = true; -- #RRGGBBAA hex codes
|
|
rgb_fn = true; -- CSS rgb() and rgba() functions
|
|
hsl_fn = true; -- CSS hsl() and hsla() functions
|
|
css = false; -- Enable all CSS features: rgb_fn, hsl_fn, names, RGB, RRGGBB
|
|
css_fn = false; -- Enable all CSS *functions*: rgb_fn, hsl_fn
|
|
mode = 'background'; -- Set the display mode.
|
|
})
|
|
|
|
-- Leap
|
|
require('leap').add_default_mappings()
|
|
|
|
-- Debugger Adapter Protocol
|
|
local dap = require('dap')
|
|
|
|
dap.adapters.codelldb = {
|
|
type = 'server',
|
|
port = "${port}",
|
|
executable = {
|
|
command = '/usr/bin/codelldb',
|
|
args = { "--port", "${port}" },
|
|
}
|
|
}
|
|
|
|
dap.configurations.rust = {
|
|
{
|
|
name = "Launch file",
|
|
type = "codelldb",
|
|
request = "launch",
|
|
program = function()
|
|
return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/', 'file')
|
|
end,
|
|
cwd = '${workspaceFolder}',
|
|
stopOnEntry = false,
|
|
},
|
|
}
|
|
|
|
map('n', '<Leader>dc', '<cmd>lua require"dap".continue()<cr>', { noremap = true })
|
|
map('n', '<Leader>db', '<cmd>lua require"dap".toggle_breakpoint()<cr>', { noremap = true })
|
|
map('n', '<Leader>do', '<cmd>lua require"dap".step_over()<cr>', { noremap = true })
|
|
map('n', '<Leader>di', '<cmd>lua require"dap".step_into()<cr>', { noremap = true })
|
|
|
|
require("dapui").setup()
|
|
map('n', '<Leader>dd', '<cmd>lua require"dapui".toggle()<cr>', { noremap = true })
|
|
|
|
-- registers preview
|
|
require("registers").setup()
|
|
|
|
-- Lazygit
|
|
map('n', '<Leader>g', '<cmd>LazyGit<cr>', { noremap = true })
|
|
|
|
-- Session
|
|
require("auto-session").setup {
|
|
log_level = "error"
|
|
}
|
|
|
|
opt.sessionoptions = "blank,buffers,curdir,folds,help,tabpages,winsize,winpos,terminal,localoptions"
|