From b149a776b009ad114b5039318419d99b9abd66e2 Mon Sep 17 00:00:00 2001 From: Hadeed Ahmad <me@hadeedahmad.com> Date: Wed, 26 Mar 2025 19:50:28 +0500 Subject: [PATCH] Start new neovim config Add basic options and keymaps --- nvim/after/ftplugin/lua.lua | 4 ++++ nvim/init.lua | 4 ++++ nvim/lua/config/keymaps.lua | 40 ++++++++++++++++++++++++++++++++ nvim/lua/config/lazy.lua | 24 +++++++++++++++++++ nvim/lua/config/options.lua | 37 +++++++++++++++++++++++++++++ nvim/lua/config/plugins/mini.lua | 9 +++++++ 6 files changed, 118 insertions(+) create mode 100644 nvim/after/ftplugin/lua.lua create mode 100644 nvim/init.lua create mode 100644 nvim/lua/config/keymaps.lua create mode 100644 nvim/lua/config/lazy.lua create mode 100644 nvim/lua/config/options.lua create mode 100644 nvim/lua/config/plugins/mini.lua diff --git a/nvim/after/ftplugin/lua.lua b/nvim/after/ftplugin/lua.lua new file mode 100644 index 0000000..6c98153 --- /dev/null +++ b/nvim/after/ftplugin/lua.lua @@ -0,0 +1,4 @@ +local opt = vim.opt_local + +opt.softtabstop = 2 +opt.shiftwidth = 2 diff --git a/nvim/init.lua b/nvim/init.lua new file mode 100644 index 0000000..f9b4270 --- /dev/null +++ b/nvim/init.lua @@ -0,0 +1,4 @@ +require("config.options") +require("config.keymaps") + +require("config.lazy") diff --git a/nvim/lua/config/keymaps.lua b/nvim/lua/config/keymaps.lua new file mode 100644 index 0000000..5b9473b --- /dev/null +++ b/nvim/lua/config/keymaps.lua @@ -0,0 +1,40 @@ +local set = vim.keymap.set +vim.g.mapleader = " " + +set("i", "jk", "<ESC>") +set("i", "kj", "<ESC>") + +set({"n", "x"}, "j", [[v:count == 0 ? "gj" : "j"]], { expr = true }) +set({"n", "x"}, "k", [[v:count == 0 ? "gk" : "k"]], { expr = true }) + +set({"n", "x"}, ";", ":") +set({"n", "x"}, ":", ";") + +set({"n", "x"}, "gy", "\"+y") +set("n", "gp", "\"+p") + +set("n", "n", "nzz") +set("n", "N", "Nzz") + +set("n", "<c-u>", "<c-u>zz") +set("n", "<c-d>", "<c-d>zz") + +set("n", "<leader>w", "<c-w>") + +set("n", "<cr>", function() + if vim.v.hlsearch == 1 then + vim.cmd.nohlsearch() + return "" + else + return "<cr>" + end +end, { expr = true }) + +vim.api.nvim_create_autocmd("Filetype", { + pattern = "lua", + group = vim.api.nvim_create_augroup("RunLua", { clear = true }), + callback = function() + vim.keymap.set("n", "<leader>x", "<cmd>. lua<cr>", { buffer = true }) + vim.keymap.set("n", "<leader><leader>x", "<cmd>% lua<cr>", { buffer = true }) + end, +}) diff --git a/nvim/lua/config/lazy.lua b/nvim/lua/config/lazy.lua new file mode 100644 index 0000000..e51a77d --- /dev/null +++ b/nvim/lua/config/lazy.lua @@ -0,0 +1,24 @@ +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) + +require("lazy").setup({ + spec = { + { "ellisonleao/gruvbox.nvim", config = function() vim.cmd.colorscheme "gruvbox" end }, + + { import = "config.plugins" } + }, + install = { colorscheme = { "gruvbox" } } +}) diff --git a/nvim/lua/config/options.lua b/nvim/lua/config/options.lua new file mode 100644 index 0000000..1098974 --- /dev/null +++ b/nvim/lua/config/options.lua @@ -0,0 +1,37 @@ +local opt = vim.opt + +opt.expandtab = true +opt.shiftwidth = 4 +opt.smartindent = true +opt.softtabstop = 4 + +opt.hidden = true +opt.swapfile = false + +opt.splitright = true +opt.splitbelow = true + +opt.number = true +opt.relativenumber = true + +opt.cursorline = true +opt.colorcolumn = "80" +opt.signcolumn = "yes" +opt.laststatus = 3 + +opt.ignorecase = true +opt.inccommand = 'nosplit' +opt.incsearch = true +opt.smartcase = true + +opt.scrolloff = 5 +opt.termguicolors = true +opt.timeoutlen = 500 +opt.wrap = false + +opt.list = true +opt.listchars = { eol = "↲", nbsp = '␣', tab = '» ', trail = '·' } +opt.fillchars = { eob = " " } + +opt.exrc = true +opt.mouse = "a" diff --git a/nvim/lua/config/plugins/mini.lua b/nvim/lua/config/plugins/mini.lua new file mode 100644 index 0000000..47b3346 --- /dev/null +++ b/nvim/lua/config/plugins/mini.lua @@ -0,0 +1,9 @@ +return { + { + "echasnovski/mini.nvim", + config = function() + local statusline = require "mini.statusline" + statusline.setup { use_icons = true } + end + } +}