vim.g.mapleader = ' ' vim.g.maplocalleader = ' ' vim.opt.tabstop = 4 vim.opt.softtabstop = 4 vim.opt.shiftwidth = 4 vim.opt.expandtab = true vim.opt.smartindent = true vim.opt.autoindent = true vim.opt.background = 'dark' vim.opt.relativenumber = true vim.opt.mouse = 'a' vim.g.copilot_enabled = 0 -- vim.opt.clipboard = 'unnamedplus' vim.opt.undofile = true vim.opt.signcolumn = 'yes' -- vim.opt.foldenable = true -- vim.opt.foldmethod = "indent" -- by default split to the right/below vim.opt.splitright = true vim.opt.splitbelow = true vim.cmd.colorscheme 'habamax' vim.opt.cursorline = true vim.opt.scrolloff = 10 vim.opt.hlsearch = true vim.opt.list = true vim.keymap.set('n', 'm', 'nohlsearch') vim.opt.listchars = { tab = '» ', trail = '·', nbsp = '␣' } -- vim.opt.wildmenu = true -- vim.opt.showmatch = true -- vim.opt.incsearch = true -- vim.opt.numberwidth = 4 vim.opt.foldenable = true vim.opt.foldmethod = 'indent' vim.opt.foldlevelstart = 10 vim.opt.foldnestmax = 10 vim.opt.backspace = 'indent,eol,start' vim.opt.termguicolors = true -- Navigation keymaps vim.keymap.set('i', 'jk', '') -- Diagnostic keymaps vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, { desc = 'Previous [D]iagnostic message' }) vim.keymap.set('n', ']d', vim.diagnostic.goto_next, { desc = 'Previous [D]iagnostic message' }) vim.keymap.set('n', 'gl', vim.diagnostic.open_float, { desc = 'Show diagnostic' }) vim.keymap.set('n', 'q', vim.diagnostic.setloclist, { desc = 'Open diagnostic [Q]uickfix list' }) vim.keymap.set('n', 'c', ':ChatGPT', { desc = 'Open ChatGPT' }) -- Diagnostics config local signs = { { name = 'DiagnosticSignError', text = '' }, { name = 'DiagnosticSignWarn', text = '' }, { name = 'DiagnosticSignHint', text = '' }, { name = 'DiagnosticSignInfo', text = '' }, } for _, sign in ipairs(signs) do vim.fn.sign_define(sign.name, { texthl = sign.name, text = sign.text, numhl = '' }) end local config = { virtual_text = false, signs = { active = signs, }, update_in_insert = true, underline = true, severity_sort = true, float = { focusable = false, style = 'minimal', border = 'none', -- max_width = 80, source = 'always', header = '', prefix = '', }, } vim.diagnostic.config(config) -- Window keymaps -- See `:help wincmd` for a list of all window commands vim.keymap.set('n', '', '', { desc = 'Move focus to the left window' }) vim.keymap.set('n', '', '', { desc = 'Move focus to the right window' }) vim.keymap.set('n', '', '', { desc = 'Move focus to the lower window' }) vim.keymap.set('n', '', '', { desc = 'Move focus to the upper window' }) vim.keymap.set('n', 'j', 'gj') vim.keymap.set('n', 'k', 'gk') -- tab navigation vim.keymap.set('n', 'H', 'gT') vim.keymap.set('n', 'L', 'gt') -- folds vim.keymap.set('n', 'l', 'za', { desc = 'fold' }) -- copy to clipbaord in visual mode vim.keymap.set('v', '', '"+y') -- move blocvim.keymap.sets of text visually vim.keymap.set('v', 'J', ":m '>+1gv=gv") vim.keymap.set('v', 'K', ":m '<-2gv=gv") -- stay in visual mode while indenting vim.keymap.set('v', '>', '>gv') vim.keymap.set('v', '<', '', 'zz') vim.keymap.set('n', '', 'zz') -- Launches vim.keymap.set('n', 'g', ':Neogit') local lazypath = vim.fn.stdpath 'data' .. '/lazy/lazy.nvim' if not vim.loop.fs_stat(lazypath) then local lazyrepo = 'https://github.com/folke/lazy.nvim.git' vim.fn.system { 'git', 'clone', '--filter=blob:none', '--branch=stable', lazyrepo, lazypath } end ---@diagnostic disable-next-line: undefined-field vim.opt.rtp:prepend(lazypath) require('lazy').setup { { 'tpope/vim-sleuth', enabled = false }, { 'numToStr/Comment.nvim', opts = {} }, { 'lewis6991/gitsigns.nvim', opts = { signs = { add = { text = '+' }, change = { text = '~' }, delete = { text = '_' }, topdelete = { text = '‾' }, changedelete = { text = '~' }, }, }, }, { 'folke/which-key.nvim', event = 'VimEnter', -- Sets the loading event to 'VimEnter' enabled = false, config = function() -- This is the function that runs, AFTER loading require('which-key').setup() -- Document existing key chains require('which-key').register { ['c'] = { name = '[C]ode', _ = 'which_key_ignore' }, ['d'] = { name = '[D]ocument', _ = 'which_key_ignore' }, ['r'] = { name = '[R]ename', _ = 'which_key_ignore' }, ['s'] = { name = '[S]earch', _ = 'which_key_ignore' }, ['w'] = { name = '[W]orkspace', _ = 'which_key_ignore' }, ['t'] = { name = '[T]oggle', _ = 'which_key_ignore' }, ['h'] = { name = 'Git [H]unk', _ = 'which_key_ignore' }, } -- visual mode require('which-key').register({ ['h'] = { 'Git [H]unk' }, }, { mode = 'v' }) end, }, { 'nvim-telescope/telescope.nvim', event = 'VimEnter', branch = '0.1.x', dependencies = { 'nvim-lua/plenary.nvim', { -- If encountering errors, see telescope-fzf-native README for installation instructions 'nvim-telescope/telescope-fzf-native.nvim', -- `build` is used to run some command when the plugin is installed/updated. -- This is only run then, not every time Neovim starts up. build = 'make', -- `cond` is a condition used to determine whether this plugin should be -- installed and loaded. cond = function() return vim.fn.executable 'make' == 1 end, }, -- TODO -- Test later -- { 'nvim-telescope/telescope-ui-select.nvim' }, { 'nvim-tree/nvim-web-devicons' }, }, config = function() require('telescope').setup { pickers = {}, defaults = { mappings = { i = { [''] = require('telescope.actions').close, [''] = require('telescope.actions').move_selection_next, [''] = require('telescope.actions').move_selection_previous, }, }, }, } pcall(require('telescope').load_extension, 'fzf') local builtin = require 'telescope.builtin' vim.keymap.set('n', '', builtin.find_files, { desc = '[S]earch [F]iles' }) vim.keymap.set('n', 'f', builtin.live_grep, { desc = '[S]earch by [G]rep' }) vim.keymap.set('n', 'sh', builtin.help_tags, { desc = '[S]earch [H]elp' }) vim.keymap.set('n', 'sk', builtin.keymaps, { desc = '[S]earch [K]eymaps' }) vim.keymap.set('n', 'ss', builtin.builtin, { desc = '[S]earch [S]elect Telescope' }) vim.keymap.set('n', 'sw', builtin.grep_string, { desc = '[S]earch current [W]ord' }) vim.keymap.set('n', 'sd', builtin.diagnostics, { desc = '[S]earch [D]iagnostics' }) vim.keymap.set('n', 'sr', builtin.resume, { desc = '[S]earch [R]esume' }) vim.keymap.set('n', 's.', builtin.oldfiles, { desc = '[S]earch Recent Files ("." for repeat)' }) vim.keymap.set('n', 'b', builtin.buffers, { desc = 'Find existing buffers' }) vim.keymap.set('n', 'sn', function() builtin.find_files { cwd = vim.fn.stdpath 'config' } end, { desc = '[S]earch [N]eovim files' }) end, }, { 'neovim/nvim-lspconfig', dependencies = { { 'williamboman/mason.nvim', config = true }, 'williamboman/mason-lspconfig.nvim', 'WhoIsSethDaniel/mason-tool-installer.nvim', { 'folke/neodev.nvim', opts = {} }, }, config = function() vim.api.nvim_create_autocmd('LspAttach', { group = vim.api.nvim_create_augroup('lsp-attach-group', { clear = true }), callback = function(event) local map = function(keys, func, desc) vim.keymap.set('n', keys, func, { buffer = event.buf, desc = 'LSP: ' .. desc }) end map('gd', require('telescope.builtin').lsp_definitions, '[G]oto [D]efinition') map('gr', require('telescope.builtin').lsp_references, '[G]oto [R]eferences') map('gI', require('telescope.builtin').lsp_implementations, '[G]oto [I]mplementation') map('D', require('telescope.builtin').lsp_type_definitions, 'Type [D]efinition') map('ds', require('telescope.builtin').lsp_document_symbols, '[D]ocument [S]ymbols') map('ws', require('telescope.builtin').lsp_dynamic_workspace_symbols, '[W]orkspace [S]ymbols') map('rn', vim.lsp.buf.rename, '[R]e[n]ame') map('ca', vim.lsp.buf.code_action, '[C]ode [A]ction') map('K', vim.lsp.buf.hover, 'Hover Documentation') map('gD', vim.lsp.buf.declaration, '[G]oto [D]eclaration') -- The following two autocommands are used to highlight references of the -- word under your cursor when your cursor rests there for a little while. -- See `:help CursorHold` for information about when this is executed -- -- When you move your cursor, the highlights will be cleared (the second autocommand). local client = vim.lsp.get_client_by_id(event.data.client_id) if client and client.server_capabilities.documentHighlightProvider then local highlight_augroup = vim.api.nvim_create_augroup('kickstart-lsp-highlight', { clear = false }) vim.api.nvim_create_autocmd({ 'CursorHold', 'CursorHoldI' }, { buffer = event.buf, group = highlight_augroup, callback = vim.lsp.buf.document_highlight, }) vim.api.nvim_create_autocmd({ 'CursorMoved', 'CursorMovedI' }, { buffer = event.buf, group = highlight_augroup, callback = vim.lsp.buf.clear_references, }) vim.api.nvim_create_autocmd('LspDetach', { group = vim.api.nvim_create_augroup('kickstart-lsp-detach', { clear = true }), callback = function(event2) vim.lsp.buf.clear_references() vim.api.nvim_clear_autocmds { group = 'kickstart-lsp-highlight', buffer = event2.buf } end, }) end end, }) local capabilities = vim.lsp.protocol.make_client_capabilities() -- capabilities = vim.tbl_deep_extend('force', capabilities, require('cmp_nvim_lsp').default_capabilities()) local servers = { pyright = {}, ruff = {}, gopls = {}, jsonls = {}, ts_ls = {}, -- ccls = {}, lua_ls = {}, } require('mason').setup() -- You can add other tools here that you want Mason to install -- for you, so that they are available from within Neovim. local ensure_installed = vim.tbl_keys(servers or {}) vim.list_extend(ensure_installed, { 'stylua', -- Used to format Lua code { 'terraformls', version = 'v0.34.2' }, }) require('mason-tool-installer').setup { ensure_installed = ensure_installed } require('mason-lspconfig').setup { handlers = { function(server_name) local server = servers[server_name] or {} -- This handles overriding only values explicitly passed -- by the server configuration above. Useful when disabling -- certain features of an LSP (for example, turning off formatting for tsserver) server.capabilities = vim.tbl_deep_extend('force', {}, capabilities, server.capabilities or {}) if server_name == 'terraformls' then local root_pattern = require('lspconfig.util').root_pattern print('Got terraformls', server_name) require('lspconfig')[server_name].setup {} -- require('lspconfig')[server_name].setup { root_dir = root_pattern '.terraformls_root' } else require('lspconfig')[server_name].setup {} end end, }, } end, }, { -- Autoformat 'stevearc/conform.nvim', lazy = false, keys = { { ']', function() require('conform').format { async = true, lsp_fallback = true } end, mode = '', desc = '[F]ormat buffer', }, }, opts = { -- notify_on_error = false, format_on_save = function(bufnr) -- Disable "format_on_save lsp_fallback" for languages that don't -- have a well standardized coding style. You can add additional -- languages here or re-enable it for the disabled ones. local disable_filetypes = { c = true, cpp = true, go = true } return { timeout_ms = 500, lsp_fallback = not disable_filetypes[vim.bo[bufnr].filetype], } end, formatters_by_ft = { lua = { 'stylua' }, python = { 'isort', 'ruff_format' }, -- You can use a sub-list to tell conform to run *until* a formatter -- is found. -- javascript = { { "prettierd", "prettier" } }, }, }, }, { -- Autocompletion 'hrsh7th/nvim-cmp', event = 'InsertEnter', dependencies = { -- Snippet Engine & its associated nvim-cmp source { 'L3MON4D3/LuaSnip', build = 'make install_jsregexp', dependencies = { { 'rafamadriz/friendly-snippets', config = function() require('luasnip.loaders.from_vscode').lazy_load() require 'snippets' end, }, }, }, 'saadparwaiz1/cmp_luasnip', -- Adds other completion capabilities. -- nvim-cmp does not ship with all sources by default. They are split -- into multiple repos for maintenance purposes. 'hrsh7th/cmp-nvim-lsp', 'hrsh7th/cmp-path', }, config = function() -- See `:help cmp` local cmp = require 'cmp' local luasnip = require 'luasnip' luasnip.config.setup {} local kind_icons = { Text = '', Method = 'm', Function = '', Constructor = '', Field = '', Variable = '', Class = '', Interface = '', Module = '', Property = '', Unit = '', Value = '', Enum = '', Keyword = '', Snippet = '', Color = '', File = '', Reference = '', Folder = '', EnumMember = '', Constant = '', Struct = '', Event = '', Operator = '', TypeParameter = '', } cmp.setup { snippet = { expand = function(args) luasnip.lsp_expand(args.body) end, }, completion = { completeopt = 'menu,menuone,noinsert' }, -- For an understanding of why these mappings were -- chosen, you will need to read `:help ins-completion` -- -- No, but seriously. Please read `:help ins-completion`, it is really good! mapping = cmp.mapping.preset.insert { [''] = cmp.mapping.select_next_item(), [''] = cmp.mapping.select_prev_item(), [''] = cmp.mapping.scroll_docs(-4), [''] = cmp.mapping.scroll_docs(4), [''] = cmp.mapping.confirm { select = true }, [''] = cmp.mapping.complete {}, -- Think of as moving to the right of your snippet expansion. -- So if you have a snippet that's like: -- function $name($args) -- $body -- end -- -- will move you to the right of each of the expansion locations. -- is similar, except moving you backwards. [''] = cmp.mapping(function() if luasnip.expand_or_locally_jumpable() then luasnip.expand_or_jump() end end, { 'i', 's' }), [''] = cmp.mapping(function() if luasnip.locally_jumpable(-1) then luasnip.jump(-1) end end, { 'i', 's' }), -- For more advanced Luasnip keymaps (e.g. selecting choice nodes, expansion) see: -- https://github.com/L3MON4D3/LuaSnip?tab=readme-ov-file#keymaps }, formatting = { fields = { 'kind', 'abbr', 'menu' }, expandable_indicator = true, format = function(entry, vim_item) -- Kind icons vim_item.kind = string.format('%s', kind_icons[vim_item.kind]) -- vim_item.kind = string.format('%s %s', kind_icons[vim_item.kind], vim_item.kind) -- This concatonates the icons with the name of the item kind vim_item.menu = ({ nvim_lsp = '[LSP]', luasnip = '[Snippet]', buffer = '[Buffer]', path = '[Path]', })[entry.source.name] return vim_item end, }, sources = { { name = 'nvim_lsp' }, { name = 'luasnip' }, { name = 'buffer' }, { name = 'path' }, }, } end, }, { 'echasnovski/mini.nvim', config = function() -- Examples: -- - va) - [V]isually select [A]round [)]paren -- - yinq - [Y]ank [I]nside [N]ext [']quote -- - ci' - [C]hange [I]nside [']quote require('mini.ai').setup { n_lines = 500 } -- Add/delete/replace surroundings (brackets, quotes, etc.) -- -- - saiw) - [S]urround [A]dd [I]nner [W]ord [)]Paren -- - sd' - [S]urround [D]elete [']quotes -- - sr)' - [S]urround [R]eplace [)] ['] require('mini.surround').setup() -- Simple and easy statusline. -- You could remove this setup call if you don't like it, -- and try some other statusline plugin -- local statusline = require 'mini.statusline' -- set use_icons to true if you have a Nerd Font -- statusline.setup { use_icons = true } -- You can configure sections in the statusline by overriding their -- default behavior. For example, here we set the section for -- cursor location to LINE:COLUMN ---@diagnostic disable-next-line: duplicate-set-field -- statusline.section_location = function() -- return '%2l:%-2v' -- end -- Check out: https://github.com/echasnovski/mini.nvim end, }, { 'nyoom-engineering/oxocarbon.nvim', config = function() vim.cmd.colorscheme 'oxocarbon' end, }, require 'plugins.nvimtree', require 'plugins.neogit', require 'plugins.lint', require 'plugins.avante', require 'plugins.chatgpt', require 'plugins.trouble', require 'plugins.markdown-preview', -- { 'github/copilot.vim' }, } -- Need to test -- vim.opt.ignorecase = true -- vim.opt.smartcase = true -- vim.opt.breakindent = true -- vim.opt.updatetime = 250 -- vim.opt.list = true -- vim.opt.listchars = { tab = '» ', trail = '·', nbsp = '␣' }