-- Options ---------- vim.o.undofile = true vim.o.backup = true vim.cmd "set backupdir-=." vim.cmd "set shortmess+=c" vim.o.mouse = "a" vim.o.ignorecase = true vim.o.smartcase = true vim.o.smartindent = true -- tabstop and shiftwidth are set locally by individual filetypes vim.o.inccommand = "split" vim.o.scrolloff = 1 vim.o.sidescrolloff = 5 vim.o.colorcolumn = "80" vim.o.cursorline = true vim.o.title = true vim.o.wildmode = "longest:full,full" vim.o.completeopt = "menu,menuone,preview,noinsert,noselect" -- Use ripgrep vim.o.grepprg = vim.g.ripgrep_path .. " --vimgrep --smart-case" vim.o.grepformat = "%f:%l:%c:%m," .. vim.o.grepformat vim.o.termguicolors = true vim.o.background = "dark" -- Mode already shown by the status line vim.o.showmode = false -- Do not set "trail:-" because it messes up the highlighting vim.o.listchars = "tab:│ ,extends:>,precedes:<,nbsp:+" vim.wo.list = true vim.o.fillchars = "fold:─,vert:│" -- Leaders ---------- vim.g.maplocalleader = "," vim.g.mapleader = ";" -- Misc ------- -- From neovim#14420 -- Restores the position of previously opened files vim.cmd [[ augroup LastCursorPos autocmd! autocmd BufReadPost * if @% !~# "\.git[\/\\]COMMIT_EDITMSG$" && line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g`\"" | endif augroup end ]] -- Highlight yanked text vim.cmd "autocmd TextYankPost * silent! lua vim.highlight.on_yank()" vim.g.tex_flavor = "latex" vim.g.gruvbox_italic = 1 vim.cmd "colorscheme gruvbox" -- Mappings ----------- local mapopts = { noremap = true, silent = true } vim.fn["camelcasemotion#CreateMotionMappings"] "" vim.keymap.set("n", "yof", function() if vim.opt_local.formatoptions:get().a then vim.opt_local.formatoptions:remove "a" print(":setlocal formatoptions-=a") else vim.opt_local.formatoptions:append "a" print(":setlocal formatoptions+=a") end end, mapopts) -- Plugins ---------- -- Gitsigns require("gitsigns").setup { keymaps = { noremap = true, buffer = true, silent = true, ["n ]c"] = { expr = true, "&diff ? ']c' : 'lua require\"gitsigns\".next_hunk()'" }, ["n [c"] = { expr = true, "&diff ? '[c' : 'lua require\"gitsigns\".prev_hunk()'" }, ["n hs"] = 'lua require"gitsigns".stage_hunk()', ["n hu"] = 'lua require"gitsigns".undo_stage_hunk()', ["n hr"] = 'lua require"gitsigns".reset_hunk()', ["n hR"] = 'lua require"gitsigns".reset_buffer()', ["n hp"] = 'lua require"gitsigns".preview_hunk()', ["n hb"] = 'lua require"gitsigns".blame_line()', -- Text objects ["o ih"] = ':lua require"gitsigns".select_hunk()', ["x ih"] = ':lua require"gitsigns".select_hunk()', }, } -- Treesitter require("nvim-treesitter.configs").setup { highlight = { enable = true, }, incremental_selection = { enable = true, keymaps = { init_selection = "gnn", node_incremental = "grn", scope_incremental = "grc", node_decremental = "grm", }, }, indent = { enable = true, disable = { "rust" }, }, matchup = { enable = true, }, refactor = { highlight_definitions = { enable = true }, }, textobjects = { lsp_interop = { enable = true, border = "none", peek_definition_code = { ["df"] = "@function.outer", ["dF"] = "@class.outer", }, }, move = { enable = true, goto_next_start = { ["]m"] = "@function.outer", ["]]"] = "@class.outer", }, goto_next_end = { ["]M"] = "@function.outer", ["]["] = "@class.outer", }, goto_previous_start = { ["[m"] = "@function.outer", ["[["] = "@class.outer", }, goto_previous_end = { ["[M"] = "@function.outer", ["[]"] = "@class.outer", }, }, select = { enable = true, keymaps = { -- You can use the capture groups defined in textobjects.scm ["af"] = "@function.outer", ["if"] = "@function.inner", ["aF"] = "@call.outer", ["iF"] = "@call.inner", ["ac"] = "@class.outer", ["ic"] = "@class.inner", ["aC"] = "@comment.outer", ["iC"] = "@comment.inner", ["ab"] = "@block.outer", ["ib"] = "@block.inner", ["aa"] = "@parameter.outer", ["ia"] = "@parameter.inner", }, }, swap = { enable = true, swap_next = { ["a"] = "@parameter.inner", }, swap_previous = { ["A"] = "@parameter.inner", }, }, }, } vim.o.foldmethod = "expr" vim.o.foldexpr = "nvim_treesitter#foldexpr()" vim.api.nvim_set_hl(0, "TSCurrentScope", { bg = vim.g.current_gruvbox_colors.dark0_soft[1], }) vim.api.nvim_set_hl(0, "TSDefinition", { bg = vim.g.current_gruvbox_colors.faded_blue[1], }) vim.api.nvim_set_hl(0, "TSDefinitionUsage", { bg = vim.g.current_gruvbox_colors.faded_aqua[1], }) -- nvim-cmp local cmp = require "cmp" cmp.setup { snippet = { expand = function(args) vim.fn["vsnip#anonymous"](args.body) end, }, mapping = cmp.mapping.preset.insert { [""] = cmp.mapping.confirm { select = false }, }, sources = cmp.config.sources({ { name = "nvim_lsp" }, { name = "vsnip" }, { name = "latex_symbols" }, { name = "calc" }, }, { { name = "path" }, { name = "treesitter" }, }, { { name = "tmux" }, { name = "spell" }, -- Use \k for iskeyword because of UTF-8 { name = "buffer", option = { keyword_pattern = [[\k\+]] } }, }), } cmp.setup.cmdline("/", { sources = { { name = "buffer", option = { keyword_pattern = [[\k\+]] } }, }, mapping = cmp.mapping.preset.cmdline {}, }) cmp.setup.cmdline(":", { sources = cmp.config.sources { { name = "cmdline" }, }, mapping = cmp.mapping.preset.cmdline {}, }) -- Telescope require("telescope").setup { extensions = { file_browser = { path = "%:p:h", dir_icon = "D", }, ["ui-select"] = { require("telescope.themes").get_dropdown(), }, }, } require("telescope").load_extension "file_browser" require("telescope").load_extension "ui-select" telescope_builtin = require "telescope.builtin" telescope_extensions = require("telescope").extensions vim.keymap.set("n", "fb", telescope_builtin.buffers, mapopts) vim.keymap.set("n", "ff", telescope_builtin.find_files, mapopts) vim.keymap.set("n", "fg", telescope_builtin.live_grep, mapopts) vim.keymap.set("n", "fh", telescope_builtin.help_tags, mapopts) vim.keymap.set("n", "fo", telescope_builtin.oldfiles, mapopts) vim.keymap.set("n", "fs", telescope_builtin.spell_suggest, mapopts) vim.keymap.set("n", "ft", telescope_builtin.treesitter, mapopts) vim.keymap.set("n", "-", telescope_extensions.file_browser.file_browser, mapopts) -- Lualine require("lualine").setup { options = { component_separators = "", icons_enabled = false, section_separators = "", }, sections = { lualine_c = { "filename", { "lsp_progress", display_components = { "lsp_client_name", { "title", "percentage", "message" } }, }, }, }, } -- VSnip vim.keymap.set("i", "", "vsnip#jumpable(1) ? '(vsnip-jump-next)' : ''", { silent = true, expr = true }) vim.keymap.set("s", "", "vsnip#jumpable(1) ? '(vsnip-jump-next)' : ''", { silent = true, expr = true }) vim.keymap.set( "i", "", "vsnip#jumpable(-1) ? '(vsnip-jump-prev)' : ''", { silent = true, expr = true } ) vim.keymap.set( "s", "", "vsnip#jumpable(-1) ? '(vsnip-jump-prev)' : ''", { silent = true, expr = true } ) -- OSCyank -- Text yanked into the "t register gets copied using OSC52 escape sequences -- (e.g. goes through SSH) vim.cmd "autocmd TextYankPost * if v:event.regname is 't' | OSCYankReg t | endif" -- Diffview require("diffview").setup { use_icons = false, enhanced_diff_hl = true, } -- Neogit require("neogit").setup { signs = { section = { "", "" }, item = { "", "" }, }, integrations = { diffview = true, }, } -- Notify vim.cmd [[highlight link NotifyERRORBorder DiagnosticError]] vim.cmd [[highlight link NotifyERRORIcon DiagnosticError]] vim.cmd [[highlight link NotifyERRORTitle DiagnosticError]] vim.cmd [[highlight link NotifyWARNBorder DiagnosticWarn]] vim.cmd [[highlight link NotifyWARNIcon DiagnosticWarn]] vim.cmd [[highlight link NotifyWARNTitle DiagnosticWarn]] vim.cmd [[highlight link NotifyINFOBorder DiagnosticInfo]] vim.cmd [[highlight link NotifyINFOIcon DiagnosticInfo]] vim.cmd [[highlight link NotifyINFOTitle DiagnosticInfo]] vim.cmd [[highlight link NotifyDEBUGBorder DiagnosticHint]] vim.cmd [[highlight link NotifyDEBUGIcon DiagnosticHint]] vim.cmd [[highlight link NotifyDEBUGTitle DiagnosticHint]] vim.cmd [[highlight link NotifyDEBUGBorder GruvboxPurple]] vim.cmd [[highlight link NotifyDEBUGIcon GruvboxPurple]] vim.cmd [[highlight link NotifyDEBUGTitle GruvboxPurple]] vim.notify = require "notify" -- Comment require("Comment").setup {} -- Local config function isModuleAvailable(name) if package.loaded[name] then return true else for _, searcher in ipairs(package.searchers or package.loaders) do local loader = searcher(name) if type(loader) == "function" then package.preload[name] = loader return true end end return false end end if isModuleAvailable "local_config" then require "local_config" end