From 9e278866985bf112ebd26a9ef61c7446262a4800 Mon Sep 17 00:00:00 2001 From: Gregory Trolliet Date: Sat, 19 Oct 2024 11:19:48 +0200 Subject: [PATCH] [nvim] basic config --- .config/nvim/init.lua | 129 +++++++++++++++++++++++ .config/nvim/lua/config/lazy.lua | 13 +++ .config/nvim/lua/plugins/colorscheme.lua | 10 ++ .config/nvim/lua/plugins/devicons.lua | 1 + .config/nvim/lua/plugins/lsp.lua | 11 ++ .config/nvim/lua/plugins/mini.lua | 1 + .config/nvim/lua/plugins/telescope.lua | 5 + .config/nvim/lua/plugins/treesitter.lua | 6 ++ .config/nvim/lua/plugins/whichkey.lua | 18 ++++ 9 files changed, 194 insertions(+) create mode 100644 .config/nvim/init.lua create mode 100644 .config/nvim/lua/config/lazy.lua create mode 100644 .config/nvim/lua/plugins/colorscheme.lua create mode 100644 .config/nvim/lua/plugins/devicons.lua create mode 100644 .config/nvim/lua/plugins/lsp.lua create mode 100644 .config/nvim/lua/plugins/mini.lua create mode 100644 .config/nvim/lua/plugins/telescope.lua create mode 100644 .config/nvim/lua/plugins/treesitter.lua create mode 100644 .config/nvim/lua/plugins/whichkey.lua diff --git a/.config/nvim/init.lua b/.config/nvim/init.lua new file mode 100644 index 0000000..494aed8 --- /dev/null +++ b/.config/nvim/init.lua @@ -0,0 +1,129 @@ +local map = vim.api.nvim_set_keymap + +vim.g.mapleader = " " + +require("config.lazy") +require("lazy").setup({ + spec = { + -- import your plugins + { import = "plugins" }, + }, + -- Configure any other settings here. See the documentation for more details. + -- colorscheme that will be used when installing plugins. + install = { colorscheme = { "habamax" } }, + -- automatically check for plugin updates + checker = { enabled = true }, +}) + +vim.opt.compatible = false -- disable compatibility to old-time vi +vim.opt.showmatch = true -- show matching brackets. +vim.opt.ignorecase = true -- case insensitive matching +vim.opt.cursorline = true -- highlights the current line in the editor +vim.opt.hlsearch = true -- highlight search results +vim.opt.number = true -- add line numbers +vim.opt.relativenumber = true -- display relative line numbers +vim.opt.colorcolumn = '88' -- set colour columns for good coding style +vim.opt.tabstop = 4 -- number of columns occupied by a tab character +vim.opt.shiftwidth = 4 -- width for autoindents +vim.opt.softtabstop = 4 -- see multiple spaces as tabstops so does the right thing + +vim.opt.listchars:append { + eol = "$", + space = "·", + tab = "▏ ", + trail = "_", + nbsp = "~", + extends = ">", + precedes = "<", +} +vim.opt.list = true + +options = { noremap = true } +map('n', 'ff', ':Telescope find_files', options) +map('n', 'fg', ':Telescope git_files', options) +map('n', 'gc', ':Telescope git_commits', options) +map('n', '', ':Telescope buffers', options) +map('n', 't', ':TagbarToggle', options) + +vim.cmd([[ +"set mouse=v " middle-click paste with mouse +"set autoindent " indent a new line the same amount as the line just typed +"set wildmode=longest,list " get bash-like tab completions +"filetype plugin indent on " allows auto-indenting depending on file type +" set expandtab " convert tabs to white space + +" specify directory for plugins +"call plug#begin('~/.config/nvim/plugged') + +"Plug 'echasnovski/mini.icons' +"Plug 'nvim-tree/nvim-web-devicons' +"Plug 'preservim/tagbar' + +"Plug 'rebelot/kanagawa.nvim' + +" Conquer on Completion +" Use release branch (recommended) +"Plug 'neoclide/coc.nvim', {'branch': 'release'} +" initialize plugin system +"call plug#end() + +"colorscheme kanagawa + +" In your init.lua or init.vim +set termguicolors +"lua << EOF +"require("bufferline").setup{} +"EO +]]) + +---------------------------------------------------------------- +-- LSP +---------------------------------------------------- +-- Reserve a space in the gutter +-- This will avoid an annoying layout shift in the screen +vim.opt.signcolumn = 'yes' + +-- Add cmp_nvim_lsp capabilities settings to lspconfig +-- This should be executed before you configure any language server +local lspconfig_defaults = require('lspconfig').util.default_config +lspconfig_defaults.capabilities = vim.tbl_deep_extend( + 'force', + lspconfig_defaults.capabilities, + require('cmp_nvim_lsp').default_capabilities() +) + +-- This is where you enable features that only work +-- if there is a language server active in the file +vim.api.nvim_create_autocmd('LspAttach', { + desc = 'LSP actions', + callback = function(event) + local opts = {buffer = event.buf} + + vim.keymap.set('n', 'K', 'lua vim.lsp.buf.hover()', opts) + vim.keymap.set('n', 'gd', 'lua vim.lsp.buf.definition()', opts) + vim.keymap.set('n', 'gD', 'lua vim.lsp.buf.declaration()', opts) + vim.keymap.set('n', 'gi', 'lua vim.lsp.buf.implementation()', opts) + vim.keymap.set('n', 'go', 'lua vim.lsp.buf.type_definition()', opts) + vim.keymap.set('n', 'gr', 'lua vim.lsp.buf.references()', opts) + vim.keymap.set('n', 'gs', 'lua vim.lsp.buf.signature_help()', opts) + vim.keymap.set('n', '', 'lua vim.lsp.buf.rename()', opts) + vim.keymap.set({'n', 'x'}, '', 'lua vim.lsp.buf.format({async = true})', opts) + vim.keymap.set('n', '', 'lua vim.lsp.buf.code_action()', opts) + end, +}) + +require('lspconfig').clangd.setup({}) + +local cmp = require('cmp') + +cmp.setup({ + sources = { + {name = 'nvim_lsp'}, + }, + snippet = { + expand = function(args) + require('luasnip').lsp_expand(args.body) + end, + }, + mapping = cmp.mapping.preset.insert({}), +}) diff --git a/.config/nvim/lua/config/lazy.lua b/.config/nvim/lua/config/lazy.lua new file mode 100644 index 0000000..14d91f8 --- /dev/null +++ b/.config/nvim/lua/config/lazy.lua @@ -0,0 +1,13 @@ +local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" +if not (vim.uv or 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) + diff --git a/.config/nvim/lua/plugins/colorscheme.lua b/.config/nvim/lua/plugins/colorscheme.lua new file mode 100644 index 0000000..92a97d5 --- /dev/null +++ b/.config/nvim/lua/plugins/colorscheme.lua @@ -0,0 +1,10 @@ +return { + { + "catppuccin/nvim", + name = "catppuccin", + priority = 1000, + config = function() + vim.cmd.colorscheme "catppuccin-macchiato" + end + } +} diff --git a/.config/nvim/lua/plugins/devicons.lua b/.config/nvim/lua/plugins/devicons.lua new file mode 100644 index 0000000..690cd6e --- /dev/null +++ b/.config/nvim/lua/plugins/devicons.lua @@ -0,0 +1 @@ +return { 'nvim-tree/nvim-web-devicons', version = false } diff --git a/.config/nvim/lua/plugins/lsp.lua b/.config/nvim/lua/plugins/lsp.lua new file mode 100644 index 0000000..e45d8d5 --- /dev/null +++ b/.config/nvim/lua/plugins/lsp.lua @@ -0,0 +1,11 @@ +return {{'VonHeikemen/lsp-zero.nvim', branch = 'v4.x'}, + {'neovim/nvim-lspconfig'}, + {'hrsh7th/cmp-nvim-lsp'}, + {'hrsh7th/nvim-cmp'}, + { + "L3MON4D3/LuaSnip", + -- follow latest release. + version = "v2.*", -- Replace by the latest released major (first number of latest release) + -- install jsregexp (optional!). + build = "make install_jsregexp" +}} diff --git a/.config/nvim/lua/plugins/mini.lua b/.config/nvim/lua/plugins/mini.lua new file mode 100644 index 0000000..3496136 --- /dev/null +++ b/.config/nvim/lua/plugins/mini.lua @@ -0,0 +1 @@ +return { 'echasnovski/mini.icons', version = false } diff --git a/.config/nvim/lua/plugins/telescope.lua b/.config/nvim/lua/plugins/telescope.lua new file mode 100644 index 0000000..bf1514a --- /dev/null +++ b/.config/nvim/lua/plugins/telescope.lua @@ -0,0 +1,5 @@ +return { + 'nvim-telescope/telescope.nvim', + tag = '0.1.8', + dependencies = { 'nvim-lua/plenary.nvim' } +} diff --git a/.config/nvim/lua/plugins/treesitter.lua b/.config/nvim/lua/plugins/treesitter.lua new file mode 100644 index 0000000..8c2e44b --- /dev/null +++ b/.config/nvim/lua/plugins/treesitter.lua @@ -0,0 +1,6 @@ +return { + "nvim-treesitter/nvim-treesitter", + build = function() + require("nvim-treesitter.install").update({ with_sync = true })() + end, +} diff --git a/.config/nvim/lua/plugins/whichkey.lua b/.config/nvim/lua/plugins/whichkey.lua new file mode 100644 index 0000000..9fadb97 --- /dev/null +++ b/.config/nvim/lua/plugins/whichkey.lua @@ -0,0 +1,18 @@ +return { + "folke/which-key.nvim", + event = "VeryLazy", + opts = { + -- your configuration comes here + -- or leave it empty to use the default settings + -- refer to the configuration section below + }, + keys = { + { + "?", + function() + require("which-key").show({ global = false }) + end, + desc = "Buffer Local Keymaps (which-key)", + }, + }, +}