Created
July 24, 2024 11:21
-
-
Save S1M0N38/81ee6ac35123ae385cbb7fe7a9c61dc7 to your computer and use it in GitHub Desktop.
Minimal Neovim Config
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
------------------------------------------------------------------------------------------------------------------------ | |
-- options | |
vim.g.mapleader = " " | |
local opt = vim.opt | |
-- UI | |
opt.laststatus = 3 -- global statusline | |
opt.number = true -- Print line number | |
opt.relativenumber = true -- Relative line numbers | |
opt.scrolloff = 4 -- Lines of context | |
opt.sidescrolloff = 8 -- Columns of context | |
opt.termguicolors = true -- True color support | |
-- Search | |
opt.ignorecase = true -- Ignore case | |
opt.smartcase = true -- Don't ignore case with capitals | |
-- Indent | |
opt.expandtab = true -- Use spaces instead of tabs | |
opt.shiftwidth = 2 -- Size of an indent | |
opt.tabstop = 2 -- Number of spaces tabs count for | |
opt.smartindent = true -- Insert indents automatically | |
-- Splits | |
opt.splitbelow = true -- Put new windows below current | |
opt.splitright = true -- Put new windows right of current | |
-- Completions | |
opt.wildmode = "longest:full,full" -- Command-line completion mode | |
opt.completeopt = "menu,menuone,noselect" | |
-- Others | |
opt.smoothscroll = true | |
opt.undofile = true | |
opt.spelllang = { "en", "it" } | |
------------------------------------------------------------------------------------------------------------------------ | |
-- keymaps | |
local map = vim.keymap.set | |
-- better up/down | |
map({ "n", "x" }, "j", "v:count == 0 ? 'gj' : 'j'", { expr = true, silent = true }) | |
map({ "n", "x" }, "<Down>", "v:count == 0 ? 'gj' : 'j'", { expr = true, silent = true }) | |
map({ "n", "x" }, "k", "v:count == 0 ? 'gk' : 'k'", { expr = true, silent = true }) | |
map({ "n", "x" }, "<Up>", "v:count == 0 ? 'gk' : 'k'", { expr = true, silent = true }) | |
-- windows | |
map("n", "<C-h>", "<C-w>h", { desc = "Go to left window", remap = true }) | |
map("n", "<C-j>", "<C-w>j", { desc = "Go to lower window", remap = true }) | |
map("n", "<C-k>", "<C-w>k", { desc = "Go to upper window", remap = true }) | |
map("n", "<C-l>", "<C-w>l", { desc = "Go to right window", remap = true }) | |
map("n", "<leader>-", "<C-W>s", { desc = "Split window below", remap = true }) | |
map("n", "<leader>|", "<C-W>v", { desc = "Split window right", remap = true }) | |
-- Move Lines | |
map("v", "<C-j>", ":m '>+1<cr>gv=gv", { desc = "Move down" }) | |
map("v", "<C-k>", ":m '<-2<cr>gv=gv", { desc = "Move up" }) | |
-- buffers | |
map("n", "<S-h>", "<cmd>bprevious<cr>", { desc = "Prev buffer" }) | |
map("n", "<S-l>", "<cmd>bnext<cr>", { desc = "Next buffer" }) | |
-- Clear search with <esc> | |
map({ "i", "n" }, "<esc>", "<cmd>noh<cr><esc>", { desc = "Escape and clear hlsearch" }) | |
-- https://github.com/mhinz/vim-galore#saner-behavior-of-n-and-n | |
map("n", "n", "'Nn'[v:searchforward].'zv'", { expr = true, desc = "Next search result" }) | |
map("x", "n", "'Nn'[v:searchforward]", { expr = true, desc = "Next search result" }) | |
map("o", "n", "'Nn'[v:searchforward]", { expr = true, desc = "Next search result" }) | |
map("n", "N", "'nN'[v:searchforward].'zv'", { expr = true, desc = "Prev search result" }) | |
map("x", "N", "'nN'[v:searchforward]", { expr = true, desc = "Prev search result" }) | |
map("o", "N", "'nN'[v:searchforward]", { expr = true, desc = "Prev search result" }) | |
-- better indenting | |
map("v", "<", "<gv") | |
map("v", ">", ">gv") | |
-- file explorer | |
map("n", "<leader>e", "<cmd>Lexplore<cr><esc>", { desc = "Toggle file explorer" }) | |
-- Improved yank/paste/delete | |
map("x", "<leader>p", '"_dP', { desc = "Paste without overwriting the default register" }) | |
map({ "n", "v" }, "<leader>d", '"_d', { desc = "Delete without overwriting the default register" }) | |
map({ "n", "v" }, "<leader>y", '"+y', { desc = "Yank to system clipboard" }) | |
map({ "n", "v" }, "<leader>Y", '"+Y', { desc = "Yank to system clipboard" }) | |
------------------------------------------------------------------------------------------------------------------------ | |
-- autocmds | |
local function augroup(name) | |
return vim.api.nvim_create_augroup("config_" .. name, { clear = true }) | |
end | |
-- Highlight on yank | |
vim.api.nvim_create_autocmd("TextYankPost", { | |
group = augroup("highlight_yank"), | |
callback = function() | |
vim.highlight.on_yank({ timeout = 80 }) | |
end, | |
}) | |
-- Auto create dir when saving a file, in case some intermediate directory does not exist | |
vim.api.nvim_create_autocmd({ "BufWritePre" }, { | |
group = augroup("auto_create_dir"), | |
callback = function(event) | |
if event.match:match("^%w%w+://") then | |
return | |
end | |
local file = vim.loop.fs_realpath(event.match) or event.match | |
vim.fn.mkdir(vim.fn.fnamemodify(file, ":p:h"), "p") | |
end, | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment