local fn = vim.fn local opt = vim.opt local map = vim.api.nvim_set_keymap local unmap = vim.api.nvim_del_keymap local augroup = vim.api.nvim_create_augroup 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 '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 "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 'davidgranstrom/nvim-markdown-preview' -- Markdown Livepreview use 'xuhdev/vim-latex-live-preview' -- Latex Livepreview use 'norcalli/nvim-colorizer.lua' -- render Color Codes use 'aklt/plantuml-syntax' -- Plantuml Syntax, till treesitter supports Plantuml use { 'rust-sailfish/sailfish', -- Sailfish Syntax rtp = 'syntax/vim' } end) -- General Editor Settings -- vim.g.colors_name = "zenburn" opt.termguicolors = true vim.cmd('colorscheme zenburn') 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', 'ZT', 'w', { noremap = true }) map('n', 'ZO', '!compiler %', { noremap = true }) map('n', 'ZK', '!kdeconnect-cli -d 3993d52f1018a472 --share %', { noremap = true }) map('n', '/', 'let @/ = ""', { noremap = true }) map('n', 'plp', '!feh %:s?pu?png? &', {noremap = true}) -- Splits map('n', '', 'h', { noremap = true }) map('n', '', 'j', { noremap = true }) map('n', '', 'k', { noremap = true }) map('n', '', 'l', { noremap = true }) opt.splitbelow = true opt.splitright = true -- Identation with autocmd augroup('programming', {}) autocmd('FileType', { group = 'programming', desc = 'Set identation to two spaces for filetypes in {pattern}', pattern = { 'lua', 'html', 'css', 'scss', 'sass', 'less', 'htmldjango', 'sailfish', 'typescript', 'typescriptreact', 'javascript', 'javascriptreact', 'haskell' }, command = 'setlocal ts=2 sw=2 sts=2 expandtab' }) autocmd('FileType', { group = 'programming', desc = 'Set identation to one tab for filetypes in {pattern}', pattern = { 'python' }, command = 'setlocal ts=4 sw=4 sts=4 expandtab' }) autocmd({ 'BufNewFile', 'BufRead' }, { group = 'programming', desc = 'Set Filetype to sailfish for .stpl files', pattern = { '*stpl' }, command = 'setlocal filetype=sailfish' }) 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('', 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', 'lua vim.lsp.buf.definition()', opts) buf_set_keymap('n', 'gi', 'lua vim.lsp.buf.implementation()', opts) buf_set_keymap('n', 'gr', 'lua vim.lsp.buf.references()', opts) buf_set_keymap('n', 'K', 'lua vim.lsp.buf.hover()', opts) buf_set_keymap('n', 'rn', 'lua vim.lsp.buf.rename()', opts) buf_set_keymap('n', 'e', 'lua vim.diagnostic.open_float()', opts) buf_set_keymap('n', 'ca', 'lua vim.lsp.buf.code_action()', opts) vim.keymap.set('n', 'f', function() vim.lsp.buf.format { async = true } end, opts) -- Signature require('lsp_signature').on_attach({ hint_enable = false }, bufnr) end local runtime_path = vim.split(package.path, ';') table.insert(runtime_path, "lua/?.lua") table.insert(runtime_path, "lua/?/init.lua") lsp.sumneko_lua.setup { cmd = {"lua-language-server"}, on_attach = on_attach, settings = { Lua = { runtime = { version = 'LuaJIT', path = runtime_path, }, diagnostics = { globals = {'vim'}, }, workspace = { library = vim.api.nvim_get_runtime_file("", true), }, telemetry = { enable = false, }, }, } } lsp.rust_analyzer.setup { on_attach = on_attach, } lsp.texlab.setup { on_attach = on_attach, } lsp.pyright.setup { on_attach = on_attach, } lsp.tsserver.setup{ on_attach = on_attach, } lsp.ccls.setup { on_attach = on_attach, } local capabilities = vim.lsp.protocol.make_client_capabilities() capabilities.textDocument.completion.completionItem.snippetSupport = true lsp.cssls.setup { capabilities = capabilities, on_attach = on_attach, } lsp.html.setup { capabilities = capabilities, on_attach = on_attach, } lsp.yamlls.setup { capabilities = capabilities, on_attach = on_attach, } lsp.ansiblels.setup { capabilities = capabilities, on_attach = on_attach, } lsp.csharp_ls.setup { capabilities = capabilities, on_attach = on_attach, } lsp.hls.setup { capabilities = capabilities, on_attach = on_attach, } -- Autopairs require'nvim-ts-autotag'.setup() require'nvim-autopairs'.setup{} -- Completion local cmp = require('cmp') cmp.setup { mapping = { [''] = cmp.mapping.select_prev_item(), [''] = cmp.mapping.select_next_item(), [''] = cmp.mapping.scroll_docs(-4), [''] = cmp.mapping.scroll_docs(4), [''] = cmp.mapping.abort(), [''] = cmp.mapping.confirm({behavior = cmp.ConfirmBehavior.Insert, select = false }), [''] = cmp.mapping.confirm({behavior = cmp.ConfirmBehavior.Insert, select = true }) }, snippet = { expand = function(args) require('luasnip').lsp_expand(args.body) end }, sources = { { name = 'luasnip'}, { name = 'nvim_lsp' }, { name = 'path' }, { name = 'buffer' }, } } -- 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 = { { "[C]", "Comment" } }, }, }, [types.insertNode] = { active = { virt_text = { { "[I]", "Comment" } }, }, }, }, }) -- Helper Termcode wrapper local to_term = function(str) return vim.api.nvim_replace_termcodes(str, true, true, true) end _G.next_opt = function() if ls and ls.expand_or_jumpable() then return to_term "luasnip-expand-or-jump" else return to_term "" end end _G.prev_opt = function() if ls and ls.jumpable(-1) then return to_term "luasnip-jump-prev" else return to_term "" end end map("i", "", "luasnip-next-choice", {}) map("s", "", "luasnip-next-choice", {}) map("i", "", "v:lua.next_opt()", {expr = true}) map("s", "", "v:lua.next_opt()", {expr = true}) map("i", "", "v:lua.prev_opt()", {expr = true}) map("s", "", "v:lua.prev_opt()", {expr = true}) require("luasnip.loaders.from_lua").load({paths = "~/.config/nvim/lua/snippets"}) -- Treesitter require('nvim-treesitter.configs').setup { ensure_installed = 'all', highlight = { enable = true, additional_vim_regex_highlighting = false, }, autotag = { enable = true } } -- Telescope map('n', 'ff', 'lua require("telescope.builtin").find_files()', {noremap = true}) map('n', 'fg', 'lua require("telescope.builtin").live_grep()', {noremap = true}) map('n', 'fb', 'lua require("telescope.builtin").buffers()', {noremap = true}) map('n', 'fh', 'lua require("telescope.builtin").help_tags()', {noremap = true}) -- Vimwiki require('mkdnflow').setup({ modules = { bib = false, folds = false, }, mappings = { MkdnEnter = { {'i', 'n', 'v'}, ''} }, links = { transform_explicit = function(text) return string.lower(text:gsub(' ', '')) end } }) autocmd('FileType', { desc = 'Set auto write all for markdown files', pattern = { 'markdown' }, command = 'set awa' }) vim.wo.conceallevel = 2 vim.keymap.set('n', '', ':edit #', { silent = true }) map('n', 'wf', 'lua require("telescope_customs").find_wiki()', {noremap = true}) map('n', 'wg', 'lua require("telescope_customs").grep_wiki()', {noremap = true}) -- Markdown Live Preview vim.g.nvim_markdown_preview_format = 'markdown' map('n', 'mlp', 'MarkdownPreview', {noremap = true}) -- Latex Live Preview vim.g.livepreview_previewer = 'zathura' vim.g.livepreview_use_biber = 1 map('n', 'llp', 'LLPStartPreview', {noremap = true}) -- Lir Filebrowser local actions = require('lir.actions') require('lir').setup { devicons_enable = false, mappings = { ['l'] = actions.edit, [''] = actions.split, [''] = actions.vsplit, [''] = actions.tabedit, ['h'] = actions.up, ['q'] = actions.quit, ['K'] = actions.mkdir, ['N'] = 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', '', 'lua require("lir.float").toggle()', { 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. })