This commit is contained in:
nil 2024-08-04 22:31:07 +08:00
parent 8eb24fb69f
commit 17ef0c9374
4 changed files with 78 additions and 3 deletions

View File

@ -1,3 +1 @@
# nvim
Neovim config
# `Neovim Config`

2
init.lua Normal file
View File

@ -0,0 +1,2 @@
require("options")
require("keymaps")

47
lua/keymaps.lua Normal file
View File

@ -0,0 +1,47 @@
-- define common options
local opts = {
noremap = true, -- non-recursive
silent = true, -- do not show message
}
local keymap = vim.keymap.set
vim.g.mapleader = " " --set leader key
---------------
-- View Mode --
---------------
keymap("v", "J", ":m '>+1<CR>gv=gv", opts) -- move line down
keymap("v", "K", ":m '<-2<CR>gv=gv", opts) -- move line up
-- Hint: start visual mode with the same area as the previous area and the same mode
keymap("v", "<Tab>", ">gv", opts) -- indent right
keymap("v", "<S-Tab>", "<gv", opts) -- indent left
-----------------
-- Normal Mode --
-----------------
keymap("n", "J", ":m .+1<CR>==", opts) -- move line down
keymap("n", "K", ":m .-2<CR>==", opts) -- move line up
keymap("n", "<leader>o", "o<Esc>", opts) -- insert new line below
keymap("n", "<leader>O", "O<Esc>", opts) -- insert new line above
keymap("n", "<leader>nh", ":nohlsearch<CR>", opts) -- clear search highlight
keymap("n", "<Tab>", ">>", opts) -- indent right
keymap("n", "<S-Tab>", "<<", opts) -- indent left
-- Window Navigation
keymap("n", "<C-h>", "<C-w>h", opts) -- move to left window
keymap("n", "<C-j>", "<C-w>j", opts) -- move to down window
keymap("n", "<C-k>", "<C-w>k", opts) -- move to up window
keymap("n", "<C-l>", "<C-w>l", opts) -- move to right window
keymap("n", "<leader>wh", "<C-w>s", opts) -- split window horizontally
keymap("n", "<leader>wv", "<C-w>v", opts) -- split window vertically
keymap("n", "<leader>wq", "<C-w>q", opts) -- close window
keymap("n", "<leader>wc", "<C-w>c", opts) -- close window
-- Resize with arrows
-- delta: 2 lines
keymap("n", "<C-Up>", ":resize -2<CR>", opts)
keymap("n", "<C-Down>", ":resize +2<CR>", opts)
keymap("n", "<C-Left>", ":vertical resize -2<CR>", opts)
keymap("n", "<C-Right>", ":vertical resize +2<CR>", opts)
-----------------
-- Insert Mode --
-----------------

28
lua/options.lua Normal file
View File

@ -0,0 +1,28 @@
local opt = vim.opt
-- Hint: use `:h <option>` to figure out the meaning if needed
opt.clipboard = "unnamedplus" -- use system clipboard
opt.completeopt = { "menu", "menuone", "noselect" }
opt.mouse = "a" -- allow the mouse to be used in Nvim
-- Tab
opt.tabstop = 4 -- number of visual spaces per TAB
opt.softtabstop = 4 -- number of spacesin tab when editing
opt.shiftwidth = 4 -- insert 4 spaces on a tab
opt.expandtab = true -- tabs are spaces, mainly because of python
-- UI config
opt.number = true -- show absolute number
opt.relativenumber = true -- add numbers to each line on the left side
opt.cursorline = true -- highlight cursor line underneath the cursor horizontally
opt.splitbelow = true -- open new vertical split bottom
opt.splitright = true -- open new horizontal splits right
--opt.termguicolors = true -- enabl 24-bit RGB color in the TUI
opt.showmode = false -- we are experienced, wo don"t need the "-- INSERT --" mode hint
-- Searching
opt.incsearch = true -- search as characters are entered
--opt.hlsearch = false -- do not highlight matches
opt.ignorecase = true -- ignore case in searches by default
opt.smartcase = true -- but make it case sensitive if an uppercase is entered