nvim config rewrite
Prithu Goswami pg@prithu.dev
Mon, 15 Jul 2024 17:59:17 +0530
18 files changed,
845 insertions(+),
152 deletions(-)
jump to
A
config/nvim-old/init.lua
@@ -0,0 +1,179 @@
+require 'plugins' +require 'options' +require 'keymaps' +require 'completion' +require 'lsp' +require 'highlights' +require 'snippets' +require 'jq' + +-- TODO move each plugin setup to own file +local function nvim_tree_on_attach(bufnr) + local api = require('nvim-tree.api') + local function opts(desc) + return { desc = 'nvim-tree: ' .. desc, buffer = bufnr, noremap = true, silent = true, nowait = true } + end + api.config.mappings.default_on_attach(bufnr) + vim.keymap.set('n', 't', api.node.open.tab, opts('Open: New Tab')) + vim.keymap.set('n', '<C-s>', api.node.open.horizontal, opts('Open: Horizontal Split')) +end + + +-- TODO implement min-width option +local tree_width_ratio = 0.3 +local tree_height_ratio = 0.82014 + +require("nvim-tree").setup({ + on_attach = nvim_tree_on_attach, + sort_by = "case_sensitive", + update_focused_file = { + enable = true, + }, + view = { + centralize_selection = true, + signcolumn = "auto", + float = { + enable = true, + quit_on_focus_loss = true, + open_win_config = function() + local screen_w = vim.opt.columns:get() + local screen_h = vim.opt.lines:get() - vim.opt.cmdheight:get() + local window_w = screen_w * tree_width_ratio + local window_h = screen_h * tree_height_ratio + local window_w_int = math.floor(window_w) + local window_h_int = math.floor(window_h) + local center_x = (screen_w - window_w) / 2 + local center_y = ((vim.opt.lines:get() - window_h) / 2) + - vim.opt.cmdheight:get() + return { + border = "rounded", + relative = "editor", + row = center_y, + col = center_x, + width = window_w_int, + height = window_h_int, + } + end, + }, + width = function() + return math.floor(vim.opt.columns:get() * tree_width_ratio) + end, + }, + filters = { + custom = {"__pycache__"} + }, + diagnostics = { + enable = true + }, + actions = { + open_file = { + window_picker = { + enable = false + }, + }, + }, + renderer = { + indent_markers = { + enable = false + }, + icons = { + show = { + file = false, + folder = false, + }, + git_placement = "before", + glyphs = { + git = { + unstaged = "△", + staged = "✔", + unmerged = "", + renamed = "➜", + untracked = "★", + deleted = "✗", + ignored = "◌", + } + } + } + }, +}) + + +require('telescope').setup { + defaults = { + mappings = { + i = { + ['<Esc>'] = require('telescope.actions').close, + ['<C-j>'] = require('telescope.actions').move_selection_next, + ['<C-k>'] = require('telescope.actions').move_selection_previous, + } + }, + }, + pickers = { + find_files = { + previewer = false, + layout_config = { + width = {0.5, max=80, min=60} + } + }, + buffers = { + previewer = false, + layout_config = { + width = {0.5, max=80, min=60} + } + }, + }, + extensions = { + fzf = { + fuzzy = true, -- false will only do exact matching + override_generic_sorter = true, + override_file_sorter = true, + case_mode = "smart_case", -- or "ignore_case" or "respect_case" + -- the default case_mode is "smart_case" + } + } +} + +require("symbols-outline").setup() + +require('gitblame').setup { + --Note how the `gitblame_` prefix is omitted in `setup` + enabled = false, +} + +require('telescope').load_extension('fzf') + +-- require'nvim-treesitter.configs'.setup { +-- ensure_installed = { "python", "hcl", "json", "go", "lua", "javascript", "typescript", "html", "css", "c", "cpp", "rust" }, +-- sync_install = false, +-- auto_install = true, +-- -- ignore_install = { "javascript" }, +-- highlight = { +-- enable = true, +-- disable = { "help"}, + +-- -- Setting this to true will run `:h syntax` and tree-sitter at the same time. +-- -- Set this to `true` if you depend on 'syntax' being enabled (like for indentation). +-- -- Using this option may slow down your editor, and you may see some duplicate highlights. +-- -- Instead of true it can also be a list of languages +-- additional_vim_regex_highlighting = true, +-- }, +-- indent = { +-- enable = false, +-- disable = {"hcl", "python"} +-- } +-- } + +-- Test runner options +vim.cmd('let test#strategy = "neovim_sticky"') +vim.cmd('let test#neovim#term_position = "vert botright"') + +-- TODO move to seperate autocmd file +vim.cmd ([[ + autocmd FileType html,javascript,lua,typescript,yaml setlocal ts=2 sts=2 sw=2 + autocmd FileType hcl setlocal ts=2 sts=2 sw=2 + autocmd BufRead *jsx setlocal sw=2 + autocmd BufRead *tsx setlocal sw=2 + autocmd FileType markdown setlocal spell +]]) + +vim.cmd('let g:copilot_enabled = 0')
A
config/nvim/.stylua.toml
@@ -0,0 +1,6 @@
+column_width = 160 +line_endings = "Unix" +indent_type = "Spaces" +indent_width = 2 +quote_style = "AutoPreferSingle" +call_parentheses = "None"
M
config/nvim/init.lua
→
config/nvim/init.lua
@@ -1,179 +1,510 @@
-require 'plugins' -require 'options' -require 'keymaps' -require 'completion' -require 'lsp' -require 'highlights' -require 'snippets' -require 'jq' +vim.g.mapleader = ' ' +vim.g.maplocalleader = ' ' --- TODO move each plugin setup to own file -local function nvim_tree_on_attach(bufnr) - local api = require('nvim-tree.api') - local function opts(desc) - return { desc = 'nvim-tree: ' .. desc, buffer = bufnr, noremap = true, silent = true, nowait = true } - end - api.config.mappings.default_on_attach(bufnr) - vim.keymap.set('n', 't', api.node.open.tab, opts('Open: New Tab')) - vim.keymap.set('n', '<C-s>', api.node.open.horizontal, opts('Open: Horizontal Split')) -end +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.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', '<leader>m', '<cmd>nohlsearch<CR>') + +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', '<Esc>') + +-- 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', '<leader>q', vim.diagnostic.setloclist, { desc = 'Open diagnostic [Q]uickfix list' }) + +-- Diagnostics config +local signs = { + { name = 'DiagnosticSignError', text = '' }, + { name = 'DiagnosticSignWarn', text = '' }, + { name = 'DiagnosticSignHint', text = '' }, + { name = 'DiagnosticSignInfo', text = '' }, +} --- TODO implement min-width option -local tree_width_ratio = 0.3 -local tree_height_ratio = 0.82014 +for _, sign in ipairs(signs) do + vim.fn.sign_define(sign.name, { texthl = sign.name, text = sign.text, numhl = '' }) +end -require("nvim-tree").setup({ - on_attach = nvim_tree_on_attach, - sort_by = "case_sensitive", - update_focused_file = { - enable = true, +local config = { + virtual_text = false, + signs = { + active = signs, }, - view = { - centralize_selection = true, - signcolumn = "auto", - float = { - enable = true, - quit_on_focus_loss = true, - open_win_config = function() - local screen_w = vim.opt.columns:get() - local screen_h = vim.opt.lines:get() - vim.opt.cmdheight:get() - local window_w = screen_w * tree_width_ratio - local window_h = screen_h * tree_height_ratio - local window_w_int = math.floor(window_w) - local window_h_int = math.floor(window_h) - local center_x = (screen_w - window_w) / 2 - local center_y = ((vim.opt.lines:get() - window_h) / 2) - - vim.opt.cmdheight:get() - return { - border = "rounded", - relative = "editor", - row = center_y, - col = center_x, - width = window_w_int, - height = window_h_int, - } - end, - }, - width = function() - return math.floor(vim.opt.columns:get() * tree_width_ratio) - end, + update_in_insert = true, + underline = true, + severity_sort = true, + float = { + focusable = false, + style = 'minimal', + border = 'none', + -- max_width = 80, + source = 'always', + header = '', + prefix = '', }, - filters = { - custom = {"__pycache__"} +} +vim.diagnostic.config(config) + +-- Window keymaps +-- See `:help wincmd` for a list of all window commands +vim.keymap.set('n', '<C-h>', '<C-w><C-h>', { desc = 'Move focus to the left window' }) +vim.keymap.set('n', '<C-l>', '<C-w><C-l>', { desc = 'Move focus to the right window' }) +vim.keymap.set('n', '<C-j>', '<C-w><C-j>', { desc = 'Move focus to the lower window' }) +vim.keymap.set('n', '<C-k>', '<C-w><C-k>', { desc = 'Move focus to the upper window' }) + +-- tab navigation +vim.keymap.set('n', 'H', 'gT') +vim.keymap.set('n', 'L', 'gt') + +-- folds +vim.keymap.set('n', '<leader>l', 'za', { desc = 'fold' }) +-- copy to clipbaord in visual mode +vim.keymap.set('v', '<C-c>', '"+y') +-- move blocvim.keymap.sets of text visually +vim.keymap.set('v', 'J', ":m '>+1<CR>gv=gv") +vim.keymap.set('v', 'K', ":m '<-2<CR>gv=gv") +-- stay in visual mode while indenting +vim.keymap.set('v', '>', '>gv') +vim.keymap.set('v', '<', '<gv') +vim.keymap.set('n', 'n', 'nzz') +vim.keymap.set('n', '<C-d>', '<C-d>zz') +vim.keymap.set('n', '<C-u>', '<C-u>zz') + +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 = '~' }, + }, + }, }, - diagnostics = { - enable = true + { + '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 { + ['<leader>c'] = { name = '[C]ode', _ = 'which_key_ignore' }, + ['<leader>d'] = { name = '[D]ocument', _ = 'which_key_ignore' }, + ['<leader>r'] = { name = '[R]ename', _ = 'which_key_ignore' }, + ['<leader>s'] = { name = '[S]earch', _ = 'which_key_ignore' }, + ['<leader>w'] = { name = '[W]orkspace', _ = 'which_key_ignore' }, + ['<leader>t'] = { name = '[T]oggle', _ = 'which_key_ignore' }, + ['<leader>h'] = { name = 'Git [H]unk', _ = 'which_key_ignore' }, + } + -- visual mode + require('which-key').register({ + ['<leader>h'] = { 'Git [H]unk' }, + }, { mode = 'v' }) + end, }, - actions = { - open_file = { - window_picker = { - enable = false + { + '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 = { + ['<Esc>'] = require('telescope.actions').close, + ['<C-j>'] = require('telescope.actions').move_selection_next, + ['<C-k>'] = require('telescope.actions').move_selection_previous, + }, + }, + }, + } + pcall(require('telescope').load_extension, 'fzf') + local builtin = require 'telescope.builtin' + vim.keymap.set('n', '<C-_>', builtin.find_files, { desc = '[S]earch [F]iles' }) + vim.keymap.set('n', '<leader>f', builtin.live_grep, { desc = '[S]earch by [G]rep' }) + vim.keymap.set('n', '<leader>sh', builtin.help_tags, { desc = '[S]earch [H]elp' }) + vim.keymap.set('n', '<leader>sk', builtin.keymaps, { desc = '[S]earch [K]eymaps' }) + vim.keymap.set('n', '<leader>ss', builtin.builtin, { desc = '[S]earch [S]elect Telescope' }) + vim.keymap.set('n', '<leader>sw', builtin.grep_string, { desc = '[S]earch current [W]ord' }) + vim.keymap.set('n', '<leader>sd', builtin.diagnostics, { desc = '[S]earch [D]iagnostics' }) + vim.keymap.set('n', '<leader>sr', builtin.resume, { desc = '[S]earch [R]esume' }) + vim.keymap.set('n', '<leader>s.', builtin.oldfiles, { desc = '[S]earch Recent Files ("." for repeat)' }) + vim.keymap.set('n', '<leader>b', builtin.buffers, { desc = 'Find existing buffers' }) + vim.keymap.set('n', '<leader>sn', function() + builtin.find_files { cwd = vim.fn.stdpath 'config' } + end, { desc = '[S]earch [N]eovim files' }) + end, }, - renderer = { - indent_markers = { - enable = false + { + 'neovim/nvim-lspconfig', + dependencies = { + { 'williamboman/mason.nvim', config = true }, + 'williamboman/mason-lspconfig.nvim', + 'WhoIsSethDaniel/mason-tool-installer.nvim', + { 'folke/neodev.nvim', opts = {} }, }, - icons = { - show = { - file = false, - folder = false, - }, - git_placement = "before", - glyphs = { - git = { - unstaged = "△", - staged = "✔", - unmerged = "", - renamed = "➜", - untracked = "★", - deleted = "✗", - ignored = "◌", - } - } - } - }, -}) + 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('<leader>D', require('telescope.builtin').lsp_type_definitions, 'Type [D]efinition') + map('<leader>ds', require('telescope.builtin').lsp_document_symbols, '[D]ocument [S]ymbols') + map('<leader>ws', require('telescope.builtin').lsp_dynamic_workspace_symbols, '[W]orkspace [S]ymbols') + map('<leader>rn', vim.lsp.buf.rename, '[R]e[n]ame') + map('<leader>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 = {}, + terraformls = {}, + tsserver = {}, + -- 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 + }) + require('mason-tool-installer').setup { ensure_installed = ensure_installed } -require('telescope').setup { - defaults = { - mappings = { - i = { - ['<Esc>'] = require('telescope.actions').close, - ['<C-j>'] = require('telescope.actions').move_selection_next, - ['<C-k>'] = require('telescope.actions').move_selection_previous, + 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 {}) + require('lspconfig')[server_name].setup(server) + end, + }, } - }, + end, }, - pickers = { - find_files = { - previewer = false, - layout_config = { - width = {0.5, max=80, min=60} - } + { -- Autoformat + 'stevearc/conform.nvim', + lazy = false, + keys = { + { + '<leader>]', + function() + require('conform').format { async = true, lsp_fallback = true } + end, + mode = '', + desc = '[F]ormat buffer', + }, }, - buffers = { - previewer = false, - layout_config = { - width = {0.5, max=80, min=60} - } + 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 } + return { + timeout_ms = 500, + lsp_fallback = not disable_filetypes[vim.bo[bufnr].filetype], + } + end, + formatters_by_ft = { + lua = { 'stylua' }, + python = { 'isort', 'black' }, + -- You can use a sub-list to tell conform to run *until* a formatter + -- is found. + -- javascript = { { "prettierd", "prettier" } }, + }, }, }, - extensions = { - fzf = { - fuzzy = true, -- false will only do exact matching - override_generic_sorter = true, - override_file_sorter = true, - case_mode = "smart_case", -- or "ignore_case" or "respect_case" - -- the default case_mode is "smart_case" - } - } -} + { -- 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() + end, + }, + }, + }, + 'saadparwaiz1/cmp_luasnip', -require("symbols-outline").setup() + -- 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 = '', + } -require('gitblame').setup { - --Note how the `gitblame_` prefix is omitted in `setup` - enabled = false, -} + cmp.setup { + snippet = { + expand = function(args) + luasnip.lsp_expand(args.body) + end, + }, + completion = { completeopt = 'menu,menuone,noinsert' }, -require('telescope').load_extension('fzf') + -- 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 { + ['<C-j>'] = cmp.mapping.select_next_item(), + ['<C-k>'] = cmp.mapping.select_prev_item(), + ['<C-b>'] = cmp.mapping.scroll_docs(-4), + ['<C-f>'] = cmp.mapping.scroll_docs(4), + ['<CR>'] = cmp.mapping.confirm { select = true }, + ['<C-Space>'] = cmp.mapping.complete {}, --- require'nvim-treesitter.configs'.setup { --- ensure_installed = { "python", "hcl", "json", "go", "lua", "javascript", "typescript", "html", "css", "c", "cpp", "rust" }, --- sync_install = false, --- auto_install = true, --- -- ignore_install = { "javascript" }, --- highlight = { --- enable = true, --- disable = { "help"}, + -- Think of <c-l> as moving to the right of your snippet expansion. + -- So if you have a snippet that's like: + -- function $name($args) + -- $body + -- end + -- + -- <c-l> will move you to the right of each of the expansion locations. + -- <c-h> is similar, except moving you backwards. + ['<C-l>'] = cmp.mapping(function() + if luasnip.expand_or_locally_jumpable() then + luasnip.expand_or_jump() + end + end, { 'i', 's' }), + ['<C-h>'] = cmp.mapping(function() + if luasnip.locally_jumpable(-1) then + luasnip.jump(-1) + end + end, { 'i', 's' }), --- -- Setting this to true will run `:h syntax` and tree-sitter at the same time. --- -- Set this to `true` if you depend on 'syntax' being enabled (like for indentation). --- -- Using this option may slow down your editor, and you may see some duplicate highlights. --- -- Instead of true it can also be a list of languages --- additional_vim_regex_highlighting = true, --- }, --- indent = { --- enable = false, --- disable = {"hcl", "python"} --- } --- } + -- 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 = '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() --- Test runner options -vim.cmd('let test#strategy = "neovim_sticky"') -vim.cmd('let test#neovim#term_position = "vert botright"') + -- 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 } --- TODO move to seperate autocmd file -vim.cmd ([[ - autocmd FileType html,javascript,lua,typescript,yaml setlocal ts=2 sts=2 sw=2 - autocmd FileType hcl setlocal ts=2 sts=2 sw=2 - autocmd BufRead *jsx setlocal sw=2 - autocmd BufRead *tsx setlocal sw=2 - autocmd FileType markdown setlocal spell -]]) + -- 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', +} -vim.cmd('let g:copilot_enabled = 0') +-- 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 = '␣' }
A
config/nvim/lazy-lock.json
@@ -0,0 +1,29 @@
+{ + "Comment.nvim": { "branch": "master", "commit": "e30b7f2008e52442154b66f7c519bfd2f1e32acb" }, + "LuaSnip": { "branch": "master", "commit": "ce0a05ab4e2839e1c48d072c5236cce846a387bc" }, + "cmp-nvim-lsp": { "branch": "main", "commit": "39e2eda76828d88b773cc27a3f61d2ad782c922d" }, + "cmp-path": { "branch": "main", "commit": "91ff86cd9c29299a64f968ebb45846c485725f23" }, + "cmp_luasnip": { "branch": "master", "commit": "05a9ab28b53f71d1aece421ef32fee2cb857a843" }, + "conform.nvim": { "branch": "master", "commit": "cd75be867f2331b22905f47d28c0c270a69466aa" }, + "diffview.nvim": { "branch": "main", "commit": "4516612fe98ff56ae0415a259ff6361a89419b0a" }, + "friendly-snippets": { "branch": "main", "commit": "00ebcaa159e817150bd83bfe2d51fa3b3377d5c4" }, + "gitsigns.nvim": { "branch": "main", "commit": "e9c4187c3774a46df2d086a66cf3a7e6bea4c432" }, + "lazy.nvim": { "branch": "main", "commit": "b02c9eae6a250f98908c146d1dc1a891f5019f0a" }, + "mason-lspconfig.nvim": { "branch": "main", "commit": "37a336b653f8594df75c827ed589f1c91d91ff6c" }, + "mason-tool-installer.nvim": { "branch": "main", "commit": "c5e07b8ff54187716334d585db34282e46fa2932" }, + "mason.nvim": { "branch": "main", "commit": "f96a31855fa8aea55599cea412fe611b85a874ed" }, + "mini.nvim": { "branch": "main", "commit": "eb19e8442edd63b033c36daf8d29c0158c9f1eb9" }, + "neodev.nvim": { "branch": "main", "commit": "46aa467dca16cf3dfe27098042402066d2ae242d" }, + "neogit": { "branch": "master", "commit": "e33089bb430201a16e5d64e8adc37b99c37e1469" }, + "nvim-cmp": { "branch": "main", "commit": "7e348da6e5085ac447144a2ef4b637220ba27209" }, + "nvim-lint": { "branch": "master", "commit": "efc6fc83f0772283e064c53a8f9fb5645bde0bc0" }, + "nvim-lspconfig": { "branch": "master", "commit": "216deb2d1b5fbf24398919228208649bbf5cbadf" }, + "nvim-tree.lua": { "branch": "master", "commit": "f9ff00bc06d7cb70548a3847d7a2a05e928bc988" }, + "nvim-web-devicons": { "branch": "master", "commit": "c0cfc1738361b5da1cd0a962dd6f774cc444f856" }, + "oxocarbon.nvim": { "branch": "main", "commit": "c5846d10cbe4131cc5e32c6d00beaf59cb60f6a2" }, + "plenary.nvim": { "branch": "master", "commit": "a3e3bc82a3f95c5ed0d7201546d5d2c19b20d683" }, + "telescope-fzf-native.nvim": { "branch": "main", "commit": "cf48d4dfce44e0b9a2e19a008d6ec6ea6f01a83b" }, + "telescope.nvim": { "branch": "0.1.x", "commit": "a0bbec21143c7bc5f8bb02e0005fa0b982edc026" }, + "vim-sleuth": { "branch": "master", "commit": "1cc4557420f215d02c4d2645a748a816c220e99b" }, + "which-key.nvim": { "branch": "main", "commit": "4d5b8959fd2a4df065ff76ccb39019aaa70cb0dc" } +}
A
config/nvim/lua/plugins/lint.lua
@@ -0,0 +1,53 @@
+return { + 'mfussenegger/nvim-lint', + event = { 'BufReadPre', 'BufNewFile' }, + config = function() + local lint = require 'lint' + lint.linters_by_ft = { + python = { 'mypy' }, + terraform = { 'tflint' }, + } + + -- To allow other plugins to add linters to require('lint').linters_by_ft, + -- instead set linters_by_ft like this: + -- lint.linters_by_ft = lint.linters_by_ft or {} + -- lint.linters_by_ft['markdown'] = { 'markdownlint' } + -- + -- However, note that this will enable a set of default linters, + -- which will cause errors unless these tools are available: + -- { + -- clojure = { "clj-kondo" }, + -- dockerfile = { "hadolint" }, + -- inko = { "inko" }, + -- janet = { "janet" }, + -- json = { "jsonlint" }, + -- markdown = { "vale" }, + -- rst = { "vale" }, + -- ruby = { "ruby" }, + -- terraform = { "tflint" }, + -- text = { "vale" } + -- } + -- + -- You can disable the default linters by setting their filetypes to nil: + -- lint.linters_by_ft['clojure'] = nil + -- lint.linters_by_ft['dockerfile'] = nil + -- lint.linters_by_ft['inko'] = nil + -- lint.linters_by_ft['janet'] = nil + -- lint.linters_by_ft['json'] = nil + -- lint.linters_by_ft['markdown'] = nil + -- lint.linters_by_ft['rst'] = nil + -- lint.linters_by_ft['ruby'] = nil + -- lint.linters_by_ft['terraform'] = nil + -- lint.linters_by_ft['text'] = nil + + -- Create autocommand which carries out the actual linting + -- on the specified events. + local lint_augroup = vim.api.nvim_create_augroup('lint', { clear = true }) + vim.api.nvim_create_autocmd({ 'BufEnter', 'BufWritePost', 'InsertLeave' }, { + group = lint_augroup, + callback = function() + require('lint').try_lint() + end, + }) + end, +}
A
config/nvim/lua/plugins/neogit.lua
@@ -0,0 +1,9 @@
+return { + 'NeogitOrg/neogit', + dependencies = { + 'nvim-lua/plenary.nvim', + 'sindrets/diffview.nvim', + 'nvim-telescope/telescope.nvim', + }, + config = true, +}
A
config/nvim/lua/plugins/nvimtree.lua
@@ -0,0 +1,86 @@
+local tree_width_ratio = 0.3 +local tree_height_ratio = 0.82014 + +return { + 'nvim-tree/nvim-tree.lua', + version = '*', + lazy = false, + dependencies = { + 'nvim-tree/nvim-web-devicons', + }, + keys = { + { '<C-n>', '<cmd>NvimTreeToggle<cr>', desc = 'Open File tree' }, + }, + opts = { + -- on_attach = nvim_tree_on_attach, + sort_by = 'case_sensitive', + update_focused_file = { + enable = true, + }, + view = { + centralize_selection = true, + signcolumn = 'auto', + float = { + enable = true, + quit_on_focus_loss = true, + open_win_config = function() + local screen_w = vim.opt.columns:get() + local screen_h = vim.opt.lines:get() - vim.opt.cmdheight:get() + local window_w = screen_w * tree_width_ratio + local window_h = screen_h * tree_height_ratio + local window_w_int = math.floor(window_w) + local window_h_int = math.floor(window_h) + local center_x = (screen_w - window_w) / 2 + local center_y = ((vim.opt.lines:get() - window_h) / 2) - vim.opt.cmdheight:get() + return { + border = 'rounded', + relative = 'editor', + row = center_y, + col = center_x, + width = window_w_int, + height = window_h_int, + } + end, + }, + width = function() + return math.floor(vim.opt.columns:get() * tree_width_ratio) + end, + }, + filters = { + custom = { '__pycache__' }, + }, + diagnostics = { + enable = true, + }, + actions = { + open_file = { + window_picker = { + enable = false, + }, + }, + }, + renderer = { + indent_markers = { + enable = false, + }, + icons = { + show = { + file = false, + folder = false, + }, + git_placement = 'before', + glyphs = { + git = { + unstaged = '△', + staged = '✔', + unmerged = '', + renamed = '➜', + untracked = '★', + deleted = '✗', + ignored = '◌', + }, + }, + }, + }, + }, +}