Restructure
This commit is contained in:
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
# nothing host-specific lives in the repo
|
||||
*.swp
|
||||
*~
|
||||
42
config/nvim/lua/core/autocmds.lua
Normal file
42
config/nvim/lua/core/autocmds.lua
Normal file
@@ -0,0 +1,42 @@
|
||||
-- core/autocmds.lua
|
||||
local aug = vim.api.nvim_create_augroup
|
||||
local au = vim.api.nvim_create_autocmd
|
||||
|
||||
-- highlight yanked text briefly
|
||||
au("TextYankPost", {
|
||||
group = aug("highlight_yank", { clear = true }),
|
||||
callback = function() vim.highlight.on_yank({ timeout = 150 }) end,
|
||||
})
|
||||
|
||||
-- restore last cursor position when reopening a file
|
||||
au("BufReadPost", {
|
||||
group = aug("last_loc", { clear = true }),
|
||||
callback = function(ev)
|
||||
local mark = vim.api.nvim_buf_get_mark(ev.buf, '"')
|
||||
local lines = vim.api.nvim_buf_line_count(ev.buf)
|
||||
if mark[1] > 0 and mark[1] <= lines then
|
||||
pcall(vim.api.nvim_win_set_cursor, 0, mark)
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
-- trim trailing whitespace on save (skip filetypes where it matters)
|
||||
au("BufWritePre", {
|
||||
group = aug("trim_ws", { clear = true }),
|
||||
callback = function()
|
||||
if vim.bo.filetype == "diff" or vim.bo.filetype == "markdown" then return end
|
||||
local view = vim.fn.winsaveview()
|
||||
vim.cmd([[silent! keeppatterns %s/\s\+$//e]])
|
||||
vim.fn.winrestview(view)
|
||||
end,
|
||||
})
|
||||
|
||||
-- auto-create parent dirs on save
|
||||
au("BufWritePre", {
|
||||
group = aug("mkdir_on_save", { clear = true }),
|
||||
callback = function(ev)
|
||||
if ev.match:match("^%w+://") then return end
|
||||
local dir = vim.fn.fnamemodify(ev.file, ":p:h")
|
||||
if vim.fn.isdirectory(dir) == 0 then vim.fn.mkdir(dir, "p") end
|
||||
end,
|
||||
})
|
||||
53
config/nvim/lua/core/keymaps.lua
Normal file
53
config/nvim/lua/core/keymaps.lua
Normal file
@@ -0,0 +1,53 @@
|
||||
-- core/keymaps.lua - leader-based, plugin-free keymaps.
|
||||
local map = vim.keymap.set
|
||||
|
||||
-- clear search highlight
|
||||
map("n", "<Esc>", "<cmd>nohlsearch<CR>", { desc = "clear highlight" })
|
||||
|
||||
-- save / quit
|
||||
map("n", "<leader>w", "<cmd>write<CR>", { desc = "write" })
|
||||
map("n", "<leader>q", "<cmd>quit<CR>", { desc = "quit" })
|
||||
map("n", "<leader>Q", "<cmd>quitall<CR>", { desc = "quit all" })
|
||||
|
||||
-- window navigation (ctrl + hjkl)
|
||||
map("n", "<C-h>", "<C-w>h", { desc = "win left" })
|
||||
map("n", "<C-j>", "<C-w>j", { desc = "win down" })
|
||||
map("n", "<C-k>", "<C-w>k", { desc = "win up" })
|
||||
map("n", "<C-l>", "<C-w>l", { desc = "win right" })
|
||||
|
||||
-- resize with arrows
|
||||
map("n", "<C-Up>", "<cmd>resize +2<CR>")
|
||||
map("n", "<C-Down>", "<cmd>resize -2<CR>")
|
||||
map("n", "<C-Left>", "<cmd>vertical resize -2<CR>")
|
||||
map("n", "<C-Right>", "<cmd>vertical resize +2<CR>")
|
||||
|
||||
-- buffer cycling
|
||||
map("n", "<S-l>", "<cmd>bnext<CR>", { desc = "next buffer" })
|
||||
map("n", "<S-h>", "<cmd>bprevious<CR>", { desc = "prev buffer" })
|
||||
map("n", "<leader>bd", "<cmd>bdelete<CR>", { desc = "delete buffer" })
|
||||
|
||||
-- keep cursor centered on jumps / search
|
||||
map("n", "<C-d>", "<C-d>zz")
|
||||
map("n", "<C-u>", "<C-u>zz")
|
||||
map("n", "n", "nzzzv")
|
||||
map("n", "N", "Nzzzv")
|
||||
|
||||
-- move selected lines (visual)
|
||||
map("v", "J", ":m '>+1<CR>gv=gv", { desc = "move line down" })
|
||||
map("v", "K", ":m '<-2<CR>gv=gv", { desc = "move line up" })
|
||||
|
||||
-- keep selection when indenting
|
||||
map("v", "<", "<gv")
|
||||
map("v", ">", ">gv")
|
||||
|
||||
-- paste over selection without clobbering the register
|
||||
map("x", "<leader>p", [["_dP]], { desc = "paste no-yank" })
|
||||
|
||||
-- yank to system clipboard explicitly
|
||||
map({ "n", "v" }, "<leader>y", [["+y]], { desc = "yank to clipboard" })
|
||||
|
||||
-- quick edit/reload of config
|
||||
map("n", "<leader>ve", "<cmd>edit $MYVIMRC<CR>", { desc = "edit config" })
|
||||
|
||||
-- sudo-write a file you opened without permissions (very ops-handy)
|
||||
map("n", "<leader>W", "<cmd>w !sudo tee % >/dev/null<CR>", { desc = "sudo write" })
|
||||
57
config/nvim/lua/core/options.lua
Normal file
57
config/nvim/lua/core/options.lua
Normal file
@@ -0,0 +1,57 @@
|
||||
-- core/options.lua - sane editor defaults for server / ops work.
|
||||
local opt = vim.opt
|
||||
local g = vim.g
|
||||
|
||||
g.mapleader = " "
|
||||
g.maplocalleader = " "
|
||||
|
||||
-- ui
|
||||
opt.number = true
|
||||
opt.relativenumber = true
|
||||
opt.cursorline = true
|
||||
opt.signcolumn = "yes"
|
||||
opt.scrolloff = 6
|
||||
opt.sidescrolloff = 8
|
||||
opt.wrap = false
|
||||
opt.termguicolors = true
|
||||
opt.showmode = false
|
||||
opt.laststatus = 3 -- global statusline
|
||||
opt.title = true -- set terminal title (nice with tmux)
|
||||
opt.list = true
|
||||
opt.listchars = { tab = "» ", trail = "·", nbsp = "␣" }
|
||||
|
||||
-- editing
|
||||
opt.expandtab = true
|
||||
opt.shiftwidth = 2
|
||||
opt.tabstop = 2
|
||||
opt.softtabstop = 2
|
||||
opt.smartindent = true
|
||||
opt.breakindent = true
|
||||
|
||||
-- search
|
||||
opt.ignorecase = true
|
||||
opt.smartcase = true
|
||||
opt.hlsearch = true
|
||||
opt.incsearch = true
|
||||
opt.inccommand = "split" -- live preview of :substitute
|
||||
|
||||
-- files / undo
|
||||
opt.undofile = true
|
||||
opt.swapfile = false
|
||||
opt.backup = false
|
||||
opt.updatetime = 250
|
||||
opt.timeoutlen = 400
|
||||
opt.confirm = true -- ask instead of failing on unsaved quit
|
||||
|
||||
-- splits feel natural
|
||||
opt.splitright = true
|
||||
opt.splitbelow = true
|
||||
|
||||
-- clipboard: use system clipboard when available (works over SSH+OSC52 in nvim 0.10+)
|
||||
opt.clipboard = "unnamedplus"
|
||||
|
||||
-- completion
|
||||
opt.completeopt = { "menu", "menuone", "noselect" }
|
||||
|
||||
-- mouse on for the occasional copy/resize over ssh
|
||||
opt.mouse = "a"
|
||||
84
config/nvim/lua/core/plugins.lua
Normal file
84
config/nvim/lua/core/plugins.lua
Normal file
@@ -0,0 +1,84 @@
|
||||
-- core/plugins.lua - optional plugin layer (lazy.nvim).
|
||||
-- Kept minimal & ops-focused. If the machine is offline at first launch this
|
||||
-- module raises an error that init.lua catches; the core config still works.
|
||||
|
||||
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
|
||||
|
||||
if not (vim.uv or vim.loop).fs_stat(lazypath) then
|
||||
-- only attempt clone if git exists; error out cleanly otherwise
|
||||
if vim.fn.executable("git") == 0 then
|
||||
error("git not available; skipping plugins")
|
||||
end
|
||||
local out = vim.fn.system({
|
||||
"git", "clone", "--filter=blob:none", "--branch=stable",
|
||||
"https://github.com/folke/lazy.nvim.git", lazypath,
|
||||
})
|
||||
if vim.v.shell_error ~= 0 then
|
||||
error("lazy.nvim clone failed: " .. out)
|
||||
end
|
||||
end
|
||||
vim.opt.rtp:prepend(lazypath)
|
||||
|
||||
require("lazy").setup({
|
||||
-- colorscheme
|
||||
{
|
||||
"folke/tokyonight.nvim",
|
||||
priority = 1000,
|
||||
config = function()
|
||||
require("tokyonight").setup({ style = "night" })
|
||||
pcall(vim.cmd.colorscheme, "tokyonight")
|
||||
end,
|
||||
},
|
||||
|
||||
-- statusline (light, no icons required so it works in plain TTYs)
|
||||
{
|
||||
"nvim-lualine/lualine.nvim",
|
||||
opts = {
|
||||
options = { theme = "auto", icons_enabled = false, globalstatus = true },
|
||||
},
|
||||
},
|
||||
|
||||
-- fuzzy finder: files / grep / buffers
|
||||
{
|
||||
"nvim-telescope/telescope.nvim",
|
||||
branch = "0.1.x",
|
||||
dependencies = { "nvim-lua/plenary.nvim" },
|
||||
keys = {
|
||||
{ "<leader>ff", "<cmd>Telescope find_files<CR>", desc = "find files" },
|
||||
{ "<leader>fg", "<cmd>Telescope live_grep<CR>", desc = "grep (ripgrep)" },
|
||||
{ "<leader>fb", "<cmd>Telescope buffers<CR>", desc = "buffers" },
|
||||
{ "<leader>fh", "<cmd>Telescope help_tags<CR>", desc = "help" },
|
||||
},
|
||||
},
|
||||
|
||||
-- treesitter: better syntax highlighting for the configs we actually touch
|
||||
{
|
||||
"nvim-treesitter/nvim-treesitter",
|
||||
build = ":TSUpdate",
|
||||
opts = {
|
||||
ensure_installed = {
|
||||
"lua", "bash", "yaml", "json", "toml", "dockerfile",
|
||||
"nix", "python", "markdown", "diff", "git_config",
|
||||
},
|
||||
highlight = { enable = true },
|
||||
indent = { enable = true },
|
||||
},
|
||||
config = function(_, opts)
|
||||
require("nvim-treesitter.configs").setup(opts)
|
||||
end,
|
||||
},
|
||||
|
||||
-- git signs in the gutter
|
||||
{ "lewis6991/gitsigns.nvim", opts = {} },
|
||||
|
||||
-- show pending keybinds
|
||||
{ "folke/which-key.nvim", event = "VeryLazy", opts = {} },
|
||||
|
||||
-- quick comment toggling: gcc / gc in visual
|
||||
{ "numToStr/Comment.nvim", opts = {} },
|
||||
}, {
|
||||
install = { colorscheme = { "tokyonight", "habamax" } },
|
||||
checker = { enabled = false }, -- don't phone home on managed hosts
|
||||
change_detection = { notify = false },
|
||||
ui = { border = "rounded" },
|
||||
})
|
||||
Reference in New Issue
Block a user