From 1974fc33bf0b8de21bff894678e8d88b80e5e9d2 Mon Sep 17 00:00:00 2001 From: Jake Ginesin Date: Fri, 10 Jan 2025 22:16:36 -0500 Subject: [PATCH] 187 current 2025-01-10 22:16:28 25.05.20241217.d3c42f1 6.6.66 * --- home/programs/nvim/default.nix | 10 ++- home/programs/nvim/init.lua | 145 +++++++++++++++++++++++++++++++++ 2 files changed, 154 insertions(+), 1 deletion(-) create mode 100644 home/programs/nvim/init.lua diff --git a/home/programs/nvim/default.nix b/home/programs/nvim/default.nix index d6a584c..98bcf7b 100644 --- a/home/programs/nvim/default.nix +++ b/home/programs/nvim/default.nix @@ -5,6 +5,14 @@ }: { programs.neovim = { enable = true; - extraConfig = lib.fileContents ./init.vim; + viAlias = true; + vimAlias = true; + vimdiffAlias = true; + + extraLuaConfig = '' + ${builtins.readFile ./init.lua} + ''; + + # extraConfig = lib.fileContents ./init.vim; }; } diff --git a/home/programs/nvim/init.lua b/home/programs/nvim/init.lua new file mode 100644 index 0000000..82a11c9 --- /dev/null +++ b/home/programs/nvim/init.lua @@ -0,0 +1,145 @@ +-- ========================================================= +-- FILE: init.lua +-- A translation of the provided Vimscript config to Lua. +-- ========================================================= + +-- filetype detection / plugin / indent +vim.cmd([[ + filetype on + filetype plugin on + filetype indent on + syntax on +]]) + +-- Basic UI +vim.opt.number = true -- set number +vim.opt.relativenumber = false -- 'set nu' in Vimscript doesn't mean relative. If you prefer relativenumber, set it to true +vim.opt.showcmd = true +vim.opt.showmode = true +vim.opt.showmatch = true -- highlights matching brackets +vim.opt.hlsearch = true +vim.opt.history = 1000 +vim.opt.wrap = false +vim.opt.scrolloff = 10 +vim.opt.incsearch = true +vim.opt.ignorecase = true +vim.opt.smartcase = true + +-- Tab / indentation +vim.opt.tabstop = 2 +vim.opt.softtabstop = 2 +vim.opt.shiftwidth = 2 +vim.opt.smarttab = true +vim.opt.cindent = true +vim.opt.expandtab = true + +-- Turn off backups, swaps +vim.opt.backup = false +vim.opt.swapfile = false +vim.opt.undofile = true +vim.opt.undodir = os.getenv("HOME") .. "/.local/share/nvim/cache" + +-- For line length column marking +vim.opt.colorcolumn = "0" +vim.opt.textwidth = 0 -- alternative if you want no fixed textwidth + +-- Some other miscellaneous settings +vim.opt.shortmess:append("c") -- don't give |ins-completion-menu| messages +vim.opt.wildmenu = true +vim.opt.wildmode = { "longest", "list" } +vim.opt.wildignore:append({ + "*.docx", "*.jpg", "*.png", "*gif", "*.pdf", "*.pyc", + "*.exe", "*.flv", "*.img", "*.png" +}) +vim.opt.termguicolors = true -- truecolor mode +vim.opt.mouse = "a" -- enable mouse +vim.opt.splitright = true +vim.opt.splitbelow = true +vim.opt.updatetime = 300 -- faster completion +vim.opt.signcolumn = "auto" +vim.opt.title = true +vim.opt.titlestring = "%(%{expand(\"%:~:h\")}%)#%(% t%)%(% M%)%(% )NVIM" + +-- Append '+' register to clipboard +vim.opt.clipboard:append("unnamedplus") + +-- Stop showing matching paren (and disable matchparen plugin) +vim.g.loaded_matchparen = 1 +vim.opt.showmatch = false + +-- t_ZH, t_ZR (italics) — for older terminal support +vim.cmd([[ let &t_ZH = "\e[3m" ]]) +vim.cmd([[ let &t_ZR = "\e[23m" ]]) + +-- netrw settings +vim.g.netrw_banner = 0 +vim.g.netrw_liststyle = 0 +vim.g.netrw_browse_split = 4 +vim.g.netrw_altv = 1 +vim.g.netrw_winsize = 25 +vim.g.netrw_keepdir = 0 +vim.g.netrw_localcopydircmd = "cp -r" + +-- Remember cursor location (viminfo) +vim.opt.viminfo = "'100,\"2500,:200,%,n~/.cache/.viminfo" + +-- Encodings +vim.opt.fileencodings = { "utf-8" } +vim.opt.encoding = "utf-8" + +-- Leader key +vim.g.mapleader = "," + +------------------------------------------------------ +-- KEY MAPPINGS +------------------------------------------------------ +local opts = { noremap = true, silent = true } + +-- Clear search highlights when pressing ESC in normal mode +vim.api.nvim_set_keymap("n", "", ":noh", opts) + +-- The literal mapping from the original: "nnoremap ^[ ^[" +vim.api.nvim_set_keymap("n", "^[", "^[", { noremap = true }) + +-- inoremap { {}O} +vim.api.nvim_set_keymap("i", "{", "{}O", { noremap = true }) + +-- Save file with Ctrl+S +vim.cmd([[ + command -nargs=0 -bar Update if &modified + \| if empty(bufname('%')) + \| browse confirm write + \| else + \| confirm write + \| endif + \|endif +]]) +vim.api.nvim_set_keymap("n", "", ":Update", opts) +vim.api.nvim_set_keymap("i", "", ":Update", opts) + +-- Terminal toggles +vim.api.nvim_set_keymap("n", "", ":termA", { noremap = true, silent = false }) +vim.api.nvim_set_keymap("t", "", [[]], { noremap = true }) + +-- "Focus" commands that rely on the Goyo plugin +vim.api.nvim_set_keymap("n", "z", ":Goyo 80", opts) +vim.api.nvim_set_keymap("n", "q", ":Goyo!", opts) + +-- Movements in visual mode +vim.api.nvim_set_keymap("x", "", "b", { noremap = true }) +vim.api.nvim_set_keymap("x", "", "w", { noremap = true }) + +-- Map Ctrl-Backspace to delete the previous word in insert mode +vim.api.nvim_set_keymap("i", "", "", { noremap = true }) +vim.api.nvim_set_keymap("i", "", "", { noremap = true }) + +------------------------------------------------------ +-- AUTOCMD +------------------------------------------------------ +local wrapLineInTexFile = vim.api.nvim_create_augroup("WrapLineInTexFile", { clear = true }) +vim.api.nvim_create_autocmd("FileType", { + pattern = { "md" }, + group = wrapLineInTexFile, + command = "setlocal wrap" +}) +