Browse Source

Add nvim configuration

Emmanuel Bouthenot 3 months ago
parent
commit
2e5ed7db48

+ 56 - 0
.config/nvim/after/plugin/lsp.lua

@@ -0,0 +1,56 @@
+--
+-- lsp plugin setup
+--
+
+local lsp_zero = require('lsp-zero')
+lsp_zero.preset('recommended')
+
+lsp_zero.on_attach(function(client, bufnr)
+    -- see :help lsp-zero-keybindings
+    -- to learn the available actions
+    lsp_zero.default_keymaps({buffer = bufnr})
+
+    vim.keymap.set("i", "<C-h>", function() vim.lsp.buf.signature_help() end, opts)
+
+end)
+
+require('mason').setup({})
+require('mason-lspconfig').setup({
+  -- Replace the language servers listed here 
+  -- with the ones you want to install
+  ensure_installed = {'tsserver', 'rust_analyzer'},
+  handlers = {
+    lsp_zero.default_setup,
+    lua_ls = function()
+      local lua_opts = lsp_zero.nvim_lua_ls()
+      require('lspconfig').lua_ls.setup(lua_opts)
+    end,
+  },
+})
+
+local cmp = require('cmp')
+local cmp_action = require('lsp-zero').cmp_action()
+
+cmp.setup({
+  sources = {
+    {name = 'nvim_lsp'},
+    {name = 'buffer'},
+    {name = 'path'},
+  },
+  window = {
+    completion = cmp.config.window.bordered(),
+    documentation = cmp.config.window.bordered(),
+  },
+  mapping = cmp.mapping.preset.insert({
+      ['<C-p>'] = cmp.mapping.complete(),
+      ['<C-f>'] = cmp_action.luasnip_jump_forward(),
+      ['<C-b>'] = cmp_action.luasnip_jump_backward(),
+      ['<C-u>'] = cmp.mapping.scroll_docs(-4),
+       ["<CR>"] = cmp.mapping.confirm({
+         behavior = cmp.ConfirmBehavior.Replace,
+         select = true,
+      }),
+      ["<Tab>"] = cmp.mapping(cmp.mapping.select_next_item(), { "i", "s" }),
+      ["<S-Tab>"] = cmp.mapping(cmp.mapping.select_prev_item(), { "i", "s" }),
+  })  
+})    

+ 5 - 0
.config/nvim/after/plugin/lualine.lua

@@ -0,0 +1,5 @@
+require('lualine').setup {
+    options = {
+        theme = 'auto'
+    },
+}

+ 12 - 0
.config/nvim/after/plugin/nvim-tree.lua

@@ -0,0 +1,12 @@
+--
+-- nvim-tree plugin setup
+--
+
+require('nvim-tree').setup()
+
+nvimtreeapi = require('nvim-tree.api')
+
+vim.keymap.set('n', '<leader>o', function()
+    nvimtreeapi.tree.toggle({ focus = true })
+end,
+{desc = 'Open the file explorer'})

+ 14 - 0
.config/nvim/after/plugin/rose-pine.lua

@@ -0,0 +1,14 @@
+--
+-- rose-pine plugin setup
+--
+
+require('rose-pine').setup {
+    disable_background = true
+}
+
+require("tokyonight").setup({
+  transparent = true
+})
+
+-- vim.cmd.colorscheme('rose-pine')
+vim.cmd.colorscheme('tokyonight-night')

+ 13 - 0
.config/nvim/after/plugin/telescope.lua

@@ -0,0 +1,13 @@
+--
+-- telescope plugin setup
+--
+
+local telescope = require('telescope.builtin')
+
+vim.keymap.set('n', '<leader>ff', telescope.find_files, { desc = "Find files from current working directory" })
+vim.keymap.set('n', '<leader>fg', telescope.git_files, { desc = "Find files from current git repository" })
+vim.keymap.set('n', '<leader>fb', telescope.buffers, { desc = "Find files from buffers" })
+vim.keymap.set('n', '<leader>fr', telescope.registers, { desc = "Find files from registers" })
+vim.keymap.set('n', '<leader>fs', function()
+    telescope.grep_string({ search = vim.fn.input("Grep > ") })
+end, { desc = 'Find in files content from current working directory' })

+ 5 - 0
.config/nvim/after/plugin/undotree.lua

@@ -0,0 +1,5 @@
+--
+-- undotree plugin setup
+--
+
+vim.keymap.set('n', '<leader>u', vim.cmd.UndotreeToggle, { desc = 'Toggle Undo tree' })

+ 12 - 0
.config/nvim/after/plugin/which-key.lua

@@ -0,0 +1,12 @@
+--
+-- which-key plugin setup
+--
+
+require('which-key').setup {
+    layout = {
+        height = {
+            max = 40
+        }
+    }
+}
+

+ 2 - 0
.config/nvim/init.lua

@@ -0,0 +1,2 @@
+require("kolter")
+

+ 52 - 0
.config/nvim/lua/kolter/init.lua

@@ -0,0 +1,52 @@
+require("kolter.set")
+require("kolter.remap")
+
+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)
+
+require("lazy").setup({
+    { 'rose-pine/neovim' },
+    { 'folke/tokyonight.nvim', lazy = false, priority = 1000 },
+    { 'nvim-lua/plenary.nvim' },
+    { 'mbbill/undotree' },
+    { 'nvim-telescope/telescope.nvim', branch = '0.1.x' },
+    { 'nvim-tree/nvim-tree.lua' },
+    { 'nvim-tree/nvim-web-devicons' },
+    { 'nvim-lualine/lualine.nvim' },
+    { 'folke/trouble.nvim' },
+    { 'folke/which-key.nvim', event = 'VeryLazy', init = function()
+            vim.o.timeout = true
+            vim.o.timeoutlen = 300
+        end
+    },
+    { 'VonHeikemen/lsp-zero.nvim', branch = 'v3.x',
+        dependencies = {
+            -- LSP Support
+            { 'neovim/nvim-lspconfig' },
+            {
+                'williamboman/mason.nvim',
+                build = function()
+                    pcall(vim.cmd, 'MasonUpdate')
+                end,
+            },
+            { 'williamboman/mason-lspconfig.nvim' },
+
+            -- Autocompletion
+            { 'hrsh7th/nvim-cmp' },
+            { 'hrsh7th/cmp-nvim-lsp' },
+            { 'L3MON4D3/LuaSnip' },
+        }
+    },
+    { 'nvim-treesitter/nvim-treesitter', build = ':TSUpdate' }
+})
+

+ 2 - 0
.config/nvim/lua/kolter/kolter.remap

@@ -0,0 +1,2 @@
+
+vim.g.mapleader = " "

+ 2 - 0
.config/nvim/lua/kolter/packer.lua

@@ -0,0 +1,2 @@
+
+

+ 27 - 0
.config/nvim/lua/kolter/remap.lua

@@ -0,0 +1,27 @@
+
+--
+-- Keys remapping
+--
+
+vim.g.mapleader = " "  -- Leader key
+
+vim.keymap.set({'n', 'i', 'o'}, '<f1>', '<cmd>bprev<cr>')	-- <F1> to switch to previous buffer
+vim.keymap.set({'n', 'i', 'o'}, '<f2>', '<cmd>bnext<cr>')      	-- <F2> to switch to next buffer
+
+vim.keymap.set({'n', 'i', 'o'}, '<f5>', '<cmd>source %<cr>')  	-- <F5> to reload current file
+
+vim.keymap.set({'n', 'i', 'o'}, '<f6>', '<cmd>vsplit<cr>')     	-- <F6> to split window vertically
+vim.keymap.set({'n', 'i', 'o'}, '<f7>', '<cmd>split<cr>')      	-- <F7> to split window horizontally
+
+vim.keymap.set({'n', 'i', 'o'}, '<c-d>', '<cmd>bwipeout<cr>')  	-- <Ctrl-d> to close the current buffer
+
+vim.keymap.set({'n', 'i', 'o'}, '<c-left>', '<cmd>wincmd h<cr>')  -- <Ctrl-left> move to windows on left
+vim.keymap.set({'n', 'i', 'o'}, '<c-Up>', '<cmd>wincmd k<cr>')    -- <Ctrl-Up> move to windows on top
+vim.keymap.set({'n', 'i', 'o'}, '<c-right>', '<cmd>wincmd l<cr>') -- <Ctrl-right> move to windows on right
+vim.keymap.set({'n', 'i', 'o'}, '<c-Down>', '<cmd>wincmd j<cr>')  -- <Ctrl-Down> move to windows on bottom
+
+vim.keymap.set('v', '>', '>gv')        -- Keep selection while indenting with '>'
+vim.keymap.set('v', '<tab>', '>gv')    -- Keep selection while indenting with <Tab>
+vim.keymap.set('v', '<', '<gv')        -- Keep selection while un-indenting with '<'
+vim.keymap.set('v', '<s-tab>', '<gv')  -- Keep selection while un-indenting with <Shift-Tab>
+

+ 49 - 0
.config/nvim/lua/kolter/set.lua

@@ -0,0 +1,49 @@
+--
+-- General settings
+--
+
+-- vim.opt.autochdir = true -- Switch to the current file directory
+
+--
+-- Backups and swap files
+--
+
+vim.opt.backup = true
+-- vim.opt.backupdir = "~/.cache/nvim/backups"
+-- vim.opt.directory = "~/.cache/nvim/swap"
+
+--
+-- UI settings
+--
+
+vim.opt.title     = true    -- Show title
+vim.opt.number    = true    -- Show line numbers
+vim.opt.ruler     = true    -- Show the line and column number of the cursor postion
+vim.opt.confirm   = true    -- raise a dialog asking what to do instead of failing
+vim.opt.mouse     = ""      -- Disable mouse
+vim.opt.shortmess = "a"     -- Show all abbreviations on status line
+
+--
+-- Editor settings
+--
+
+vim.opt.report = 0 	        -- Agressive reporting
+vim.opt.autoindent = true   -- Copy indent from current line when starting a new line
+vim.opt.smartindent = true  -- Do smart autoindenting when starting a new line.
+
+vim.opt.expandtab = true    -- Convert tabs to space
+vim.opt.tabstop = 4	        -- Number of spaces that a <Tab> in the file counts for
+vim.opt.shiftwidth = 4	    -- Number of spaces to use for each step of (auto)indent
+vim.opt.shiftround = true   -- Round indent to multiple of 'shiftwidth'
+vim.opt.softtabstop = 4     -- Number of spaces that a <Tab> counts for while editing
+vim.opt.showmatch = true    -- When a bracket is inserted, briefly jump to the matching one
+vim.opt.infercase = true    -- Infer case when doing keyword completion
+
+--
+-- Search settings
+--
+
+vim.opt.hlsearch = true	    -- When there is a previous search pattern, highlight the matches
+vim.opt.ignorecase = true   -- Ignore case in search patterns
+
+