-- Options are automatically loaded before lazy.nvim startup -- Default options that are always set: https://github.com/LazyVim/LazyVim/blob/main/lua/lazyvim/config/options.lua -- Add any additional options here -- No AI/inline completion: LazyVim's blink extra sets -- completion.ghost_text.enabled = vim.g.ai_cmp (grey inline preview of the top -- item). Must be set here, before LazyVim imports its extras. vim.g.ai_cmp = false -- Clipboard provider. LazyVim disables `clipboard=unnamedplus` under SSH, so -- select the right provider and explicitly re-enable clipboard-linked yanks: -- * tmux -> tmux buffer (p first asks the outer terminal via -- `refresh-client -l`; only works if it allows OSC 52 reads) -- * SSH/remote -> OSC 52 copy + host-local paste cache (see below) -- * local macOS -> native pbcopy/pbpaste. -- Do NOT use OSC 52 locally: yanky's `sync_with_ring` reads the system -- clipboard, and OSC 52 reads depend on the terminal answering a query, which -- Ghostty refuses by default -> OSC 52 error + yanky stack trace. Neovim 0.12 -- also auto-prefers OSC 52 over pbcopy, so the macOS provider must be explicit. if vim.env.TMUX then vim.g.clipboard = "tmux" elseif vim.env.SSH_CONNECTION then -- Remote session (bare SSH, or a multiplexer like herdr that exports no env -- var of its own). Copy via OSC 52 so yanks reach the OUTER terminal's -- clipboard, but NEVER read the clipboard back: OSC 52 reads require the -- terminal to answer a query, which Warp/herdr/Ghostty don't, and the runtime -- reader then blocks for up to 10 s. Pasting FROM the Mac INTO nvim is the -- terminal's own paste (Cmd-V, bracketed paste; works in every mode). -- -- `p` returns the last copy made by ANY nvim on this host: copy() also writes -- {regtype, lines...} to stdpath("state")/clipboard/last (dir 0700, file 0600, -- atomic rename; writefile/readfile "b" keep NUL bytes and trailing empty -- lines), so a yank in one herdr pane pastes in another. Falls back to this -- instance's last copy. Over 8 MiB the shared file is removed, not left stale. -- No "nothing to paste" hint: yanky reads "+ when it loads, so paste() can't -- tell a user's `p` from a plugin's read. -- -- The paste function below must NOT call vim.fn.getreg('"')/'*'/'+' itself: -- Neovim's clipboard provider (autoload/provider/clipboard.vim) guards -- against re-entrant provider calls (`s:here`, see nvim#7184), so a getreg() -- of a clipboard-linked register issued from *inside* a registered paste() -- callback is swallowed and silently returns empty -- not the register's -- real content. It reads the shared file or what copy() was last given. -- Neither function may throw: an error would land in the middle of a yank. local osc52_send = require("vim.ui.clipboard.osc52").copy("+") local share_dir = vim.fn.stdpath("state") .. "/clipboard" local share_file = share_dir .. "/last" local SHARE_MAX, OSC52_WARN = 8 * 1024 * 1024, 512 * 1024 local last, dir_mode_set = { lines = {}, regtype = "v" }, false local stale -- identity of a shared file we failed to replace or remove local function file_id() local st = vim.uv.fs_stat(share_file) return st and ("%d:%d.%d:%d"):format(st.ino, st.mtime.sec, st.mtime.nsec, st.size) end local function share(lines, regtype, size) local tmp = ("%s.%d.tmp"):format(share_file, vim.uv.os_getpid()) local ok = pcall(function() if size > SHARE_MAX then error("too large to share") end if vim.fn.isdirectory(share_dir) == 0 then vim.fn.mkdir(share_dir, "p", tonumber("700", 8)) dir_mode_set = false end if not dir_mode_set then -- once per process, also for a pre-existing dir dir_mode_set = true vim.uv.fs_chmod(share_dir, tonumber("700", 8)) end local data = { regtype } vim.list_extend(data, lines) if vim.fn.writefile(data, tmp, "bS") ~= 0 then error("write failed") end assert(vim.uv.fs_chmod(tmp, tonumber("600", 8))) assert(vim.uv.fs_rename(tmp, share_file)) end) stale = nil if not ok then -- never serve a stale shared copy pcall(os.remove, tmp) pcall(os.remove, share_file) stale = file_id() -- still there (read-only dir): ignore it until replaced end end local function remember(lines, regtype) last.lines, last.regtype = lines, regtype local size = 0 for _, l in ipairs(lines) do size = size + #l + 1 end share(lines, regtype, size) return size end local function copy_plus(lines, regtype) local size = remember(lines, regtype) pcall(osc52_send, lines, regtype) if size > OSC52_WARN then vim.schedule(function() vim.notify(("Copied %d KiB via OSC 52; the terminal may drop payloads this large (nvim `p` on this host still has it)."):format(math.floor(size / 1024)), vim.log.levels.WARN) end) end end -- OSC 52 'p' (primary selection) means nothing on the Mac, so "* only updates -- the paste cache. A yank that fans out to "+ AND "* (provider: -- s:copy['*'] != s:copy['+'], i.e. 'clipboard' has unnamed) still sends -- exactly one OSC 52 sequence. local function copy_star(lines, regtype) remember(lines, regtype) end local function paste() if vim.fn.filereadable(share_file) == 1 and (not stale or file_id() ~= stale) then local ok, data = pcall(vim.fn.readfile, share_file, "b") if ok and type(data) == "table" and #data > 0 and data[1]:match("^[vVb]$") then local regtype = table.remove(data, 1) return { data, regtype } end end return { last.lines, last.regtype } end vim.g.clipboard = { name = "osc52-copyonly", copy = { ["+"] = copy_plus, ["*"] = copy_star }, paste = { ["+"] = paste, ["*"] = paste }, cache_enabled = 0, } elseif vim.fn.has("mac") == 1 then vim.g.clipboard = { name = "pbcopy", copy = { ["+"] = "pbcopy", ["*"] = "pbcopy" }, paste = { ["+"] = "pbpaste", ["*"] = "pbpaste" }, cache_enabled = 0, } end -- Make ordinary y/Y use the selected provider. LazyVim applies its SSH default -- after this file is read, so restore the option once startup has settled. The -- schedule keeps this callback after LazyVim's own VeryLazy clipboard callback. vim.api.nvim_create_autocmd("User", { pattern = "VeryLazy", once = true, callback = function() vim.schedule(function() vim.opt.clipboard = "unnamedplus" end) end, }) -- VS Code-like visual improvements vim.opt.cursorline = true -- Highlight current line -- vim.opt.colorcolumn = "80,120" -- Disabled: renders poorly with some themes vim.opt.scrolloff = 8 -- Keep 8 lines visible above/below cursor vim.opt.sidescrolloff = 8 -- Keep 8 columns visible left/right vim.opt.smoothscroll = true -- Smooth scrolling -- Shift+arrows start Select mode like a conventional editor: typing replaces -- the selection; / copy/cut it to the clipboard (keymaps.lua). -- Mouse drags start Visual mode so y/d/p work as usual (over SSH with -- mouse=a the terminal can't copy a drag itself). Keep `cmd` out of -- selectmode so v/V continue to enter Vim's Visual mode. vim.opt.keymodel = { "startsel", "stopsel" } vim.opt.selectmode = { "key" }