diff --git a/CHEATSHEET.md b/CHEATSHEET.md new file mode 100644 index 0000000..2dd6d0e --- /dev/null +++ b/CHEATSHEET.md @@ -0,0 +1,37 @@ +# Neovim cheatsheet for this setup + + +## Save and exit + +```vim +:w -- save file +w -- +w -- + +:wq -- save and exit +wq -- + +:q -- exit without saving +q -- +q -- + +:q! -- force to quit without saving +qq -- +``` + + +## Buffer navigation + +```vim +:e -- open a file in a new buffer +e -- + +:ls -- list buffers +ls -- + +:bnext -- goto next buffer +f -- + +:bprevious -- goto previous buffer +d -- +``` diff --git a/README.md b/README.md new file mode 100644 index 0000000..df30541 --- /dev/null +++ b/README.md @@ -0,0 +1,19 @@ +# Basic neovim configuration + + +To open [CHEATSHEET.md](./CHEATSHEET.md): `h`. +To open [README.md](./README.md): `hr` + + +## Used package + +- [x] kanagawa: color schema +- [x] oil: files manager +- [x] mini-statusline + +## References + + - https://www.youtube.com/watch?v=g1gyYttzxcI + + + diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..551ec67 --- /dev/null +++ b/init.lua @@ -0,0 +1,2 @@ +require("config.lazy") + diff --git a/lazy-lock.json b/lazy-lock.json new file mode 100644 index 0000000..6124fb6 --- /dev/null +++ b/lazy-lock.json @@ -0,0 +1,8 @@ +{ + "kanagawa.nvim": { "branch": "master", "commit": "aef7f5cec0a40dbe7f3304214850c472e2264b10" }, + "lazy.nvim": { "branch": "main", "commit": "85c7ff3711b730b4030d03144f6db6375044ae82" }, + "mini.icons": { "branch": "main", "commit": "ff2e4f1d29f659cc2bad0f9256f2f6195c6b2428" }, + "mini.statusline": { "branch": "main", "commit": "e331175f10d9f400b42523b3890841aba202ce16" }, + "oil.nvim": { "branch": "master", "commit": "7e1cd7703ff2924d7038476dcbc04b950203b902" }, + "vim-sleuth": { "branch": "master", "commit": "be69bff86754b1aa5adcbb527d7fcd1635a84080" } +} diff --git a/lua/config/keymap.lua b/lua/config/keymap.lua new file mode 100644 index 0000000..4fff024 --- /dev/null +++ b/lua/config/keymap.lua @@ -0,0 +1,55 @@ +vim.keymap.set('n', "-", "Oil --float", { desc ="Enter file explorer (Oil)" }) + +vim.keymap.set('n', "w", "w", { desc = "Save" } ) +vim.keymap.set('n', "w", "w", { desc = "Save" } ) +vim.keymap.set('n', "q", "q", { desc = "Quit without saving" } ) +vim.keymap.set('n', "q", "q", { desc = "Quit without saving" } ) +vim.keymap.set('n', "wq", "wq", { desc = "Save and quit" } ) +vim.keymap.set('n', "qq", "q!", { desc = "Force to quit without saving" } ) + + +-- todo: this is not robust... add autocompletion and verify that file exists +vim.keymap.set("n", "e", function() + local file_name = vim.fn.input("Open file: ") + if file_name ~= "" then + vim.cmd(":edit " .. file_name) + end +end, { desc = "edit a file"}) + +vim.keymap.set("n","ls", "ls", { desc = "list buffers" }) +vim.keymap.set("n","f", "bnext", { desc = "goto next buffers" }) +vim.keymap.set("n","d", "bprevious", { desc = "goto previous buffers" }) +vim.keymap.set("n","c", "bd", { desc = "close buffers" }) + +vim.keymap.set("n", "h", function() + local config_path = vim.fn.stdpath('config') + local readme_path = config_path .. '/CHEATSHEET.md' + local buf = vim.fn.bufadd(readme_path) + vim.fn.bufload(buf) + local win = vim.api.nvim_open_win(buf, true, { + relative = 'editor', + width = 80, + height = 20, + col = (vim.o.columns - 80) / 2, + row = (vim.o.lines - 100) / 2, + style = 'minimal' + }) + vim.api.nvim_win_set_option(win, 'number', false) +end, { desc = "Open CHEATSHEET.md"}) + +vim.keymap.set("n", "hr", function() + local config_path = vim.fn.stdpath('config') + local readme_path = config_path .. '/README.md' + local buf = vim.fn.bufadd(readme_path) + vim.fn.bufload(buf) + local win = vim.api.nvim_open_win(buf, true, { + relative = 'editor', + width = 80, + height = 20, + col = (vim.o.columns - 80) / 2, + row = (vim.o.lines - 100) / 2, + style = 'minimal' + }) + vim.api.nvim_win_set_option(win, 'number', false) +end, { desc = "Open CHEATSHEET.md"}) + diff --git a/lua/config/lazy.lua b/lua/config/lazy.lua new file mode 100644 index 0000000..c69b300 --- /dev/null +++ b/lua/config/lazy.lua @@ -0,0 +1,38 @@ +-- Bootstrap lazy.nvim +local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" +if not (vim.uv or vim.loop).fs_stat(lazypath) then + local lazyrepo = "https://github.com/folke/lazy.nvim.git" + local out = vim.fn.system({ "git", "clone", "--filter=blob:none", "--branch=stable", lazyrepo, lazypath }) + if vim.v.shell_error ~= 0 then + vim.api.nvim_echo({ + { "Failed to clone lazy.nvim:\n", "ErrorMsg" }, + { out, "WarningMsg" }, + { "\nPress any key to exit..." }, + }, true, {}) + vim.fn.getchar() + os.exit(1) + end +end +vim.opt.rtp:prepend(lazypath) + +-- Make sure to setup `mapleader` and `maplocalleader` before +-- loading lazy.nvim so that mappings are correct. +-- This is also a good place to setup other settings (vim.opt) +vim.g.mapleader = " " +vim.g.maplocalleader = "\\" + +-- Setup lazy.nvim +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 = { "kanagawa" } }, + -- automatically check for plugin updates + checker = { enabled = true }, +}) + +require("config.keymap") +require("config.options") diff --git a/lua/config/options.lua b/lua/config/options.lua new file mode 100644 index 0000000..2057548 --- /dev/null +++ b/lua/config/options.lua @@ -0,0 +1,26 @@ +vim.o.number = true -- show line numbers +vim.o.relativenumber = true -- show line numbers relative to current line + +vim.o.ignorecase = true +vim.o.smartcase = true + + +-- use vim +--vim.o.expandtab = true -- convert tab to spaces +--vim.o.shiftwidth = 4 + +vim.o.cursorline = true + +vim.o.undofile = true + +vim.o.showmode = false + +vim.o.signcolumn = "yes" + + + +vim.o.list = true +vim.opt.listchars = { tab = '» ', trail = '·', nbsp = '␣' } + + + diff --git a/lua/plugins/kanagawa.lua b/lua/plugins/kanagawa.lua new file mode 100644 index 0000000..1081741 --- /dev/null +++ b/lua/plugins/kanagawa.lua @@ -0,0 +1,14 @@ +return { + "rebelot/kanagawa.nvim", opt = {}, + config = function() + require("kanagawa").setup({ +compile = true, + +transparent = true + }); +vim.cmd("colorscheme kanagawa"); +end, +build = function() + vim.cmd("KanagawaCompile"); -- this line fail at first install +end, +} diff --git a/lua/plugins/mini-statusline.lua b/lua/plugins/mini-statusline.lua new file mode 100644 index 0000000..48e86e7 --- /dev/null +++ b/lua/plugins/mini-statusline.lua @@ -0,0 +1,6 @@ +return { + +'nvim-mini/mini.statusline', version = "", +opts={}, + +} diff --git a/lua/plugins/oil.lua b/lua/plugins/oil.lua new file mode 100644 index 0000000..8f5d6ff --- /dev/null +++ b/lua/plugins/oil.lua @@ -0,0 +1,11 @@ +return { + 'stevearc/oil.nvim', + ---@module 'oil' + ---@type oil.SetupOpts + opts = {}, + -- Optional dependencies + dependencies = { { "nvim-mini/mini.icons", opts = {} } }, + -- dependencies = { "nvim-tree/nvim-web-devicons" }, -- use if you prefer nvim-web-devicons + -- Lazy loading is not recommended because it is very tricky to make it work correctly in all situations. + lazy = false, +} diff --git a/lua/plugins/sleuth.lua b/lua/plugins/sleuth.lua new file mode 100644 index 0000000..9d02aa3 --- /dev/null +++ b/lua/plugins/sleuth.lua @@ -0,0 +1,3 @@ +return { + "tpope/vim-sleuth" +}