From 859043b7c61dd68a1843695deaafb46675e9686f Mon Sep 17 00:00:00 2001 From: grimhilt Date: Wed, 28 Feb 2024 17:42:02 +0100 Subject: [PATCH] feat(nvim): new nvim config --- .config/nvim/init.lua | 659 +++++++++++++++++++- .config/nvim/lazy-lock.json | 27 + .config/nvim/lua_back/packer-plugins.lua | 50 ++ .config/nvim/plugin/harpoon.lua | 8 +- .config/nvim/plugin/telescope.lua | 1 - .config/nvim/plugin_old/harpoon.lua | 11 + .config/nvim/plugin_old/lsp.lua | 13 + .config/nvim/plugin_old/packer_compiled.lua | 169 +++++ .config/nvim/plugin_old/telescope.lua | 5 + .config/nvim/plugin_old/treesitter.lua | 35 ++ 10 files changed, 964 insertions(+), 14 deletions(-) create mode 100644 .config/nvim/lazy-lock.json create mode 100644 .config/nvim/lua_back/packer-plugins.lua create mode 100644 .config/nvim/plugin_old/harpoon.lua create mode 100644 .config/nvim/plugin_old/lsp.lua create mode 100644 .config/nvim/plugin_old/packer_compiled.lua create mode 100644 .config/nvim/plugin_old/telescope.lua create mode 100644 .config/nvim/plugin_old/treesitter.lua diff --git a/.config/nvim/init.lua b/.config/nvim/init.lua index 160c89d..230a627 100755 --- a/.config/nvim/init.lua +++ b/.config/nvim/init.lua @@ -1,19 +1,51 @@ -vim.g.mapleader = " " +vim.g.mapleader = ' ' +vim.g.maplocalleader = ' ' vim.o.relativenumber = true +vim.o.colorcolumn = "80" vim.o.number = true vim.o.tabstop = 4 vim.o.softtabstop = 4 vim.o.shiftwidth = 4 vim.o.expandtab = true vim.o.smartindent = true +-- [[ Setting options ]] +-- See `:help vim.o` +-- NOTE: You can change these options as you wish! + +-- Make line numbers default +vim.wo.number = true + +-- Enable mouse mode +vim.o.mouse = 'a' -- Sync clipboard between OS and Neovim. --- See `:help 'clipboard'` +-- Remove this option if you want your OS clipboard to remain independent. +-- See `:help 'clipboard'` vim.o.clipboard = 'unnamedplus' +-- Enable break indent +vim.o.breakindent = true + -- Save undo history vim.o.undofile = true +-- Keep signcolumn on by default +vim.wo.signcolumn = 'yes' + +-- Decrease update time +vim.o.updatetime = 250 +vim.o.timeoutlen = 300 + +-- Set completeopt to have a better completion experience +vim.o.completeopt = 'menuone,noselect' + +-- NOTE: You should make sure your terminal supports this +vim.o.termguicolors = true + +-- [[ Basic Keymaps ]] + +--vim.o.listchars="eol:$" + --vim.keymap.set({"n", "v", "i"}, "", "", {noremap = true}) --ignore case if pattern doesn't contain upper case @@ -25,9 +57,7 @@ vim.o.scrolloff = 8 -- vim.keymap.set("n", "pv", vim.cmd.Ex) - ---clear hightlight -vim.keymap.set("n", "h", ":noh", {noremap=true}) +vim.keymap.set("n", "h", ":noh") --move line shortcut vim.keymap.set("n", "", ":m +1==", {noremap = true}) @@ -61,5 +91,620 @@ vim.keymap.set("n", "fp", ":bprev", {noremap = true}) -- wrap toggle vim.keymap.set("n", "w", function() vim.o.wrap = not vim.o.wrap end, {noremap = true}) -require('packer-plugins') -require('telescope') +--[[ + + - https://learnxinyminutes.com/docs/lua/ + + And then you can explore or search through `:help lua-guide` + - https://neovim.io/doc/user/lua-guide.html +--]] + +-- [[ Install `lazy.nvim` plugin manager ]] +-- https://github.com/folke/lazy.nvim +-- `:help lazy.nvim.txt` for more info +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) + +-- [[ Configure plugins ]] +-- NOTE: Here is where you install your plugins. +-- You can configure plugins using the `config` key. +-- +-- You can also configure plugins after the setup call, +-- as they will be available in your neovim runtime. +require('lazy').setup({ + -- NOTE: First, some plugins that don't require any configuration + + -- Git related plugins + 'tpope/vim-fugitive', + 'tpope/vim-rhubarb', + + -- harpoon + 'nvim-lua/plenary.nvim', + 'ThePrimeagen/harpoon', + + -- Detect tabstop and shiftwidth automatically + 'tpope/vim-sleuth', + + -- NOTE: This is where your plugins related to LSP can be installed. + -- The configuration is done below. Search for lspconfig to find it below. + { + -- LSP Configuration & Plugins + 'neovim/nvim-lspconfig', + dependencies = { + -- Automatically install LSPs to stdpath for neovim + { 'williamboman/mason.nvim', config = true }, + 'williamboman/mason-lspconfig.nvim', + + -- Useful status updates for LSP + -- NOTE: `opts = {}` is the same as calling `require('fidget').setup({})` + { 'j-hui/fidget.nvim', opts = {} }, + + -- Additional lua configuration, makes nvim stuff amazing! + 'folke/neodev.nvim', + }, + }, + + { + -- Autocompletion + 'hrsh7th/nvim-cmp', + dependencies = { + -- Snippet Engine & its associated nvim-cmp source + { + 'L3MON4D3/LuaSnip', + build = (function() + -- Build Step is needed for regex support in snippets + -- This step is not supported in many windows environments + -- Remove the below condition to re-enable on windows + if vim.fn.has 'win32' == 1 then + return + end + return 'make install_jsregexp' + end)(), + }, + 'saadparwaiz1/cmp_luasnip', + + -- Adds LSP completion capabilities + 'hrsh7th/cmp-nvim-lsp', + 'hrsh7th/cmp-path', + + -- Adds a number of user-friendly snippets + 'rafamadriz/friendly-snippets', + }, + }, + + -- auto pair + { + "windwp/nvim-autopairs", + config = function() require("nvim-autopairs").setup {} end + }, + + -- Useful plugin to show you pending keybinds. + { 'folke/which-key.nvim', opts = {} }, + --{ + -- -- Adds git related signs to the gutter, as well as utilities for managing changes + -- 'lewis6991/gitsigns.nvim', + -- opts = { + -- -- See `:help gitsigns.txt` + -- signs = { + -- add = { text = '+' }, + -- change = { text = '~' }, + -- delete = { text = '_' }, + -- topdelete = { text = '‾' }, + -- changedelete = { text = '~' }, + -- }, + -- on_attach = function(bufnr) + -- local gs = package.loaded.gitsigns + + -- local function map(mode, l, r, opts) + -- opts = opts or {} + -- opts.buffer = bufnr + -- vim.keymap.set(mode, l, r, opts) + -- end + + -- -- Navigation + -- map({ 'n', 'v' }, ']c', function() + -- if vim.wo.diff then + -- return ']c' + -- end + -- vim.schedule(function() + -- gs.next_hunk() + -- end) + -- return '' + -- end, { expr = true, desc = 'Jump to next hunk' }) + + -- map({ 'n', 'v' }, '[c', function() + -- if vim.wo.diff then + -- return '[c' + -- end + -- vim.schedule(function() + -- gs.prev_hunk() + -- end) + -- return '' + -- end, { expr = true, desc = 'Jump to previous hunk' }) + + -- -- Actions + -- -- visual mode + -- map('v', 'hs', function() + -- gs.stage_hunk { vim.fn.line '.', vim.fn.line 'v' } + -- end, { desc = 'stage git hunk' }) + -- map('v', 'hr', function() + -- gs.reset_hunk { vim.fn.line '.', vim.fn.line 'v' } + -- end, { desc = 'reset git hunk' }) + -- -- normal mode + -- map('n', 'hs', gs.stage_hunk, { desc = 'git stage hunk' }) + -- map('n', 'hr', gs.reset_hunk, { desc = 'git reset hunk' }) + -- map('n', 'hS', gs.stage_buffer, { desc = 'git Stage buffer' }) + -- map('n', 'hu', gs.undo_stage_hunk, { desc = 'undo stage hunk' }) + -- map('n', 'hR', gs.reset_buffer, { desc = 'git Reset buffer' }) + -- map('n', 'hp', gs.preview_hunk, { desc = 'preview git hunk' }) + -- map('n', 'hb', function() + -- gs.blame_line { full = false } + -- end, { desc = 'git blame line' }) + -- map('n', 'hd', gs.diffthis, { desc = 'git diff against index' }) + -- map('n', 'hD', function() + -- gs.diffthis '~' + -- end, { desc = 'git diff against last commit' }) + + -- -- Toggles + -- map('n', 'tb', gs.toggle_current_line_blame, { desc = 'toggle git blame line' }) + -- map('n', 'td', gs.toggle_deleted, { desc = 'toggle git show deleted' }) + + -- -- Text object + -- map({ 'o', 'x' }, 'ih', ':Gitsigns select_hunk', { desc = 'select git hunk' }) + -- end, + -- }, + --}, + + { + -- Theme inspired by Atom + 'navarasu/onedark.nvim', + priority = 1000, + lazy = false, + config = function() + require('onedark').setup { + -- Set a style preset. 'dark' is default. + style = 'dark', -- dark, darker, cool, deep, warm, warmer, light + } + require('onedark').load() + end, + }, + + -- bar + --{ + -- -- Set lualine as statusline + -- 'nvim-lualine/lualine.nvim', + -- -- See `:help lualine.txt` + -- opts = { + -- options = { + -- icons_enabled = false, + -- theme = 'auto', + -- component_separators = '|', + -- section_separators = '', + -- }, + -- }, + --}, + + -- coloration and indentation + --{ + -- -- Add indentation guides even on blank lines + -- 'lukas-reineke/indent-blankline.nvim', + -- -- Enable `lukas-reineke/indent-blankline.nvim` + -- -- See `:help ibl` + -- main = 'ibl', + -- opts = {}, + --}, + + -- `gcc` - Toggles the current line using linewise comment + -- `gbc` - Toggles the current line using blockwise comment + -- `[count]gcc` - Toggles the number of line given as a prefix-count using linewise + -- `[count]gbc` - Toggles the number of line given as a prefix-count using blockwise + -- `gc[count]{motion}` - (Op-pending) Toggles the region using linewise comment + -- `gb[count]{motion}` - (Op-pending) Toggles the region using blockwise comment + { 'numToStr/Comment.nvim', opts = {} }, + + -- Fuzzy Finder (files, lsp, etc) + { + 'nvim-telescope/telescope.nvim', + branch = '0.1.x', + dependencies = { + 'nvim-lua/plenary.nvim', + -- Fuzzy Finder Algorithm which requires local dependencies to be built. + -- Only load if `make` is available. Make sure you have the system + -- requirements installed. + { + 'nvim-telescope/telescope-fzf-native.nvim', + -- NOTE: If you are having trouble with this installation, + -- refer to the README for telescope-fzf-native for more instructions. + build = 'make', + cond = function() + return vim.fn.executable 'make' == 1 + end, + }, + }, + }, + + { + -- Highlight, edit, and navigate code + 'nvim-treesitter/nvim-treesitter', + dependencies = { + 'nvim-treesitter/nvim-treesitter-textobjects', + }, + build = ':TSUpdate', + }, + + -- NOTE: Next Step on Your Neovim Journey: Add/Configure additional "plugins" for kickstart + -- These are some example plugins that I've included in the kickstart repository. + -- Uncomment any of the lines below to enable them. + -- require 'kickstart.plugins.autoformat', + -- require 'kickstart.plugins.debug', + + -- NOTE: The import below can automatically add your own plugins, configuration, etc from `lua/custom/plugins/*.lua` + -- You can use this folder to prevent any conflicts with this init.lua if you're interested in keeping + -- up-to-date with whatever is in the kickstart repo. + -- Uncomment the following line and add your plugins to `lua/custom/plugins/*.lua` to get going. + -- + -- For additional information see: https://github.com/folke/lazy.nvim#-structuring-your-plugins + -- { import = 'custom.plugins' }, +}, {}) + +-- Keymaps for better default experience +-- See `:help vim.keymap.set()` +vim.keymap.set({ 'n', 'v' }, '', '', { silent = true }) + +-- Remap for dealing with word wrap +vim.keymap.set('n', 'k', "v:count == 0 ? 'gk' : 'k'", { expr = true, silent = true }) +vim.keymap.set('n', 'j', "v:count == 0 ? 'gj' : 'j'", { expr = true, silent = true }) + +-- Diagnostic keymaps +vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, { desc = 'Go to previous diagnostic message' }) +vim.keymap.set('n', ']d', vim.diagnostic.goto_next, { desc = 'Go to next diagnostic message' }) +vim.keymap.set('n', 'e', vim.diagnostic.open_float, { desc = 'Open floating diagnostic message' }) +vim.keymap.set('n', 'd', vim.diagnostic.setloclist, { desc = 'Open diagnostics list' }) + +-- [[ Highlight on yank ]] +-- See `:help vim.highlight.on_yank()` +--local highlight_group = vim.api.nvim_create_augroup('YankHighlight', { clear = true }) +--vim.api.nvim_create_autocmd('TextYankPost', { +-- callback = function() +-- vim.highlight.on_yank() +-- end, +-- group = highlight_group, +-- pattern = '*', +--}) + +-- [[ Configure Telescope ]] +-- See `:help telescope` and `:help telescope.setup()` +require('telescope').setup { + defaults = { + mappings = { + i = { + [''] = false, + [''] = false, + }, + }, + }, +} + +-- Enable telescope fzf native, if installed +pcall(require('telescope').load_extension, 'fzf') + +-- Telescope live_grep in git root +-- Function to find the git root directory based on the current buffer's path +local function find_git_root() + -- Use the current buffer's path as the starting point for the git search + local current_file = vim.api.nvim_buf_get_name(0) + local current_dir + local cwd = vim.fn.getcwd() + -- If the buffer is not associated with a file, return nil + if current_file == '' then + current_dir = cwd + else + -- Extract the directory from the current file's path + current_dir = vim.fn.fnamemodify(current_file, ':h') + end + + -- Find the Git root directory from the current file's path + local git_root = vim.fn.systemlist('git -C ' .. vim.fn.escape(current_dir, ' ') .. ' rev-parse --show-toplevel')[1] + if vim.v.shell_error ~= 0 then + print 'Not a git repository. Searching on current working directory' + return cwd + end + return git_root +end + +-- Custom live_grep function to search in git root +local function live_grep_git_root() + local git_root = find_git_root() + if git_root then + require('telescope.builtin').live_grep { + search_dirs = { git_root }, + } + end +end + +vim.api.nvim_create_user_command('LiveGrepGitRoot', live_grep_git_root, {}) + +-- See `:help telescope.builtin` +vim.keymap.set('n', '?', require('telescope.builtin').oldfiles, { desc = '[?] Find recently opened files' }) +vim.keymap.set('n', '', require('telescope.builtin').buffers, { desc = '[ ] Find existing buffers' }) +vim.keymap.set('n', '/', function() + -- You can pass additional configuration to telescope to change theme, layout, etc. + require('telescope.builtin').current_buffer_fuzzy_find(require('telescope.themes').get_dropdown { + winblend = 10, + previewer = false, + }) +end, { desc = '[/] Fuzzily search in current buffer' }) + +local function telescope_live_grep_open_files() + require('telescope.builtin').live_grep { + grep_open_files = true, + prompt_title = 'Live Grep in Open Files', + } +end +vim.keymap.set('n', 's/', telescope_live_grep_open_files, { desc = '[S]earch [/] in Open Files' }) +vim.keymap.set('n', 'ss', require('telescope.builtin').builtin, { desc = '[S]earch [S]elect Telescope' }) +vim.keymap.set('n', 'gf', require('telescope.builtin').git_files, { desc = 'Search [G]it [F]iles' }) +vim.keymap.set('n', 'sf', require('telescope.builtin').find_files, { desc = '[S]earch [F]iles' }) +vim.keymap.set('n', 'sh', require('telescope.builtin').help_tags, { desc = '[S]earch [H]elp' }) +vim.keymap.set('n', 'sw', require('telescope.builtin').grep_string, { desc = '[S]earch current [W]ord' }) +vim.keymap.set('n', 'sg', require('telescope.builtin').live_grep, { desc = '[S]earch by [G]rep' }) +vim.keymap.set('n', 'sG', ':LiveGrepGitRoot', { desc = '[S]earch by [G]rep on Git Root' }) +vim.keymap.set('n', 'sd', require('telescope.builtin').diagnostics, { desc = '[S]earch [D]iagnostics' }) +vim.keymap.set('n', 'sr', require('telescope.builtin').resume, { desc = '[S]earch [R]esume' }) + +-- [[ Configure Treesitter ]] +-- See `:help nvim-treesitter` +-- Defer Treesitter setup after first render to improve startup time of 'nvim {filename}' +vim.defer_fn(function() + 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', 'javascript', 'typescript', 'vimdoc', 'vim', 'bash' }, + + -- Autoinstall languages that are not installed. Defaults to false (but you can change for yourself!) + auto_install = false, + -- Install languages synchronously (only applied to `ensure_installed`) + sync_install = false, + -- List of parsers to ignore installing + ignore_install = {}, + -- You can specify additional Treesitter modules here: -- For example: -- playground = {--enable = true,-- }, + modules = {}, + 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_next_end = { + [']M'] = '@function.outer', + [']['] = '@class.outer', + }, + goto_previous_start = { + ['[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', + }, + }, + }, + } +end, 0) + +-- [[ Configure LSP ]] +-- This function gets run when an LSP connects to a particular buffer. +local on_attach = function(_, bufnr) + -- NOTE: Remember that lua is a real programming language, and as such it is possible + -- to define small helper and utility functions so you don't have to repeat yourself + -- many times. + -- + -- In this case, we create a function that lets us more easily define mappings specific + -- for LSP related items. It sets the mode, buffer and description for us each time. + 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, '[R]e[n]ame') + nmap('ca', function() + vim.lsp.buf.code_action { context = { only = { 'quickfix', 'refactor', 'source' } } } + end, '[C]ode [A]ction') + + nmap('gd', require('telescope.builtin').lsp_definitions, '[G]oto [D]efinition') + nmap('gr', require('telescope.builtin').lsp_references, '[G]oto [R]eferences') + nmap('gI', require('telescope.builtin').lsp_implementations, '[G]oto [I]mplementation') + nmap('D', require('telescope.builtin').lsp_type_definitions, 'Type [D]efinition') + nmap('ds', require('telescope.builtin').lsp_document_symbols, '[D]ocument [S]ymbols') + nmap('ws', require('telescope.builtin').lsp_dynamic_workspace_symbols, '[W]orkspace [S]ymbols') + + -- See `:help K` for why this keymap + nmap('K', vim.lsp.buf.hover, 'Hover Documentation') + nmap('', vim.lsp.buf.signature_help, 'Signature Documentation') + + -- Lesser used LSP functionality + nmap('gD', vim.lsp.buf.declaration, '[G]oto [D]eclaration') + nmap('wa', vim.lsp.buf.add_workspace_folder, '[W]orkspace [A]dd Folder') + nmap('wr', vim.lsp.buf.remove_workspace_folder, '[W]orkspace [R]emove Folder') + nmap('wl', function() + print(vim.inspect(vim.lsp.buf.list_workspace_folders())) + end, '[W]orkspace [L]ist Folders') + + -- 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 + +-- document existing key chains +require('which-key').register { + ['c'] = { name = '[C]ode', _ = 'which_key_ignore' }, + ['d'] = { name = '[D]ocument', _ = 'which_key_ignore' }, + ['g'] = { name = '[G]it', _ = 'which_key_ignore' }, + ['h'] = { name = 'Git [H]unk', _ = 'which_key_ignore' }, + ['r'] = { name = '[R]ename', _ = 'which_key_ignore' }, + ['s'] = { name = '[S]earch', _ = 'which_key_ignore' }, + ['t'] = { name = '[T]oggle', _ = 'which_key_ignore' }, + ['w'] = { name = '[W]orkspace', _ = 'which_key_ignore' }, +} +-- register which-key VISUAL mode +-- required for visual hs (hunk stage) to work +require('which-key').register({ + [''] = { name = 'VISUAL ' }, + ['h'] = { 'Git [H]unk' }, +}, { mode = 'v' }) + +-- mason-lspconfig requires that these setup functions are called in this order +-- before setting up the servers. +require('mason').setup() +require('mason-lspconfig').setup() + +-- Enable the following language servers +-- Feel free to add/remove any LSPs that you want here. They will automatically be installed. +-- +-- Add any additional override configuration in the following tables. They will be passed to +-- the `settings` field of the server config. You must look up that documentation yourself. +-- +-- If you want to override the default filetypes that your language server will attach to you can +-- define the property 'filetypes' to the map in question. +local servers = { + clangd = {}, + -- gopls = {}, + -- pyright = {}, + -- rust_analyzer = {}, + -- tsserver = {}, + -- html = { filetypes = { 'html', 'twig', 'hbs'} }, + + lua_ls = { + Lua = { + workspace = { checkThirdParty = false }, + telemetry = { enable = false }, + -- NOTE: toggle below to ignore Lua_LS's noisy `missing-fields` warnings + -- diagnostics = { disable = { 'missing-fields' } }, + }, + }, +} + +-- Setup neovim lua configuration +require('neodev').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], + filetypes = (servers[server_name] or {}).filetypes, + } + end, +} + +-- [[ Configure nvim-cmp ]] +-- See `:help cmp` +local cmp = require 'cmp' +local luasnip = require 'luasnip' +require('luasnip.loaders.from_vscode').lazy_load() +luasnip.config.setup {} + +cmp.setup { + snippet = { + expand = function(args) + luasnip.lsp_expand(args.body) + end, + }, + completion = { + completeopt = 'menu,menuone,noinsert', + }, + 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.complete {}, + [''] = cmp.mapping.confirm { + behavior = cmp.ConfirmBehavior.Replace, + select = true, + }, + [''] = 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' }, + { name = 'luasnip' }, + { name = 'path' }, + }, +} diff --git a/.config/nvim/lazy-lock.json b/.config/nvim/lazy-lock.json new file mode 100644 index 0000000..d239600 --- /dev/null +++ b/.config/nvim/lazy-lock.json @@ -0,0 +1,27 @@ +{ + "Comment.nvim": { "branch": "master", "commit": "0236521ea582747b58869cb72f70ccfa967d2e89" }, + "LuaSnip": { "branch": "master", "commit": "f3b3d3446bcbfa62d638b1903ff00a78b2b730a1" }, + "cmp-nvim-lsp": { "branch": "main", "commit": "5af77f54de1b16c34b23cba810150689a3a90312" }, + "cmp-path": { "branch": "main", "commit": "91ff86cd9c29299a64f968ebb45846c485725f23" }, + "cmp_luasnip": { "branch": "master", "commit": "05a9ab28b53f71d1aece421ef32fee2cb857a843" }, + "fidget.nvim": { "branch": "main", "commit": "60404ba67044c6ab01894dd5bf77bd64ea5e09aa" }, + "friendly-snippets": { "branch": "main", "commit": "dcd4a586439a1c81357d5b9d26319ae218cc9479" }, + "harpoon": { "branch": "master", "commit": "ccae1b9bec717ae284906b0bf83d720e59d12b91" }, + "lazy.nvim": { "branch": "main", "commit": "28126922c9b54e35a192ac415788f202c3944c9f" }, + "mason-lspconfig.nvim": { "branch": "main", "commit": "21d33d69a81f6351e5a5f49078b2e4f0075c8e73" }, + "mason.nvim": { "branch": "main", "commit": "3b5068f0fc565f337d67a2d315d935f574848ee7" }, + "neodev.nvim": { "branch": "main", "commit": "3157f2e876fd6223d36cfa76bee4709247d62fa5" }, + "nvim-autopairs": { "branch": "master", "commit": "c6139ca0d5ad7af129ea6c89cb4c56093f2c034a" }, + "nvim-cmp": { "branch": "main", "commit": "04e0ca376d6abdbfc8b52180f8ea236cbfddf782" }, + "nvim-lspconfig": { "branch": "master", "commit": "ec7d51a619049c7c597f469f81ea199db6794651" }, + "nvim-treesitter": { "branch": "master", "commit": "fad40f2010c6f50aaad285b2752551a37d8772e4" }, + "nvim-treesitter-textobjects": { "branch": "master", "commit": "7f00d94543f1fd37cab2afa2e9a6cd54e1c6b9ef" }, + "onedark.nvim": { "branch": "master", "commit": "1230aaf2a427b2c5b73aba6e4a9a5881d3e69429" }, + "plenary.nvim": { "branch": "master", "commit": "4f71c0c4a196ceb656c824a70792f3df3ce6bb6d" }, + "telescope-fzf-native.nvim": { "branch": "main", "commit": "6c921ca12321edaa773e324ef64ea301a1d0da62" }, + "telescope.nvim": { "branch": "0.1.x", "commit": "d90956833d7c27e73c621a61f20b29fdb7122709" }, + "vim-fugitive": { "branch": "master", "commit": "2e88f14a585c014691904ba8fe39e6ea851c9422" }, + "vim-rhubarb": { "branch": "master", "commit": "ee69335de176d9325267b0fd2597a22901d927b1" }, + "vim-sleuth": { "branch": "master", "commit": "1cc4557420f215d02c4d2645a748a816c220e99b" }, + "which-key.nvim": { "branch": "main", "commit": "4433e5ec9a507e5097571ed55c02ea9658fb268a" } +} \ No newline at end of file diff --git a/.config/nvim/lua_back/packer-plugins.lua b/.config/nvim/lua_back/packer-plugins.lua new file mode 100644 index 0000000..fc3a6d3 --- /dev/null +++ b/.config/nvim/lua_back/packer-plugins.lua @@ -0,0 +1,50 @@ +return require('packer').startup(function() + use 'wbthomason/packer.nvim' + --use 'sonph/onehalf' + use 'navarasu/onedark.nvim' + require("onedark").setup({ + style = 'cool' + }) + require('onedark').load() + vim.cmd('colorscheme onedark') + + use { + 'nvim-telescope/telescope.nvim', tag = '0.1.1', + -- or , branch = '0.1.x', + requires = { {'nvim-lua/plenary.nvim'} } + } + -- use({ + -- 'rose-pine/neovim', + -- as = 'rose-pine', + -- config = function() + -- vim.cmd('colorscheme rose-pine') + -- end + -- }) + use('nvim-treesitter/nvim-treesitter', {run = ':TSUpdate'}) + use { + 'VonHeikemen/lsp-zero.nvim', + branch = 'v2.x', + requires = { + -- LSP Support + {'neovim/nvim-lspconfig'}, + {'williamboman/mason.nvim', run = function() + pcall(vim.cmd, 'MasonUpdate') + end,}, + {'williamboman/mason-lspconfig.nvim'}, -- Optional + + -- Autocompletion + {'hrsh7th/nvim-cmp'}, -- Required + {'hrsh7th/cmp-nvim-lsp'}, -- Required + {'L3MON4D3/LuaSnip'}, -- Required + } + } + + -- Auto pairs + use { + "windwp/nvim-autopairs", + config = function() require("nvim-autopairs").setup {} end + } + + --harpoon + use("theprimeagen/harpoon") +end) diff --git a/.config/nvim/plugin/harpoon.lua b/.config/nvim/plugin/harpoon.lua index a8ca66f..fcb2fdc 100644 --- a/.config/nvim/plugin/harpoon.lua +++ b/.config/nvim/plugin/harpoon.lua @@ -1,15 +1,11 @@ local mark = require("harpoon.mark") local ui = require("harpoon.ui") -vim.keymap.set("n", "a", mark.add_file) vim.keymap.set("n", "q", mark.add_file) vim.keymap.set("n", "", ui.toggle_quick_menu) -vim.keymap.set("n", "", function() ui.nav_file(1) end) -vim.keymap.set("n", "", function() ui.nav_file(2) end) +vim.keymap.set("n", "", function() ui.nav_file(1) end) +vim.keymap.set("n", "", function() ui.nav_file(2) end) vim.keymap.set("n", "", function() ui.nav_file(3) end) vim.keymap.set("n", "", function() ui.nav_file(4) end) vim.keymap.set("n", "", function() ui.nav_file(5) end) - -vim.keymap.set("n", "", function() ui.nav_file(1) end) -vim.keymap.set("n", "", function() ui.nav_file(2) end) diff --git a/.config/nvim/plugin/telescope.lua b/.config/nvim/plugin/telescope.lua index 8e6332d..93a4dfb 100644 --- a/.config/nvim/plugin/telescope.lua +++ b/.config/nvim/plugin/telescope.lua @@ -2,4 +2,3 @@ local builtin = require('telescope.builtin') vim.keymap.set('n', 'pf', builtin.find_files, {noremap = true}) vim.keymap.set('n', '', builtin.git_files, {noremap = true}) - diff --git a/.config/nvim/plugin_old/harpoon.lua b/.config/nvim/plugin_old/harpoon.lua new file mode 100644 index 0000000..fcb2fdc --- /dev/null +++ b/.config/nvim/plugin_old/harpoon.lua @@ -0,0 +1,11 @@ +local mark = require("harpoon.mark") +local ui = require("harpoon.ui") + +vim.keymap.set("n", "q", mark.add_file) +vim.keymap.set("n", "", ui.toggle_quick_menu) + +vim.keymap.set("n", "", function() ui.nav_file(1) end) +vim.keymap.set("n", "", function() ui.nav_file(2) end) +vim.keymap.set("n", "", function() ui.nav_file(3) end) +vim.keymap.set("n", "", function() ui.nav_file(4) end) +vim.keymap.set("n", "", function() ui.nav_file(5) end) diff --git a/.config/nvim/plugin_old/lsp.lua b/.config/nvim/plugin_old/lsp.lua new file mode 100644 index 0000000..25d389f --- /dev/null +++ b/.config/nvim/plugin_old/lsp.lua @@ -0,0 +1,13 @@ +local lsp = require('lsp-zero').preset({}) + + lsp.on_attach(function(client, bufnr) + local opts = {buffer = bufnr, remap = false} + + vim.keymap.set("n", "gd", function() vim.lsp.buf.definition() end, opts) + end) + +lsp.ensure_installed({ + 'tsserver', + 'eslint' +}) +lsp.setup() diff --git a/.config/nvim/plugin_old/packer_compiled.lua b/.config/nvim/plugin_old/packer_compiled.lua new file mode 100644 index 0000000..1a80e56 --- /dev/null +++ b/.config/nvim/plugin_old/packer_compiled.lua @@ -0,0 +1,169 @@ +-- Automatically generated packer.nvim plugin loader code + +if vim.api.nvim_call_function('has', {'nvim-0.5'}) ~= 1 then + vim.api.nvim_command('echohl WarningMsg | echom "Invalid Neovim version for packer.nvim! | echohl None"') + return +end + +vim.api.nvim_command('packadd packer.nvim') + +local no_errors, error_msg = pcall(function() + +_G._packer = _G._packer or {} +_G._packer.inside_compile = true + +local time +local profile_info +local should_profile = false +if should_profile then + local hrtime = vim.loop.hrtime + profile_info = {} + time = function(chunk, start) + if start then + profile_info[chunk] = hrtime() + else + profile_info[chunk] = (hrtime() - profile_info[chunk]) / 1e6 + end + end +else + time = function(chunk, start) end +end + +local function save_profiles(threshold) + local sorted_times = {} + for chunk_name, time_taken in pairs(profile_info) do + sorted_times[#sorted_times + 1] = {chunk_name, time_taken} + end + table.sort(sorted_times, function(a, b) return a[2] > b[2] end) + local results = {} + for i, elem in ipairs(sorted_times) do + if not threshold or threshold and elem[2] > threshold then + results[i] = elem[1] .. ' took ' .. elem[2] .. 'ms' + end + end + if threshold then + table.insert(results, '(Only showing plugins that took longer than ' .. threshold .. ' ms ' .. 'to load)') + end + + _G._packer.profile_output = results +end + +time([[Luarocks path setup]], true) +local package_path_str = "/home/hugo.meens/.cache/nvim/packer_hererocks/2.1.0-beta3/share/lua/5.1/?.lua;/home/hugo.meens/.cache/nvim/packer_hererocks/2.1.0-beta3/share/lua/5.1/?/init.lua;/home/hugo.meens/.cache/nvim/packer_hererocks/2.1.0-beta3/lib/luarocks/rocks-5.1/?.lua;/home/hugo.meens/.cache/nvim/packer_hererocks/2.1.0-beta3/lib/luarocks/rocks-5.1/?/init.lua" +local install_cpath_pattern = "/home/hugo.meens/.cache/nvim/packer_hererocks/2.1.0-beta3/lib/lua/5.1/?.so" +if not string.find(package.path, package_path_str, 1, true) then + package.path = package.path .. ';' .. package_path_str +end + +if not string.find(package.cpath, install_cpath_pattern, 1, true) then + package.cpath = package.cpath .. ';' .. install_cpath_pattern +end + +time([[Luarocks path setup]], false) +time([[try_loadstring definition]], true) +local function try_loadstring(s, component, name) + local success, result = pcall(loadstring(s), name, _G.packer_plugins[name]) + if not success then + vim.schedule(function() + vim.api.nvim_notify('packer.nvim: Error running ' .. component .. ' for ' .. name .. ': ' .. result, vim.log.levels.ERROR, {}) + end) + end + return result +end + +time([[try_loadstring definition]], false) +time([[Defining packer_plugins]], true) +_G.packer_plugins = { + LuaSnip = { + loaded = true, + path = "/home/hugo.meens/.local/share/nvim/site/pack/packer/start/LuaSnip", + url = "https://github.com/L3MON4D3/LuaSnip" + }, + ["cmp-nvim-lsp"] = { + loaded = true, + path = "/home/hugo.meens/.local/share/nvim/site/pack/packer/start/cmp-nvim-lsp", + url = "https://github.com/hrsh7th/cmp-nvim-lsp" + }, + harpoon = { + loaded = true, + path = "/home/hugo.meens/.local/share/nvim/site/pack/packer/start/harpoon", + url = "https://github.com/theprimeagen/harpoon" + }, + ["lsp-zero.nvim"] = { + loaded = true, + path = "/home/hugo.meens/.local/share/nvim/site/pack/packer/start/lsp-zero.nvim", + url = "https://github.com/VonHeikemen/lsp-zero.nvim" + }, + ["mason-lspconfig.nvim"] = { + loaded = true, + path = "/home/hugo.meens/.local/share/nvim/site/pack/packer/start/mason-lspconfig.nvim", + url = "https://github.com/williamboman/mason-lspconfig.nvim" + }, + ["mason.nvim"] = { + loaded = true, + path = "/home/hugo.meens/.local/share/nvim/site/pack/packer/start/mason.nvim", + url = "https://github.com/williamboman/mason.nvim" + }, + ["nvim-autopairs"] = { + config = { "\27LJ\2\n@\0\0\3\0\3\0\a6\0\0\0'\2\1\0B\0\2\0029\0\2\0004\2\0\0B\0\2\1K\0\1\0\nsetup\19nvim-autopairs\frequire\0" }, + loaded = true, + path = "/home/hugo.meens/.local/share/nvim/site/pack/packer/start/nvim-autopairs", + url = "https://github.com/windwp/nvim-autopairs" + }, + ["nvim-cmp"] = { + loaded = true, + path = "/home/hugo.meens/.local/share/nvim/site/pack/packer/start/nvim-cmp", + url = "https://github.com/hrsh7th/nvim-cmp" + }, + ["nvim-lspconfig"] = { + loaded = true, + path = "/home/hugo.meens/.local/share/nvim/site/pack/packer/start/nvim-lspconfig", + url = "https://github.com/neovim/nvim-lspconfig" + }, + ["nvim-treesitter"] = { + loaded = true, + path = "/home/hugo.meens/.local/share/nvim/site/pack/packer/start/nvim-treesitter", + url = "https://github.com/nvim-treesitter/nvim-treesitter" + }, + ["onedark.nvim"] = { + loaded = true, + path = "/home/hugo.meens/.local/share/nvim/site/pack/packer/start/onedark.nvim", + url = "https://github.com/navarasu/onedark.nvim" + }, + ["packer.nvim"] = { + loaded = true, + path = "/home/hugo.meens/.local/share/nvim/site/pack/packer/start/packer.nvim", + url = "https://github.com/wbthomason/packer.nvim" + }, + ["plenary.nvim"] = { + loaded = true, + path = "/home/hugo.meens/.local/share/nvim/site/pack/packer/start/plenary.nvim", + url = "https://github.com/nvim-lua/plenary.nvim" + }, + ["telescope.nvim"] = { + loaded = true, + path = "/home/hugo.meens/.local/share/nvim/site/pack/packer/start/telescope.nvim", + url = "https://github.com/nvim-telescope/telescope.nvim" + } +} + +time([[Defining packer_plugins]], false) +-- Config for: nvim-autopairs +time([[Config for nvim-autopairs]], true) +try_loadstring("\27LJ\2\n@\0\0\3\0\3\0\a6\0\0\0'\2\1\0B\0\2\0029\0\2\0004\2\0\0B\0\2\1K\0\1\0\nsetup\19nvim-autopairs\frequire\0", "config", "nvim-autopairs") +time([[Config for nvim-autopairs]], false) + +_G._packer.inside_compile = false +if _G._packer.needs_bufread == true then + vim.cmd("doautocmd BufRead") +end +_G._packer.needs_bufread = false + +if should_profile then save_profiles() end + +end) + +if not no_errors then + error_msg = error_msg:gsub('"', '\\"') + vim.api.nvim_command('echohl ErrorMsg | echom "Error in packer_compiled: '..error_msg..'" | echom "Please check your config for correctness" | echohl None') +end diff --git a/.config/nvim/plugin_old/telescope.lua b/.config/nvim/plugin_old/telescope.lua new file mode 100644 index 0000000..8e6332d --- /dev/null +++ b/.config/nvim/plugin_old/telescope.lua @@ -0,0 +1,5 @@ +local builtin = require('telescope.builtin') + +vim.keymap.set('n', 'pf', builtin.find_files, {noremap = true}) +vim.keymap.set('n', '', builtin.git_files, {noremap = true}) + diff --git a/.config/nvim/plugin_old/treesitter.lua b/.config/nvim/plugin_old/treesitter.lua new file mode 100644 index 0000000..a8322c0 --- /dev/null +++ b/.config/nvim/plugin_old/treesitter.lua @@ -0,0 +1,35 @@ +require'nvim-treesitter.configs'.setup { + -- A list of parser names, or "all" (the five listed parsers should always be installed) + ensure_installed = { "javascript", "typescript", "rust", "c", "lua", "vim", "vimdoc", "query" }, + + -- Install parsers synchronously (only applied to `ensure_installed`) + sync_install = false, + + -- Automatically install missing parsers when entering buffer + -- Recommendation: set to false if you don't have `tree-sitter` CLI installed locally + auto_install = true, + + highlight = { + enable = true, + + -- NOTE: these are the names of the parsers and not the filetype. (for example if you want to + -- disable highlighting for the `tex` filetype, you need to include `latex` in this list as this is + -- the name of the parser) + -- list of language that will be disabled + disable = { }, + -- Or use a function for more flexibility, e.g. to disable slow treesitter highlight for large files + disable = function(lang, buf) + local max_filesize = 100 * 1024 -- 100 KB + local ok, stats = pcall(vim.loop.fs_stat, vim.api.nvim_buf_get_name(buf)) + if ok and stats and stats.size > max_filesize then + return true + end + end, + + -- 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 = false, + }, +}