162 lines
5.0 KiB
Plaintext
162 lines
5.0 KiB
Plaintext
-- Helper function for key mappings
|
|
local function map(mode, lhs, rhs, opts)
|
|
local options = { silent = true, noremap = true }
|
|
|
|
if opts then
|
|
options = vim.tbl_extend("force", options, opts)
|
|
end
|
|
|
|
if type(mode) == "table" then
|
|
for _, m in ipairs(mode) do
|
|
vim.keymap.set(m, lhs, rhs, options)
|
|
end
|
|
else
|
|
vim.keymap.set(mode, lhs, rhs, options)
|
|
end
|
|
end
|
|
|
|
-- Mode-specific mapping functions
|
|
local function nmap(lhs, rhs, opts) map("n", lhs, rhs, opts) end
|
|
local function imap(lhs, rhs, opts) map("i", lhs, rhs, opts) end
|
|
local function vmap(lhs, rhs, opts) map("v", lhs, rhs, opts) end
|
|
local function tmap(lhs, rhs, opts) map("t", lhs, rhs, opts) end
|
|
vim.opt.signcolumn = "no"
|
|
|
|
|
|
-- Map Leader
|
|
vim.g.mapleader = " "
|
|
vim.g.maplocalleader = " "
|
|
|
|
-- Use Nerd Font
|
|
vim.g.have_nerd_font = true
|
|
|
|
-- Add vertical line
|
|
-- vim.opt.colorcolumn = "100"
|
|
|
|
-- Enable TrueColor
|
|
vim.opt.termguicolors = true
|
|
|
|
-- Disable Neovim background
|
|
vim.api.nvim_set_hl(0, "Normal", { bg = "none" })
|
|
vim.api.nvim_set_hl(0, "NormalFloat", { bg = "none" })
|
|
|
|
-- Scroll lines/columns
|
|
vim.opt.mousescroll = "hor:1,ver:1"
|
|
|
|
-- Set indentation preferences
|
|
vim.opt.expandtab = true -- Convert tabs to spaces
|
|
vim.opt.shiftwidth = 2 -- Number of spaces for auto-indent
|
|
vim.opt.tabstop = 2 -- Number of spaces a tab counts for
|
|
vim.opt.softtabstop = 2 -- Number of spaces a tab counts for when editing
|
|
vim.opt.autoindent = true -- Copy indent from current line when starting new line
|
|
vim.opt.smartindent = true -- Do smart autoindenting when starting a new line
|
|
|
|
-- Disable line wrapping
|
|
vim.opt.wrap = false
|
|
|
|
-- Enable break indent
|
|
vim.opt.breakindent = true
|
|
|
|
-- Make line numbers default
|
|
vim.opt.number = true
|
|
vim.opt.relativenumber = true
|
|
|
|
-- Enable mouse mode, can be useful for resizing splits for example
|
|
vim.opt.mouse = "a"
|
|
|
|
-- Full path on status line
|
|
vim.opt.statusline = "%F%m%r%h%w%=%l,%c %P"
|
|
|
|
-- Sync clipboard between OS and Neovim
|
|
vim.schedule(function()
|
|
vim.opt.clipboard = "unnamedplus"
|
|
end)
|
|
|
|
-- Save undo history
|
|
vim.opt.undofile = true
|
|
|
|
-- Case-insensitive searching UNLESS \C or one or more capital letters in the search term
|
|
vim.opt.ignorecase = true
|
|
vim.opt.smartcase = true
|
|
|
|
-- Decrease update time
|
|
vim.opt.updatetime = 250
|
|
|
|
-- Decrease mapped sequence wait time
|
|
-- Displays which-key popup sooner
|
|
vim.opt.timeoutlen = 300
|
|
|
|
-- Configure how new splits should be opened
|
|
vim.opt.splitright = true
|
|
vim.opt.splitbelow = true
|
|
|
|
-- Sets how neovim will display certain whitespace characters in the editor.
|
|
vim.opt.list = true
|
|
vim.opt.listchars = { tab = "» ", trail = "·", nbsp = "␣" }
|
|
|
|
-- Preview substitutions live, as you type
|
|
vim.opt.inccommand = "split"
|
|
|
|
-- Show which line your cursor is on
|
|
vim.opt.cursorline = true
|
|
|
|
-- Minimal number of screen lines to keep above and below the cursor
|
|
vim.opt.scrolloff = 10
|
|
|
|
-- Highlight when yanking (copying) text
|
|
vim.api.nvim_create_autocmd("TextYankPost", {
|
|
callback = function()
|
|
vim.highlight.on_yank()
|
|
end,
|
|
})
|
|
|
|
-- Keymaps
|
|
|
|
nmap("<leader>q", vim.diagnostic.setloclist, { desc = "Open diagnostic [Q]uickfix list" })
|
|
|
|
imap("jk", "<Esc>", { desc = "Exit insert mode with jk" })
|
|
nmap("<Esc>", "<cmd>nohlsearch<CR>", { desc = "Clear highlights" })
|
|
|
|
-- Prevent "x" from overriding the register
|
|
nmap("x", '"_x')
|
|
|
|
-- Window Navigation
|
|
nmap("<C-h>", "<C-w>h", { desc = "Move focus to the left window" })
|
|
nmap("<C-l>", "<C-w>l", { desc = "Move focus to the right window" })
|
|
nmap("<C-j>", "<C-w>j", { desc = "Move focus to the lower window" })
|
|
nmap("<C-k>", "<C-w>k", { desc = "Move focus to the upper window" })
|
|
|
|
-- Tab management
|
|
nmap("<Leader>tn", ":tabnew<CR>", { desc = "[T]ab [N]ew" })
|
|
nmap("<Leader>tc", ":tabclose<CR>", { desc = "[T]ab [C]lose" })
|
|
nmap("<Leader>to", ":tabonly<CR>", { desc = "[T]ab [O]nly" })
|
|
nmap("<Leader>tl", ":tabnext<CR>", { desc = "[T]ab Next" })
|
|
nmap("<Leader>th", ":tabprevious<CR>", { desc = "[T]ab Previous" })
|
|
nmap("<Leader>tm.", ":tabmove +1<CR>", { desc = "[T]ab [M]ove Right" })
|
|
nmap("<Leader>tm,", ":tabmove -1<CR>", { desc = "[T]ab [M]ove Left" })
|
|
for i = 1, 9 do
|
|
nmap(string.format("<Leader>%d", i), string.format("%dgt", i), { desc = string.format("[T]ab %d", i) })
|
|
end
|
|
|
|
-- Buffer Management
|
|
nmap("<Leader>bl", ":ls<CR>", { desc = "[B]uffer [L]ist" })
|
|
nmap("<Leader>bd", ":bdelete<CR>", { desc = "[B]uffer [D]elete" })
|
|
nmap("]b", ":bnext<CR>", { desc = "[B]uffer [N]ext" })
|
|
nmap("[b", ":bprevious<CR>", { desc = "[B]uffer [P]revious" })
|
|
nmap("<Leader>bb", ":b<Space>", { desc = "[B]uffer Select" })
|
|
nmap("<Leader>bo", ":bufdo bd|1bd<CR>", { desc = "[B]uffer Delete Others" })
|
|
|
|
-- Terminal
|
|
nmap("<Leader>tet", function()
|
|
vim.cmd("terminal")
|
|
vim.cmd("startinsert")
|
|
end, { desc = "[T]erminal" })
|
|
nmap("<leader>ter", function()
|
|
local buf_dir = vim.fn.expand("%:p:h")
|
|
vim.cmd("edit term://" .. buf_dir .. "//zsh")
|
|
vim.cmd("startinsert")
|
|
end, { desc = "[T]erminal [R]elative" })
|
|
tmap("<Esc>", "<C-\\><C-n>", { desc = "Terminal Normal Mode" })
|
|
tmap("jk", "<C-\\><C-n>", { desc = "Terminal Normal Mode" })
|
|
tmap("<C-w>", "<C-\\><C-n><C-w>", { desc = "Terminal Window Command" })
|