From f02cdb1f1e69966eaec0c457b4d5e83274486f55 Mon Sep 17 00:00:00 2001 From: Tanguy Herbron Date: Fri, 7 Apr 2023 18:24:48 +0200 Subject: [PATCH] feat(vim): Migration configuration to Lua Every configuration file related to Neovim has been moved to Lua. This comes with a variety of updatly around theming and implementation for better compatiblity accross the environment. --- .config/nvim/init.lua | 157 +++++++++++++++++++++++++- .config/nvim/legacy.vim | 4 +- .config/nvim/lua/keybindings.lua | 49 ++++++++ .config/nvim/lua/telescope-config.lua | 4 +- 4 files changed, 209 insertions(+), 5 deletions(-) create mode 100644 .config/nvim/lua/keybindings.lua diff --git a/.config/nvim/init.lua b/.config/nvim/init.lua index f20c91a..fae78d5 100644 --- a/.config/nvim/init.lua +++ b/.config/nvim/init.lua @@ -1,2 +1,157 @@ -vim.cmd("source ~/.config/nvim/legacy.vim") +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", + lazypath, + }) +end +vim.opt.rtp:prepend(lazypath) +require("lazy").setup({ + { "Shatur/neovim-ayu", lazy = false, enabled = true }, + "junegunn/fzf.vim", + "yggdroot/indentline", + "yuezk/vim-js", + { "neoclide/coc.nvim", branch = "release" }, + { + "nvim-lualine/lualine.nvim", + dependencies = { + "nvim-tree/nvim-web-devicons" + } + }, + { + "nvim-telescope/telescope.nvim", + branch = "0.1.x", + dependencies = { + "nvim-lua/plenary.nvim", + "jremmen/vim-ripgrep", + { "nvim-treesitter/nvim-treesitter", build = ":TSUpdate" }, + "nvim-tree/nvim-web-devicons" + } + }, + "tpope/vim-fugitive", + { "rrethy/vim-hexokinase", build = "make hexokinase" }, + "mbbill/undotree", + "skanehira/docker-compose.vim", + "chr4/nginx.vim", + "machakann/vim-highlightedyank", + "godlygeek/tabular", + "preservim/vim-markdown", + "tpope/vim-obsession", +}) + +--- THEMING --- + +require('ayu').setup({ + mirage = true, + overrides = function() + if vim.o.background == "dark" then + return { + Normal = {bg = '#0f1419', fg = '#cbccc6'}, + Comment = { fg = "#5c6773" } + } + end + end +}) + +require('ayu').colorscheme() + +--- Change default behaviour --- +-- Disable integrated providers +vim.g.loaded_ruby_provider = 0 +vim.g.loaded_perl_provider = 0 +vim.g.loaded_node_provider = 0 + +-- Disable error bell +vim.opt.errorbells = false + +--- Tab configuration --- +-- Show tabs at 4 spaces +vim.opt.tabstop = 4 +vim.opt.softtabstop = 4 + +-- When indenting with '>', use 4 spaces +vim.opt.shiftwidth = 4 + +-- Insert 4 spaces instead of tab +vim.opt.expandtab = true + +--- Line formatting --- +vim.opt.nu = true +vim.opt.wrap = false + +--- Search configuration --- +vim.opt.smartcase = true +vim.opt.ignorecase = true + +--- Window configuration --- +vim.opt.splitright = true +vim.opt.splitbelow = true +-- Remove duplicate -- INSERT -- +vim.opt.showmode = false + +--- Operation configuration --- +vim.opt.swapfile = false +vim.opt.backup = false +vim.opt.undodir = "~/.config/nvim/undodir" +vim.opt.undofile = true + +--- Folding behaviour configuration --- +vim.opt.foldmethod = "indent" +vim.opt.foldnestmax = 10 +vim.opt.foldenable = false +vim.opt.foldlevel = 99 +vim.opt.signcolumn = "no" + +--- Miscellaneous --- +-- rg smart root finder and adds git ignore loading for faster execution +if vim.fn.executable("rg") == 1 then + vim.g.rg_derive_root = true +end + +-- Disable mouse +vim.opt.mouse = nil + +-- Source CoC configuration +vim.cmd("source ~/.config/nvim/coc.vim") + +-- IndentLine configuration +vim.g.indentLine_enabled = 1 +vim.g.indentLine_char_list = {'|', '¦', '┆', '┊'} +vim.g.indentLine_setColors = 1 +vim.g.indentLine_color_gui = "#5C6370" +vim.g.indentLine_showFirstIndentLevel = 1 + +-- Advertise 256 colors capability (for tmux) +vim.t_Co = 256 + +-- Undocumented ??? +--vim.&t_8f = "\[38;2;%lu;%lu;%lum" +--vim.&t_8b = "\[48;2;%lu;%lu;%lum" + +--- Lualine --- +-- Setup +require("lualine").setup({ + options = { + theme = "ayu_dark", + section_separators = { left = '', right = '' }, + component_separators = { left = '', right = '' }, + globalstatus = false, + }, + sections = { + lualine_a = {'mode'}, + lualine_b = {'branch', 'diff', 'diagnostics'}, + lualine_c = {'filename'}, + lualine_x = {'encoding', 'fileformat', 'filetype'}, + lualine_y = {}, + lualine_z = {'location'} + }, +}) + +require("keybindings") + +-- vim.cmd("source ~/.config/nvim/legacy.vim") diff --git a/.config/nvim/legacy.vim b/.config/nvim/legacy.vim index 0782ea6..69599bd 100644 --- a/.config/nvim/legacy.vim +++ b/.config/nvim/legacy.vim @@ -1,6 +1,6 @@ call plug#begin('~/.config/nvim/plugged') " Ayu color scheme -Plug 'TanguyHerbron/ayu-vim' +Plug 'https://git.halia.dev/therbron/ayu-vim' Plug 'junegunn/fzf.vim' @@ -64,7 +64,7 @@ Plug 'tpope/vim-obsession' " Plug 'ekalinin/Dockerfile.vim' " Vim integration in tmux -Plug 'vimpostor/vim-tpipeline' +"Plug 'vimpostor/vim-tpipeline' call plug#end() " Disable integrated providers diff --git a/.config/nvim/lua/keybindings.lua b/.config/nvim/lua/keybindings.lua new file mode 100644 index 0000000..15729f7 --- /dev/null +++ b/.config/nvim/lua/keybindings.lua @@ -0,0 +1,49 @@ +local function map(mode, combo, mapping, opts) + local options = {noremap = true} + if opts then + options = vim.tbl_extend('force', options, opts) + end + vim.api.nvim_set_keymap(mode, combo, mapping, options) +end + +vim.g.mapleader = ' ' + +-- Navigate through panes using lead key and vim direction +map('', 'h', ':wincmd h') +map('', 'j', ':wincmd j') +map('', 'k', ':wincmd k') +map('', 'l', ':wincmd l') + +-- Move to tab using lead key plus number +map('', '1', '1gt') +map('', '2', '2gt') +map('', '3', '3gt') +map('', '4', '4gt') +map('', '5', '5gt') +map('', '6', '6gt') +map('', '7', '7gt') +map('', '8', '8gt') +map('', '9', '9gt') +map('', '0', '10gt') + +-- Open undotree panel +map('', 'u', ':UndotreeToggle') + +-- Open lazy.nvim +map('', 'p', ':Lazy home') + +--- Telescope --- +-- List project files +vim.keymap.set('', '', function() require("telescope-config").project_files() end) + +-- Grep through files in project +vim.keymap.set('', '', ":Telescope live_grep") + +--- Miscellaneous +-- Toggle line wrap +vim.keymap.set('', 'w', function() + vim.cmd("set wrap! linebreak! nolist!") +end) + +-- Format markdown tables +map('', 't', ":TableFormat") diff --git a/.config/nvim/lua/telescope-config.lua b/.config/nvim/lua/telescope-config.lua index f09f8ec..6e34520 100644 --- a/.config/nvim/lua/telescope-config.lua +++ b/.config/nvim/lua/telescope-config.lua @@ -4,9 +4,9 @@ M.project_files = function() local opts = {} vim.fn.system('git rev-parse is-inside-work-tree') if vim.v.shell_error == 0 then - require"telescope.builtin".git_files({show_untracked=true}) + require("telescope.builtin").git_files({show_untracked=true}) else - require"telescope.builtin".find_files(opts) + require("telescope.builtin").find_files(opts) end end