commit 02f0def35ebcd8177d03f3b4d06e5163f7fb9424 Author: Yorick Barbanneauwq Date: Tue Mar 14 12:38:15 2023 +0100 first commit diff --git a/README.md b/README.md new file mode 100644 index 0000000..a930c64 --- /dev/null +++ b/README.md @@ -0,0 +1,36 @@ +Neovim configuration +-------------------- + +This is my Neovim configuratio all written in lua, Neovim 8 minimum is required. +For `Tree sitter` working properly, you need `g++` in Debian : + +``` +apt install g++ clang gcc +``` + +Then clone this repository: + +``` +git clone https://git.epha.se/ephase/nvim_config.git ~/.config/nvim +``` + +To install plugins, start nvim in headless mode with `lua/plugins.lua` config +file: + +``` +nvim -u ~/.config/nvim/lua/plugins.lua --headless +``` + +## Keybinding + +Leader key is `space` + +* fm : open file manager +* l : show all caracters (`space`, `tab`, `eol`) +* [ : previous tab +* ] : nest tab +* gn : gitsign - goto next hunk +* gN : gitsign - goto previous hunk +* gs : gitsign - stage hunk +* gr : gitsign - reset hunk +* gd : gitsign - diff diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..1455668 --- /dev/null +++ b/init.lua @@ -0,0 +1,4 @@ +require("plugins") +require("settings") +require("plugins-options") +require("keybiding") diff --git a/lua/keybiding.lua b/lua/keybiding.lua new file mode 100644 index 0000000..1fecc0e --- /dev/null +++ b/lua/keybiding.lua @@ -0,0 +1,28 @@ +-- " Key biding +-- " ---------- +local opts = { noremap = true, silent = true} + +vim.api.nvim_set_keymap('n', '/', ':nohlsearch', opts) + +vim.api.nvim_set_keymap('n', 'fm', + ':NeoTreeFocusToggle', + { table.unpack(opts), desc = 'Toggle NeoTree' } +) + +-- Move tabs with \[ and \] +vim.api.nvim_set_keymap('n', ']', ':tabnext', opts) +vim.api.nvim_set_keymap('n', '[', ':tabprev', opts) +vim.api.nvim_set_keymap('n', 'l', ':set list!', {silent = true}) + +-- Manage Tab +local t = function(str) + return vim.api.nvim_replace_termcodes(str, true, true, true) +end + +-- git sign +-- vim.api.nvim_set_keymap('n', 'gp', require("gitsigns").preview_hunk, opts) +vim.api.nvim_set_keymap('n', 'gn', [[lua require('gitsigns').next_hunk()]], opts) +vim.api.nvim_set_keymap('n', 'gN', [[lua require('gitsigns').prev_hunk()]], opts) +vim.api.nvim_set_keymap('n', 'gs', ':Gitsigns stage_hunk', opts) +vim.api.nvim_set_keymap('n', 'gr', ':Gitsigns reset_hunk', opts) +vim.api.nvim_set_keymap('n', 'gd', [[lua require("gitsigns").diffthis('~')]], opts) diff --git a/lua/plugins-options.lua b/lua/plugins-options.lua new file mode 100644 index 0000000..9107e9f --- /dev/null +++ b/lua/plugins-options.lua @@ -0,0 +1,10 @@ +require('plugins.treesitter') +require('plugins.lsp') +require('plugins.mason') +require('plugins.cmp') +require('plugins.gitsigns') +require('plugins.lualine') +require('plugins.autopairs') +require('plugins.whichkey') +require('plugins.base16') +require('plugins.neotree') diff --git a/lua/plugins.lua b/lua/plugins.lua new file mode 100644 index 0000000..cd03466 --- /dev/null +++ b/lua/plugins.lua @@ -0,0 +1,71 @@ +local function clone_paq() + local path = vim.fn.stdpath("data") .. "/site/pack/paqs/start/paq-nvim" + local is_installed = vim.fn.empty(vim.fn.glob(path)) == 0 + if not is_installed then + vim.fn.system { "git", "clone", "--depth=1", "https://github.com/savq/paq-nvim.git", path } + return true + end +end + +local pkgs = { + "savq/paq-nvim"; + + -- need to install g++ package on Debian + -- for tree sitter plugins + 'nvim-treesitter/nvim-treesitter'; + + -- LSP installer + 'neovim/nvim-lspconfig'; + + -- ui elements + 'MunifTanjim/nui.nvim'; + 'nvim-lua/plenary.nvim'; + + -- status bar + 'nvim-lualine/lualine.nvim'; + + -- Base16 theme + 'RRethy/nvim-base16'; + + -- file manager + 'nvim-neo-tree/neo-tree.nvim'; + + -- git integration + 'lewis6991/gitsigns.nvim'; + + + -- Mason is a GUI to install language servers and lspconfig is a bridge + -- between mason and nvim-lspconfig + 'williamboman/mason.nvim'; + 'williamboman/mason-lspconfig.nvim'; + + -- autocompletion plugin + 'hrsh7th/nvim-cmp'; + 'hrsh7th/cmp-nvim-lsp'; -- LSP source + 'hrsh7th/cmp-path'; -- path source + 'hrsh7th/cmp-buffer'; -- buffer + 'L3MON4D3/LuaSnip'; -- snippet engine + 'saadparwaiz1/cmp_luasnip'; + + -- autopair + 'windwp/nvim-autopairs'; + + -- indent guide + 'lukas-reineke/indent-blankline.nvim'; + + -- windows popup with keys + 'folke/which-key.nvim'; +} + +if clone_paq() then + vim.cmd('packadd paq-nvim') + local paq = require('paq') + -- Exit nvim after installing plugins + vim.cmd('autocmd User PaqDoneInstall quit') + -- Read and install packages + paq(pkgs) + paq.install() +end + +local paq = require("paq") +paq(pkgs) diff --git a/lua/plugins/autopairs.lua b/lua/plugins/autopairs.lua new file mode 100644 index 0000000..926f47a --- /dev/null +++ b/lua/plugins/autopairs.lua @@ -0,0 +1 @@ +local autopair = require("nvim-autopairs").setup {} diff --git a/lua/plugins/base16.lua b/lua/plugins/base16.lua new file mode 100644 index 0000000..8267c8b --- /dev/null +++ b/lua/plugins/base16.lua @@ -0,0 +1 @@ +vim.cmd.colorscheme 'base16-default-dark' diff --git a/lua/plugins/cmp.lua b/lua/plugins/cmp.lua new file mode 100644 index 0000000..76c6516 --- /dev/null +++ b/lua/plugins/cmp.lua @@ -0,0 +1,84 @@ +local has_words_before = function() + unpack = unpack or table.unpack + local line, col = unpack(vim.api.nvim_win_get_cursor(0)) + return col ~= 0 and vim.api.nvim_buf_get_lines( + 0, + line - 1, + line, + true + )[1]:sub(col, col):match('%s') == nil +end + +-- Add additional capabilities supported by nvim-cmp +local capabilities = require('cmp_nvim_lsp').default_capabilities() +local luasnip = require("luasnip") + +local kind_icons = { + Text = "", + Method = "", + Function = "", + Constructor = "", + Field = "", + Variable = "", + Class = "ﴯ", + Interface = "", + Module = "", + Property = "ﰠ", + Unit = "", + Value = "", + Enum = "", + Keyword = "", + Snippet = "", + Color = "", + File = "", + Reference = "", + Folder = "", + EnumMember = "", + Constant = "", + Struct = "", + Event = "", + Operator = "", + TypeParameter = "" +} + +-- nvim-cmp setup +local cmp = require 'cmp' +cmp.setup { + mapping = { + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + -- You could replace the expand_or_jumpable() calls with expand_or_locally_jumpable() + -- they way you will only jump inside the snippet region + elseif luasnip.expand_or_jumpable() then + luasnip.expand_or_jump() + elseif has_words_before() then + cmp.complete() + else + fallback() + end + end, { "i", "s" }), + + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_prev_item() + elseif luasnip.jumpable(-1) then + luasnip.jump(-1) + else + fallback() + end + end, { "i", "s" }), + }, + formatting = { + format = function(_, vim_item) + vim_item.kind = string.format('%s %s', kind_icons[vim_item.kind], vim_item.kind) + return vim_item + end, + }, + sources = { + { name = 'nvim_lsp' }, + { name = 'luasnip' }, + { name = 'path' }, + { name = 'buffer' }, + }, +} diff --git a/lua/plugins/gitsigns.lua b/lua/plugins/gitsigns.lua new file mode 100644 index 0000000..7253a57 --- /dev/null +++ b/lua/plugins/gitsigns.lua @@ -0,0 +1,3 @@ +require('gitsigns').setup { + keymaps = {}, -- NO default keybindings +} diff --git a/lua/plugins/lsp.lua b/lua/plugins/lsp.lua new file mode 100644 index 0000000..7c9834f --- /dev/null +++ b/lua/plugins/lsp.lua @@ -0,0 +1 @@ +local lspconfig = require('lspconfig') diff --git a/lua/plugins/lualine.lua b/lua/plugins/lualine.lua new file mode 100644 index 0000000..1748764 --- /dev/null +++ b/lua/plugins/lualine.lua @@ -0,0 +1,29 @@ +require('lualine').setup { + options = { + icons_enabled = true, + theme = 'base16', + component_separators = { left = '|', right = '|'}, + section_separators = { left = '', right = ''}, + disabled_filetypes = {}, + always_divide_middle = true, + globalstatus = true, + }, + sections = { + lualine_a = {'mode'}, + lualine_b = {'branch', 'diff', 'diagnostics'}, + lualine_c = {'filename'}, + lualine_x = {'encoding', 'fileformat', 'filetype'}, + lualine_y = {'progress'}, + lualine_z = {'location'} + }, + inactive_sections = { + lualine_a = {}, + lualine_b = {}, + lualine_c = {'filename'}, + lualine_x = {'location'}, + lualine_y = {}, + lualine_z = {} + }, + tabline = {}, + extensions = {} +} diff --git a/lua/plugins/mason.lua b/lua/plugins/mason.lua new file mode 100644 index 0000000..cf2dcad --- /dev/null +++ b/lua/plugins/mason.lua @@ -0,0 +1,25 @@ +local mason = require("mason").setup{ + ensure_installed= { + 'shellcheck', + 'shfmt' + } +} +local mason_lspconfig = require("mason-lspconfig").setup{ + ensure_installed={ + 'ansiblels', + 'bashls' + + } +} + + +require("mason-lspconfig").setup_handlers({ + -- The first entry (without a key) will be the default handler + -- and will be called for each installed server that doesn't have + -- a dedicated handler. + function (server_name) -- default handler (optional) + require("lspconfig")[server_name].setup {} + end, + -- Next, you can provide targeted overrides for specific servers. + -- +}) diff --git a/lua/plugins/neotree.lua b/lua/plugins/neotree.lua new file mode 100644 index 0000000..beb0786 --- /dev/null +++ b/lua/plugins/neotree.lua @@ -0,0 +1,13 @@ +local neotree = require 'neo-tree' + +neotree.setup({ + event_handlers = { + { + event = "file_opened", + handler = function(file_path) + --auto close + require("neo-tree").close_all() + end + }, + } +}) diff --git a/lua/plugins/treesitter.lua b/lua/plugins/treesitter.lua new file mode 100644 index 0000000..4e5b835 --- /dev/null +++ b/lua/plugins/treesitter.lua @@ -0,0 +1,22 @@ +-- Tree sitter +local ts = require 'nvim-treesitter.configs' + +ts.setup { + ensure_installed = { + 'bash', + 'c', + 'cmake', + 'dockerfile', + 'latex', + 'lua', + 'markdown', + 'markdown_inline', + 'python', + 'yaml' + }, + sync_install = false, + highlight = { + enable = true, + additional_vim_regex_highlighting = false, + } +} diff --git a/lua/plugins/whichkey.lua b/lua/plugins/whichkey.lua new file mode 100644 index 0000000..9271746 --- /dev/null +++ b/lua/plugins/whichkey.lua @@ -0,0 +1,2 @@ +local wk = require 'which-key' +wk.register() diff --git a/lua/settings.lua b/lua/settings.lua new file mode 100644 index 0000000..11b72ff --- /dev/null +++ b/lua/settings.lua @@ -0,0 +1,92 @@ +-- General Option + +vim.g.mapleader = " " +vim.g.maplocalleader = " " + +vim.opt.autoindent = true +vim.opt.background = 'dark' +vim.opt.backupdir = os.getenv("HOME") .. '/.local/tmp/nvim' +vim.opt.clipboard = 'unnamedplus' --Use system clipboard +vim.opt.colorcolumn = '80' +vim.opt.directory = os.getenv("HOME") .. '/.local/tmp/nvim' +vim.opt.expandtab = true +vim.opt.foldmethod = 'syntax' +vim.opt.gdefault = true -- search: all occurrences by default +vim.opt.hlsearch = true -- search: hightlight terms +vim.opt.ignorecase = true +vim.opt.incsearch = true +vim.opt.laststatus = 1 +-- show special character +vim.opt.listchars = {tab = '→ ', trail = '␣', eol = '', extends = '…' } + +vim.opt.signcolumn = "yes" -- alway show sign column +vim.opt.number = true +vim.opt.relativenumber = true +vim.opt.cursorline = true -- highlight current line +vim.opt.shiftwidth = 4 +vim.opt.showmatch = true +vim.opt.smartcase = true -- search: try :to be smart about cases +vim.opt.smartindent = true +vim.opt.tabstop = 4 +vim.opt.termguicolors = true -- 24 bits color support +vim.opt.wildmenu = true -- activate enhanced user menu +vim.opt.wildmode = 'lastused:full,list' -- enhance menu +vim.opt.pumheight = 10 +vim.opt.pumwidth = 50 +vim.opt.pumblend = 10 + +-- Options than need vim.cmd +-- vim.cmd('syntax on') + +-- -- Code Fold +-- "Load and save view atomatocally (save and restore fold) +vim.cmd('au BufWinLeave *.* mkview') +vim.cmd('au BufWinEnter *.* silent! loadview') + + +-- Diagnostic settings +-- +-- diagnostic windows must be float +vim.diagnostic.config { + virtual_text = false, + signs = true, + underline = true, +} + +local signs = { Error = " ", Warn = " ", Hint = " ", Info = " " } +for type, icon in pairs(signs) do + local hl = "DiagnosticSign" .. type + vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = hl }) +end + +-- You will likely want to reduce updatetime which affects CursorHold +-- note: this setting is global and should be set only once +vim.o.updatetime = 250 +vim.cmd [[autocmd! CursorHold,CursorHoldI * lua vim.diagnostic.open_float(nil, {scope='cursor', header = "", prefix = "", focus=false})]] + +-- Autotype +vim.cmd('au BufRead,BufNewFile *.md setlocal textwidth=80') +vim.cmd('au BufRead,BufNewFile *.tex setlocal textwidth=80') +vim.cmd('au BufNewFile,BufRead /tmp/neomutt* set tw=72 fo=awq comments+=nb:> noautoindent filetype=mail') + +-- Ignore these filenames during enhanced command line completion. +vim.opt.wildignore = { + '*.bak', + '*.class', + '*.aux', + '*.out', + '*.toc', + '*.jpg', + '*.bmp', + '*.gif', + '*.png', + '*.luac', + '*.o', + '*.obj', + '*.exe', + '*.dll', + '*.manifest', + '*.pyc', + '*.spl', + '*.sw?' +}