local vim = vim -- luacheck: ignore -- general settings vim.o.scrolloff = 3 -- keep 3 lines above/below the cursor -- clipboard: use PRIMARY, with xclip vim.opt.clipboard:append({'unnamed'}) vim.o.mouse = 'a' -- enable mouse for all modes -- display settings vim.o.title = true -- Titel anzeigen vim.o.cursorline = true -- highlight line with cursor vim.o.signcolumn = "yes" -- always show signcolumn vim.o.number = true -- Zeilennummern anzeigen, optional mit relativenumber vim.o.colorcolumn = '80' -- vim.o.statusline = '[%n]\ %f\ \ %y\ \ %m%r%h%w\ \ (%l,%v)\ \ %p%%' -- define characters for displaying special characters and enable them vim.o.listchars = 'tab:▸ ,lead:·,leadmultispace:|···,trail:·,eol:¬,extends:❯,precedes:❮' vim.o.list = true vim.o.showbreak = '↪' -- netrw (explorer) settings vim.g.netrw_liststyle = 3 vim.g.netrw_banner = 0 -- code display settings vim.o.termguicolors = true -- enable 24-bit colors - some colorschemes need this vim.o.showmatch = true -- Zeigt korrespondierende Klammern -- search/replace settings vim.o.ignorecase = true -- case doesnt matter in searches vim.o.smartcase = true -- search casesensitive if 1+ chars are uppercase vim.o.gdefault = true -- replace all occurences in a line without explicit 'g' -- completion settings vim.o.completeopt = 'menu,menuone,noselect' -- mappings vim.g.mapleader = " " -- Use Ctrl-c to leave insert mode vim.keymap.set("i", "", "") -- open explorer vim.keymap.set("n", "e", vim.cmd.Ex) -- save current buffer vim.keymap.set("n", "w", ":w") -- close current buffer vim.keymap.set("n", "c", ":bp:bw #", {silent = true}) -- force close current buffer (closing also the window) vim.keymap.set("n", "C", ":close", {silent = true}) -- Alt + h/l: previous/next buffer vim.keymap.set("n", "", ":bp", {silent = true}) vim.keymap.set("n", "", ":bn", {silent = true}) -- toggle between current and previous buffer vim.keymap.set("n", "", "") -- search for a string typed in vim.keymap.set("n", "f", ":grep! --no-ignore -g '!.git/*' -g '!__pycache__/*' '' .") -- search for the word under the cursor vim.keymap.set("n", "F", ":execute \"grep! --no-ignore -g '!.git/*' -g '!__pycache__/*' '\".expand(\"\").\"' .\":copen", {silent = true}) -- jump to previous search result vim.keymap.set("n", "k", ":cp", {silent = true}) -- jump to next search result vim.keymap.set("n", "j", ":cn", {silent = true}) -- Keep search matches in the middle of the window vim.keymap.set("n", "n", "nzzzv") vim.keymap.set("n", "N", "Nzzzv") -- Keep half-page up/down in the middle of the window vim.keymap.set("n", "", "zz") vim.keymap.set("n", "", "zz") -- Search for word under cursor but do not jump to next occurence vim.keymap.set("n", "*", "*N") -- clear search highlight vim.keymap.set("n", "", ":nohlsearch", {silent = true}) -- search and replace in current file vim.keymap.set("n", "r", ":%s//XXX/Ic") -- move a block in visual mode vim.keymap.set("v", "J", ":m '>+1gv=gv") vim.keymap.set("v", "K", ":m '<-2gv=gv") -- indent a block in visual mode vim.keymap.set("v", "H", "gv") -- paste in visual mode without losing the register content vim.keymap.set("x", "p", [["_dP]]) -- fugitive status view vim.keymap.set("n", "g", ":0G", {silent = true}) -- Insert an unchecked checkbox vim.keymap.set("n", "t", "o- [ ] ") -- Check the checkbox in the current line vim.keymap.set("n", "T", ":s/\\[ \\]/[X]/:nohls", {silent = true}) -- show/hide invisible characters vim.keymap.set("n", ".", ":set invlist", {silent = true}) -- set local settings for terminal buffers vim.api.nvim_create_autocmd("TermOpen", { group = vim.api.nvim_create_augroup("custom-term-open", {}), callback = function() vim.opt_local.number = false vim.opt_local.scrolloff = 0 vim.bo.buflisted = false end, }) -- use escape key in terminal mode as well vim.keymap.set("t", "", "") -- open a terminal at the bottom of the screen with a fixed height. vim.keymap.set("n", "st", function() vim.cmd.new() vim.cmd.wincmd "J" vim.api.nvim_win_set_height(0, 20) vim.wo.winfixheight = true vim.cmd.term() end) -- install lazy.nvim package manager if not already done local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" 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", -- latest stable release lazypath, }) end vim.opt.rtp:prepend(lazypath) -- install plugins require('lazy').setup({ -- navigation {'nvim-telescope/telescope.nvim', branch = '0.1.x', dependencies = { 'nvim-lua/plenary.nvim', { 'nvim-telescope/telescope-fzf-native.nvim', build = 'make', cond = function() return vim.fn.executable 'make' == 1 end, }, } }, {'ThePrimeagen/harpoon', dependencies = {'nvim-lua/plenary.nvim'}, branch = "harpoon2" }, 'christoomey/vim-tmux-navigator', -- statusline 'nvim-lualine/lualine.nvim', 'nvim-tree/nvim-web-devicons', -- lsp/completion 'neovim/nvim-lspconfig', 'hrsh7th/nvim-cmp', 'hrsh7th/cmp-cmdline', 'hrsh7th/cmp-buffer', 'hrsh7th/cmp-path', 'hrsh7th/cmp-nvim-lua', 'hrsh7th/cmp-nvim-lsp', 'onsails/lspkind-nvim', -- misc plugins 'tpope/vim-fugitive', 'lewis6991/gitsigns.nvim', 'mfussenegger/nvim-lint', {'folke/trouble.nvim', opts = { focus = true, auto_preview = false, }, cmd = "Trouble", keys = { { "tt", "Trouble diagnostics toggle", desc = "Diagnostics (Trouble)", }, }, }, -- colorschemes 'mhinz/vim-janah', 'lifepillar/vim-solarized8', }, {}) local function cs_janah() -- luacheck: ignore vim.o.termguicolors = false vim.cmd.colorscheme('janah') -- set different highlight groups for indentation and newline/wrap hints vim.cmd('highlight link Whitespace SpecialKey') vim.cmd('highlight! link NonText Comment') end local function cs_solarized_light() -- luacheck: ignore vim.o.termguicolors = true vim.o.background = 'light' vim.cmd.colorscheme('solarized8_high') vim.cmd('highlight link Whitespace htmlTag') vim.cmd('highlight! link NonText htmlTag') end local function cs_solarized_dark() -- luacheck: ignore vim.o.termguicolors = true vim.o.background = 'dark' vim.cmd.colorscheme('solarized8_flat') vim.cmd('highlight link Whitespace htmlTag') vim.cmd('highlight! link NonText htmlTag') end local function cs_toggle() -- luacheck: ignore if vim.g.colors_name == 'solarized8_high' then cs_janah() else cs_solarized_light() end end -- toggle colorschemes vim.keymap.set("n", ",", cs_toggle) -- colorschemes cs_janah() --cs_solarized_light() --cs_solarized_dark() -- lsp setup local cmp = require'cmp' local lspkind = require "lspkind" cmp.setup({ mapping = { [''] = cmp.mapping(cmp.mapping.scroll_docs(-4), { 'i', 'c' }), [''] = cmp.mapping(cmp.mapping.scroll_docs(4), { 'i', 'c' }), [''] = cmp.mapping(cmp.mapping.complete(), { 'i', 'c' }), [''] = cmp.mapping(cmp.mapping.select_next_item(), { 'i', 'c' }), [''] = cmp.config.disable, -- Specify `cmp.config.disable` if you want to remove the default `` mapping. [''] = cmp.mapping({ i = cmp.mapping.abort(), c = cmp.mapping.close(), }), [''] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. }, sources = cmp.config.sources({ }, { { name = "nvim_lsp" }, { name = 'buffer' }, { name = "path" }, { name = "nvim_lua" }, }), formatting = { format = lspkind.cmp_format { with_text = true, menu = { buffer = "[buf]", nvim_lsp = "[LSP]", nvim_lua = "[api]", path = "[path]", cmdline = "[cmd]", }, }, }, }) -- Use buffer source for `/` (if you enabled `native_menu`, this won't work anymore). cmp.setup.cmdline('/', { sources = { { name = 'buffer' } } }) -- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore). cmp.setup.cmdline(':', { sources = cmp.config.sources({ { name = 'path' } }, { { name = 'cmdline' } }) }) -- Setup lspconfig local nvim_lsp = require('lspconfig') -- Use an on_attach function to only map the following keys -- after the language server attaches to the current buffer local on_attach = function(client, bufnr) -- luacheck: ignore local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end 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.declaration()', opts) buf_set_keymap('n', 'gd', 'lua vim.lsp.buf.definition()', opts) buf_set_keymap('n', 'K', 'lua vim.lsp.buf.hover()', opts) -- buf_set_keymap('n', 'gi', 'lua vim.lsp.buf.implementation()', opts) -- buf_set_keymap('n', '', 'lua vim.lsp.buf.signature_help()', opts) -- buf_set_keymap('n', 'wa', 'lua vim.lsp.buf.add_workspace_folder()', opts) -- buf_set_keymap('n', 'wr', 'lua vim.lsp.buf.remove_workspace_folder()', opts) -- buf_set_keymap('n', 'wl', 'lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))', opts) -- buf_set_keymap('n', 'D', 'lua vim.lsp.buf.type_definition()', opts) buf_set_keymap('n', 'R', 'lua vim.lsp.buf.rename()', opts) -- buf_set_keymap('n', 'ca', 'lua vim.lsp.buf.code_action()', opts) buf_set_keymap('n', 'o', 'lua vim.lsp.buf.references()', opts) -- buf_set_keymap('n', 'e', 'lua vim.diagnostic.open_float()', opts) -- buf_set_keymap('n', '[d', 'lua vim.diagnostic.goto_prev()', opts) -- buf_set_keymap('n', ']d', 'lua vim.diagnostic.goto_next()', opts) -- buf_set_keymap('n', 'q', 'lua vim.diagnostic.setloclist()', opts) -- buf_set_keymap('n', 'f', 'lua vim.lsp.buf.formatting()', opts) end -- configure pyright language server nvim_lsp.pyright.setup { on_attach = on_attach, flags = { debounce_text_changes = 150, }, settings = { python = { analysis = { typeCheckingMode = "off", } } } } -- configure nvim-lint do local lint = require('lint') lint.linters_by_ft = { lua = {'luacheck'}, python = {'flake8'}, sh = {'shellcheck'}, ['yaml.ansible'] = {'ansible_lint'}, } vim.api.nvim_create_autocmd({'BufWritePost', 'BufEnter'}, { group = vim.api.nvim_create_augroup('lint', { clear = true }), callback = function() lint.try_lint() end, }) end -- configure lualine require('lualine').setup({ options = { section_separators = '', component_separators = '|' }, sections = { lualine_a = {'mode'}, lualine_b = { {'filename', path = 1} }, -- relative path lualine_c = {}, lualine_x = {'encoding', 'fileformat', 'filetype'}, lualine_y = {'progress'}, lualine_z = {'location'} }, tabline = { lualine_a = { { 'buffers', symbols = {alternate_file = ''}, buffers_color = { active = 'lualine_a_insert', inactive = 'lualine_a_normal', }, } }, lualine_b = {}, lualine_c = {}, lualine_x = {}, lualine_y = {}, lualine_z = {} } }) -- configure gitsigns require('gitsigns').setup({ signs = { add = { text = '+' }, change = { text = '~' }, delete = { text = '_' }, topdelete = { text = '‾' }, changedelete = { text = '~' }, untracked = { text = '┆' }, }, }) -- configure telescope local actions = require('telescope.actions') require('telescope').setup({ defaults = { layout_strategy = 'vertical', mappings = { i = { [""] = actions.close -- exit telescope in insert mode with }, }, vimgrep_arguments = { "rg", "--color=never", "--no-heading", "--with-filename", "--line-number", "--column", "--smart-case", "--no-ignore" -- ignore .gitignore, .ignore, etc }, } }) require('telescope').load_extension('fzf') local builtin = require('telescope.builtin') vim.keymap.set('n', 'ff', function() builtin.find_files({no_ignore = true}) end) vim.keymap.set('n', 'fg', builtin.live_grep) vim.keymap.set('n', 'fb', builtin.buffers) vim.keymap.set('n', 'fh', builtin.help_tags) -- configure harpoon local harpoon = require("harpoon") harpoon:setup() vim.keymap.set("n", "m", function() harpoon:list():add() end) vim.keymap.set("n", "h", function() harpoon.ui:toggle_quick_menu(harpoon:list()) end) vim.keymap.set("n", "1", function() harpoon:list():select(1) end) vim.keymap.set("n", "2", function() harpoon:list():select(2) end) vim.keymap.set("n", "3", function() harpoon:list():select(3) end) vim.keymap.set("n", "4", function() harpoon:list():select(4) end) vim.keymap.set("n", "5", function() harpoon:list():select(5) end) vim.keymap.set("n", "6", function() harpoon:list():select(6) end) vim.keymap.set("n", "7", function() harpoon:list():select(7) end) vim.keymap.set("n", "8", function() harpoon:list():select(8) end) vim.keymap.set("n", "9", function() harpoon:list():select(9) end) vim.keymap.set("n", "0", function() harpoon:list():select(10) end)