vim.g.mapleader = ' ' vim.g.maplocalleader = ' ' vim.g.loaded_netrw = 1 vim.g.loaded_netrwPlugin = 1 -- Set highlight on search vim.o.hlsearch = false -- Make line numbers default vim.wo.number = true -- Enable mouse mode vim.o.mouse = 'a' -- Enable break indent vim.o.breakindent = true -- Save undo history vim.o.undofile = true -- Case insensitive searching UNLESS /C or capital in search vim.o.ignorecase = true vim.o.smartcase = true -- Keep signcolumn on by default vim.wo.signcolumn = 'yes' -- Set completeopt to have a better completion experience vim.o.completeopt = 'menuone,noselect,noinsert' -- Use terminal colors vim.o.termguicolors = true -- Tabs vim.o.shiftwidth = 4 vim.o.smarttab = true vim.o.tabstop = 4 vim.o.expandtab = true vim.o.softtabstop = 4 -- Show cursor line vim.o.cursorline = true vim.o.pumheight = 10 vim.o.relativenumber = true vim.o.scrolloff = 8 vim.o.showmode = false vim.o.showtabline = 0 vim.o.wrap = true -- show cursor line only in active window local cursorLineGrp = vim.api.nvim_create_augroup("CursorLine", { clear = true }) vim.api.nvim_create_autocmd( { "InsertLeave", "WinEnter" }, { pattern = "*", command = "set cursorline", group = cursorLineGrp } ) vim.api.nvim_create_autocmd( { "InsertEnter", "WinLeave" }, { pattern = "*", command = "set nocursorline", group = cursorLineGrp } ) -- Auto format on save vim.cmd [[autocmd BufWritePre * lua vim.lsp.buf.format()]] ------------------------------------------------------------------- -- Plugin management ------------------------------------------------------------------- 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) ------------------------------------------------------------------- -- Plugin installation ------------------------------------------------------------------- require('lazy').setup({ -- Color scheme ------------------------------------------ { dir = "~/code_server/nightly_cm.nvim", lazy = false, priority = 1000, config = function() vim.cmd.colorscheme 'nightly_cm' end, }, -- LSP ---------------------------------------------------- { 'neovim/nvim-lspconfig', event = { "BufReadPre", "BufNewFile" }, dependencies = { { 'williamboman/mason.nvim', config = true }, 'williamboman/mason-lspconfig.nvim', }, }, { 'hrsh7th/nvim-cmp', dependencies = { 'onsails/lspkind.nvim', 'L3MON4D3/LuaSnip', 'saadparwaiz1/cmp_luasnip', 'hrsh7th/cmp-nvim-lsp', 'rafamadriz/friendly-snippets', 'hrsh7th/cmp-buffer', 'hrsh7th/cmp-path', 'hrsh7th/cmp-cmdline', }, }, { 'zbirenbaum/copilot-cmp', event = { 'BufRead', 'BufNewFile' }, dependencies = { { 'zbirenbaum/copilot.lua', config = function() require('copilot').setup { suggestion = { enabled = false }, panel = { enabled = false }, filetypes = { markdown = true }, } end, }, }, config = function() require('copilot_cmp').setup() end, }, { -- Highlight, edit, and navigate code 'nvim-treesitter/nvim-treesitter', dependencies = { 'nvim-treesitter/nvim-treesitter-textobjects', }, build = ':TSUpdate', }, { "simrat39/rust-tools.nvim", }, -- { -- "ray-x/lsp_signature.nvim", -- config = function() -- require "lsp_signature".setup { -- bind = true, -- This is mandatory, otherwise border config won't get registered. -- handler_opts = { -- border = "solid" -- } -- } -- end -- }, -- { "jay-babu/mason-null-ls.nvim", event = { "BufReadPre", "BufNewFile" }, dependencies = { "williamboman/mason.nvim", "jose-elias-alvarez/null-ls.nvim", }, config = function() require("mason").setup() require("mason-null-ls").setup({ ensure_installed = { -- Opt to list sources here, when available in mason. }, automatic_installation = false, handlers = {}, }) require("null-ls").setup({ sources = { -- Anything not supported by mason. } }) end, }, -- File explorer ------------------------------------------- { 'nvim-telescope/telescope.nvim', branch = '0.1.x', dependencies = { 'nvim-lua/plenary.nvim' }, opts = function() local actions = require "telescope.actions" return { defaults = { path_display = { "truncate" }, mappings = { i = { [""] = actions.cycle_history_next, [""] = actions.cycle_history_prev, [""] = actions.move_selection_next, [""] = actions.move_selection_previous, [""] = actions.select_default, [""] = actions.close, }, n = { ["q"] = actions.close, [""] = actions.close, }, }, }, } end, }, { "nvim-telescope/telescope-file-browser.nvim", dependencies = { "nvim-telescope/telescope.nvim", "nvim-lua/plenary.nvim", }, }, { "nvim-neo-tree/neo-tree.nvim", branch = "v2.x", dependencies = { "nvim-lua/plenary.nvim", "nvim-tree/nvim-web-devicons", "MunifTanjim/nui.nvim", }, config = function() require("neo-tree").setup { close_if_last_window = true, default_component_configs = { indent = { padding = 0, indent_size = 1 }, }, commands = { parent_or_close = function(state) local node = state.tree:get_node() if (node.type == "directory" or node:has_children()) and node:is_expanded() then state.commands.toggle_node(state) else require("neo-tree.ui.renderer").focus_node(state, node:get_parent_id()) end end, child_or_open = function(state) local node = state.tree:get_node() if node.type == "directory" or node:has_children() then if not node:is_expanded() then -- if unexpanded, expand state.commands.toggle_node(state) else -- if expanded and has children, seleect the next child require("neo-tree.ui.renderer").focus_node(state, node:get_child_ids()[1]) end else -- if not a directory just open it state.commands.open_with_window_picker(state) end end, copy_selector = function(state) local node = state.tree:get_node() local filepath = node:get_id() local filename = node.name local modify = vim.fn.fnamemodify local results = { e = { val = modify(filename, ":e"), msg = "Extension only" }, f = { val = filename, msg = "Filename" }, F = { val = modify(filename, ":r"), msg = "Filename w/o extension" }, h = { val = modify(filepath, ":~"), msg = "Path relative to Home" }, p = { val = modify(filepath, ":."), msg = "Path relative to CWD" }, P = { val = filepath, msg = "Absolute path" }, } local messages = { { "\nChoose to copy to clipboard:\n", "Normal" }, } for i, result in pairs(results) do if result.val and result.val ~= "" then vim.list_extend(messages, { { ("%s."):format(i), "Identifier" }, { (" %s: "):format(result.msg) }, { result.val, "String" }, { "\n" }, }) end end vim.api.nvim_echo(messages, false, {}) local result = results[vim.fn.getcharstr()] if result and result.val and result.val ~= "" then vim.notify("Copied: " .. result.val) vim.fn.setreg("+", result.val) end end, }, window = { width = 30, mappings = { [""] = false, -- disable space until we figure out which-key disabling h = "parent_or_close", l = "child_or_open", Y = "copy_selector", }, }, } end, }, { "s1n7ax/nvim-window-picker", opts = { use_winbar = "smart", highlights = { statusline = { unfocused = { fg = '#d7af5f', bg = '#262626', bold = true, }, focused = { fg = '#d7af5f', bg = '#262626', bold = true, }, }, }, } }, -- GUI ------------------------------------------------------ { 'mrjones2014/smart-splits.nvim', opts = { at_edge = 'stop', } }, { -- Set lualine as statusline 'nvim-lualine/lualine.nvim', opts = { options = { icons_enabled = true, theme = 'nightly_cm', component_separators = '', section_separators = '', globalstatus = true, }, sections = { lualine_a = { 'mode' }, lualine_b = { 'branch', 'diff' }, lualine_c = { 'filename' }, lualine_x = { { -- Lsp server name . function() local msg = '' local clients = vim.lsp.get_active_clients({ bufnr = 0 }) if next(clients) == nil then return msg end for _, client in ipairs(clients) do msg = msg .. client.name .. ", " end if msg == '' then return msg end return msg:sub(1, -3) end, color = { fg = '#c6c6c6' }, }, }, lualine_y = { 'filetype' }, lualine_z = { 'progress' } }, }, }, { -- Adds git releated signs to the gutter, as well as utilities for managing changes 'lewis6991/gitsigns.nvim', opts = { signs = { add = { text = "▎" }, change = { text = "▎" }, delete = { text = "▎" }, topdelete = { text = "▎" }, changedelete = { text = "▎" }, untracked = { text = "▎" }, }, preview_config = { -- Options passed to nvim_open_win border = 'solid', style = 'minimal', relative = 'cursor', row = 0, col = 1 }, on_attach = function(bufnr) vim.keymap.set('n', 'gp', require('gitsigns').prev_hunk, { buffer = bufnr, desc = '[G]o to [P]revious Hunk' }) vim.keymap.set('n', 'gn', require('gitsigns').next_hunk, { buffer = bufnr, desc = '[G]o to [N]ext Hunk' }) vim.keymap.set('n', 'ph', require('gitsigns').preview_hunk, { buffer = bufnr, desc = '[P]review [H]unk' }) end, }, }, { -- Add indentation guides even on blank lines 'lukas-reineke/indent-blankline.nvim', opts = { show_trailing_blankline_indent = false, use_treesitter = true, char = "▏", context_char = "▏", show_current_context = true, } }, { "norcalli/nvim-colorizer.lua", config = function() require("colorizer").setup() end, }, { "folke/neodev.nvim", opts = {} }, -- Utils --------------------------------------------------- { "max397574/better-escape.nvim", opts = { timeout = 300 } }, { 'numToStr/Comment.nvim', opts = {} }, { "kdheepak/lazygit.nvim", dependencies = { "nvim-lua/plenary.nvim", }, }, { 'akinsho/toggleterm.nvim', version = "*", config = function() require("toggleterm").setup { open_mapping = [[]], shade_terminals = false, highlights = { Normal = { guibg = "#262626", }, NormalNC = { guibg = "#262626", }, }, } end, }, { "folke/todo-comments.nvim", dependencies = { "nvim-lua/plenary.nvim" }, opts = { } }, { 'phaazon/hop.nvim', branch = 'v2', -- optional but strongly recommended config = function() require 'hop'.setup { keys = 'etovxqpdygfblzhckisuran' } end }, { "folke/trouble.nvim", dependencies = { "nvim-tree/nvim-web-devicons" }, opts = { }, }, }, {}) ------------------------------------------------------------------- -- LSP Configurations ------------------------------------------------------------------- local on_attach = function(_, bufnr) local nmap = function(keys, func, desc) if desc then desc = 'LSP: ' .. desc end vim.keymap.set('n', keys, func, { buffer = bufnr, desc = desc }) end nmap('rn', vim.lsp.buf.rename, 'Rename') nmap('ca', vim.lsp.buf.code_action, 'Code Action') nmap('gd', vim.lsp.buf.definition, 'Goto Definition') nmap('gD', vim.lsp.buf.declaration, 'Goto Declaration') nmap('gI', vim.lsp.buf.implementation, 'Goto Implementation') nmap('gr', require('telescope.builtin').lsp_references, 'Goto References') nmap('D', vim.lsp.buf.type_definition, 'Type Definition') nmap('K', vim.lsp.buf.hover, 'Hover Documentation') nmap('', vim.lsp.buf.signature_help, 'Signature Documentation') nmap('', vim.lsp.buf.format(), 'Format current buffer') nmap('ds', require('telescope.builtin').lsp_document_symbols, 'Document Symbols') nmap('ws', require('telescope.builtin').lsp_dynamic_workspace_symbols, 'Workspace Symbols') -- Create a command `:Format` local to the LSP buffer vim.api.nvim_buf_create_user_command(bufnr, 'Format', function(_) vim.lsp.buf.format() end, { desc = 'Format current buffer with LSP' }) end -- Add LSP servers local servers = { lua_ls = { Lua = { workspace = { checkThirdParty = false }, telemetry = { enable = false }, }, }, clangd = { cmd = { 'clangd', '--background-index' }, filetypes = { 'c', 'cpp', 'objc', 'objcpp' }, }, rust_analyzer = {}, bashls = {}, pyright = {}, marksman = {}, } ------------------------------------------------------------------- -- Plugin Setup ------------------------------------------------------------------- -- nvim-cmp supports additional completion capabilities, so broadcast that to servers local capabilities = vim.lsp.protocol.make_client_capabilities() capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities) -- Ensure the servers above are installed local mason_lspconfig = require 'mason-lspconfig' mason_lspconfig.setup { ensure_installed = vim.tbl_keys(servers), } mason_lspconfig.setup_handlers { function(server_name) require('lspconfig')[server_name].setup { capabilities = capabilities, on_attach = on_attach, settings = servers[server_name], } end, } local handlers = { ["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, { border = "solid" }), ["textDocument/signatureHelp"] = vim.lsp.with(vim.lsp.handlers.signature_help, { border = "solid" }), } require('lspconfig').rust_analyzer.setup { on_attach = on_attach, handlers = handlers, } local opts = { tools = { runnables = { use_telescope = true, }, inlay_hints = { auto = true, show_parameter_hints = false, parameter_hints_prefix = "=> ", other_hints_prefix = "=> ", }, }, -- all the opts to send to nvim-lspconfig -- these override the defaults set by rust-tools.nvim -- see https://github.com/neovim/nvim-lspconfig/blob/master/CONFIG.md#rust_analyzer server = { -- on_attach is a callback called when the language server attachs to the buffer on_attach = on_attach, settings = { -- to enable rust-analyzer settings visit: -- https://github.com/rust-analyzer/rust-analyzer/blob/master/docs/user/generated_config.adoc ["rust-analyzer"] = { -- enable clippy on save checkOnSave = { command = "clippy", }, }, }, }, } require("rust-tools").setup(opts) require('lspconfig').clangd.setup { on_attach = on_attach, capabilities = { offsetEncoding = 'utf-16' }, handlers = handlers, } local runtime_path = vim.split(package.path, ';') table.insert(runtime_path, "lua/?.lua") table.insert(runtime_path, "lua/?/init.lua") require 'lspconfig'.lua_ls.setup { on_attach = on_attach, capabilities = capabilities, handlers = handlers, settings = { Lua = { runtime = { version = 'LuaJIT', path = runtime_path, }, diagnostics = { globals = { 'vim' }, }, workspace = { library = vim.api.nvim_get_runtime_file("", true), }, telemetry = { enable = false, }, }, }, } -- Setup neovim lua configuration require("telescope").load_extension "file_browser" -- [[ Configure nvim-cmp ]] local cmp = require 'cmp' local luasnip = require 'luasnip' require('luasnip.loaders.from_vscode').lazy_load() luasnip.config.setup {} local cmp_opts = { border = "solid", winhighlight = 'Normal:Pmenu,FloatBorder:FloatBorder,Search:NONE,CursorLine:PmenuSel', } cmp.setup { preselect = cmp.PreselectMode.None, view = { entries = "custom" -- can be "custom", "wildmenu" or "native" }, completion = { completion = { completeopt = 'menu,menuone,noinsert,noselect' }, }, window = { completion = cmp.config.window.bordered(cmp_opts), documentation = cmp.config.window.bordered(cmp_opts), }, snippet = { expand = function(args) luasnip.lsp_expand(args.body) end, }, duplicates = { nvim_lsp = 1, luasnip = 1, cmp_tabnine = 1, buffer = 1, path = 1, }, mapping = cmp.mapping.preset.insert { [''] = cmp.mapping.complete {}, [''] = cmp.mapping.confirm { behavior = cmp.ConfirmBehavior.Replace, select = false, }, [''] = cmp.mapping(function(fallback) if cmp.visible() then cmp.select_next_item() elseif luasnip.expand_or_locally_jumpable() then luasnip.expand_or_jump() else fallback() end end, { 'i', 's' }), [''] = cmp.mapping(function(fallback) if cmp.visible() then cmp.select_prev_item() elseif luasnip.locally_jumpable(-1) then luasnip.jump(-1) else fallback() end end, { 'i', 's' }), }, sources = { { name = 'nvim_lsp', priority = 2000 }, { name = 'luasnip', priority = 1000 }, { name = 'copilot', priority = 750 }, { name = 'buffer', priority = 500 }, { name = 'path', priority = 250 }, }, } cmp.setup.cmdline({ '/', '?' }, { mapping = cmp.mapping.preset.cmdline(), view = { entries = { name = 'wildmenu', separator = '|' } }, window = { completion = cmp.config.window.bordered(cmp_opts), documentation = cmp.config.window.bordered(cmp_opts), }, sources = { { name = 'buffer' } } }) cmp.setup.cmdline(':', { mapping = cmp.mapping.preset.cmdline(), view = { entries = { name = 'wildmenu', separator = '|' } }, window = { completion = cmp.config.window.bordered(cmp_opts), documentation = cmp.config.window.bordered(cmp_opts), }, sources = cmp.config.sources({ { name = 'path' } }, { { name = 'cmdline' } }) }) -- [[ Configure Treesitter ]] require('nvim-treesitter.configs').setup { -- Add languages to be installed here that you want installed for treesitter ensure_installed = { 'c', 'cpp', 'go', 'lua', 'python', 'rust', 'tsx', 'typescript', 'vimdoc', 'vim' }, -- Autoinstall languages that are not installed. Defaults to false (but you can change for yourself!) auto_install = false, highlight = { enable = true }, indent = { enable = true }, incremental_selection = { enable = true, keymaps = { init_selection = '', node_incremental = '', scope_incremental = '', node_decremental = '', }, }, textobjects = { select = { enable = true, lookahead = true, -- Automatically jump forward to textobj, similar to targets.vim keymaps = { -- You can use the capture groups defined in textobjects.scm ['aa'] = '@parameter.outer', ['ia'] = '@parameter.inner', ['af'] = '@function.outer', ['if'] = '@function.inner', ['ac'] = '@class.outer', ['ic'] = '@class.inner', }, }, move = { enable = true, set_jumps = true, -- whether to set jumps in the jumplist goto_next_start = { [']m'] = '@function.outer', [']]'] = '@class.outer', }, goto_previous_start = { ['[m'] = '@function.outer', ['[['] = '@class.outer', }, goto_next_end = { [']M'] = '@function.outer', [']['] = '@class.outer', }, goto_previous_end = { ['[M'] = '@function.outer', ['[]'] = '@class.outer', }, }, swap = { enable = true, swap_next = { ['a'] = '@parameter.inner', }, swap_previous = { ['A'] = '@parameter.inner', }, }, }, } -- resizing splits vim.keymap.set({ 'n', 't' }, '', require('smart-splits').resize_left, { desc = 'Resize left' }) vim.keymap.set({ 'n', 't' }, '', require('smart-splits').resize_down, { desc = 'Resize down' }) vim.keymap.set({ 'n', 't' }, '', require('smart-splits').resize_up, { desc = 'Resize up' }) vim.keymap.set({ 'n', 't' }, '', require('smart-splits').resize_right, { desc = 'Resize right' }) -- moving between splits vim.keymap.set({ 'n', 't' }, '', require('smart-splits').move_cursor_left, { desc = 'Move cursor left' }) vim.keymap.set({ 'n', 't' }, '', require('smart-splits').move_cursor_down, { desc = 'Move cursor down' }) vim.keymap.set({ 'n', 't' }, '', require('smart-splits').move_cursor_up, { desc = 'Move cursor up' }) vim.keymap.set({ 'n', 't' }, '', require('smart-splits').move_cursor_right, { desc = 'Move cursor right' }) -- swapping buffers between windows vim.keymap.set('n', 'h', require('smart-splits').swap_buf_left, { desc = 'Swap buffer left' }) vim.keymap.set('n', 'j', require('smart-splits').swap_buf_down, { desc = 'Swap buffer down' }) vim.keymap.set('n', 'k', require('smart-splits').swap_buf_up, { desc = 'Swap buffer up' }) vim.keymap.set('n', 'l', require('smart-splits').swap_buf_right, { desc = 'Swap buffer right' }) -- telescope vim.keymap.set('n', 'fo', require('telescope.builtin').oldfiles, { desc = 'Find recently opened files' }) vim.keymap.set('n', 'ff', require('telescope.builtin').find_files, { desc = 'Find files' }) vim.keymap.set('n', 'fb', ":Telescope file_browser", { desc = 'File browser', silent = true }) vim.keymap.set('n', 'sh', require('telescope.builtin').help_tags, { desc = 'Search help' }) vim.keymap.set('n', 'sw', require('telescope.builtin').grep_string, { desc = 'Search current word' }) vim.keymap.set('n', 'sg', require('telescope.builtin').live_grep, { desc = 'Search by grep' }) vim.keymap.set('n', 'sd', require('telescope.builtin').diagnostics, { desc = 'Search diagnostics' }) --Other vim.keymap.set('n', '', ":tabNext", { desc = 'Next tab', silent = true }) vim.keymap.set('n', '', ":Format", { desc = 'Format code', silent = true }) vim.keymap.set('n', 'gg', ":LazyGitCurrentFile", { desc = 'Format code', silent = true }) vim.keymap.set('n', '', ":make", { desc = 'Format code', silent = true }) vim.keymap.set('n', '', ":make clean", { desc = 'Format code', silent = true }) vim.keymap.set('n', '', ":write", { desc = 'Save', silent = true }) vim.keymap.set('n', '', ":quit", { desc = 'Quit', silent = true }) vim.keymap.set('n', 'n', ":tabnew", { desc = 'Format code', silent = true }) vim.keymap.set('n', 'c', ":tabclose", { desc = 'Format code', silent = true }) vim.keymap.set('n', 'e', ":NeoTreeShowToggle", { desc = 'File explorer', silent = true }) vim.keymap.set('n', 's', ":HopWord", { desc = 'hop', silent = true }) vim.keymap.set('n', 't', ":TroubleToggle", { desc = 'Trouble view', silent = true })