From 387e08c52d9752bc839c71119f140ba8435c3d70 Mon Sep 17 00:00:00 2001 From: Yigit Sever Date: Fri, 18 Aug 2023 23:42:39 +0300 Subject: nvim: switch to lazy.nvim revert this as whole, if you miss the good old days --- .config/nvim/lua/core/keymaps.lua | 77 ++++++++++++++++++++++++++++++ .config/nvim/lua/core/lazy.lua | 30 ++++++++++++ .config/nvim/lua/core/options.lua | 98 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 205 insertions(+) create mode 100644 .config/nvim/lua/core/keymaps.lua create mode 100644 .config/nvim/lua/core/lazy.lua create mode 100644 .config/nvim/lua/core/options.lua (limited to '.config/nvim/lua/core') diff --git a/.config/nvim/lua/core/keymaps.lua b/.config/nvim/lua/core/keymaps.lua new file mode 100644 index 0000000..b63156d --- /dev/null +++ b/.config/nvim/lua/core/keymaps.lua @@ -0,0 +1,77 @@ +local map = require("helpers.keys").map + +-- https://stackoverflow.com/questions/4256697/vim-search-and-highlight-but-do-not-jump +-- search & highlight but do not jump +map("n", "*", "keepjumps normal! mi*`i", "search forwards") +map("n", "#", "keepjumps normal! mi#`i", "search backwards") + +-- save file as sudo on files that require root permission +map("c", "w!!", 'execute "silent! write !sudo tee % >/dev/null" edit!', "save file as sudo", { silent = false }) + +-- replace ex mode with gq (format lines) +map("n", "Q", "gq", "format lines") + +-- set formatprg to sentences, for prose +-- TODO: can we do this with vim.o.formatprg? +map("n", "fp", "set formatprg=~/.local/bin/sentences", "switch to sentences view", { silent = false }) + +-- replace all is aliased to S. +map("n", "S", ":s//g", "replace all", { silent = false }) +map("v", "S", ":s//g", "replace all selection", { silent = false }) + +-- jump to buffer +map("n", "b", "ls:b", "jump to buffer") + +-- up and down are more logical with g.. +map("n", "k", '(v:count == 0 ? "gk" : "k")', "up", { expr = true }) +map("n", "j", '(v:count == 0 ? "gj" : "j")', "down", { expr = true }) +map("i", "", "gka") +map("i", "", "gja") + +-- space used to toggle folds, now it's x (because x is d) +map("n", "", '"_x') + +-- separate cut and delete +map("n", "x", "d") +map("x", "x", "d") +map("n", "xx", "dd") +map("n", "X", "D") + +-- change into pwd of current buffer +map("n", "cd", "lcd %:p:h:pwd", "cd to current buffer's pwd") + +-- call CreatePaper on word below cursor +map("n", "np", 'gewi[[/papers/Ea]]bb:call CreatePaper(expand(""))', + "vimwiki new paper on word under cursor") + +-- link paper +map("n", "lp", "gewi[[/papers/Ea]]", "vimwiki link wrap word under cursor") + +-- call CreateReference on word below cursor +map("n", "nr", 'call CreateReference(expand(""))', "vimwiki new reference word under cursor") + +-- create a new note +map("n", "nn", "call CreateNote()", "vimwiki new note for slipbox") + +-- :%% to get current file path +map('c', '%%', "getcmdtype() == ':' ? expand('%:h').'/' : '%%'", "get current file path", { expr = true, silent = false }) + +-- reselect visual selection after indent +map('v', '>', '>gv') +map('v', '<', 'ut", function() + if vim.o.background == "dark" then + vim.o.background = "light" + else + vim.o.background = "dark" + end +end, "toggle between light and dark background") diff --git a/.config/nvim/lua/core/lazy.lua b/.config/nvim/lua/core/lazy.lua new file mode 100644 index 0000000..8a91029 --- /dev/null +++ b/.config/nvim/lua/core/lazy.lua @@ -0,0 +1,30 @@ +-- install lazy.nvim if not already installed +local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" +if not vim.loop.fs_stat(lazypath) then + vim.fn.system({ + "git", + "clone", + "--filter=blob:none", + "https://github.com/folke/lazy.nvim.git", + "--branch=stable", -- latest stable release + lazypath, + }) +end +vim.opt.rtp:prepend(lazypath) + +-- use a protected call so we don't error out on first use +local ok, lazy = pcall(require, "lazy") +if not ok then + return +end + +-- we have to set the leader key here for lazy.nvim to work +require("helpers.keys").set_leader("\\") + +-- load plugins from specifications +-- see: https://github.com/folke/lazy.nvim#-structuring-your-plugins +-- we are loading them as a lua module +lazy.setup("plugins") + +-- easy-access keybindings +require("helpers.keys").map("n", "L", lazy.show, "show lazy") diff --git a/.config/nvim/lua/core/options.lua b/.config/nvim/lua/core/options.lua new file mode 100644 index 0000000..3299e83 --- /dev/null +++ b/.config/nvim/lua/core/options.lua @@ -0,0 +1,98 @@ +local opts = { + -- this might not be needed anymore + termguicolors = true, + + -- copy indent on a new line + autoindent = true, + + -- :h tabstop, 2. point + -- use appropriate number of spaces to insert a + expandtab = true, + shiftwidth = 4, + softtabstop = 4, + tabstop = 8, + + -- use english for spellchecking + spelllang = "en_gb", + + -- tab completion, zsh style + wildmode = "longest:full,full", + + -- put one space for join (not two) + joinspaces = false, + + -- keep n lines above/below cursor while scrolling + scrolloff = 4, + + -- line numbers + number = true, + + -- manual folding + foldmethod = "marker", + + -- set the terminal title + title = true, + + -- wrap using 'breakat' character + linebreak = true, + + -- new split panes will split to below and right + splitbelow = true, + splitright = true, + + -- use relative line numbers + relativenumber = true, + + -- we are already using a cursorline, don't clobber linter messages + showmode = false, + + -- jump to the matching bracket briefly + showmatch = true, + + -- persistent undo + undofile = true, + + -- lower case searches ignore case, upper case searches do not + ignorecase = true, + smartcase = true, + + -- https://stackoverflow.com/a/3445040/ + -- switch case labels + cinoptions = "l1", + +} + +for opt, val in pairs(opts) do + vim.o[opt] = val +end + +-- set other options +-- local colorscheme = require("helpers.colorscheme") +-- vim.cmd.colorscheme(colorscheme) + +-- interact with system clipboard +vim.opt.clipboard:append('unnamedplus') + +vim.opt.wildignore = { + '*.o', '*.obj', '*.class', '*.aux', '*.lof', '*.log', '*.lot', '*.fls', + '*.toc', '*.fmt', '*.fot', '*.cb', '*.cb2', '.*.lb', '.dvi', '*.xdv', + '*.bbl', '*.bcf', '*.blg', '*-blx.aux', '*-blx.bib', '*.run.xml', + '*.fdb_latexmk', '*.synctex', '*.synctex(busy)', '*.synctex.gz', + '*.synctex.gz(busy)', '*.pdfsync' +} + +-- iwhite: ignore changes in amount of white space. +-- vertical: start diff mode with vertical splits +-- filler: show filler lines, +vim.opt.diffopt = { + "iwhite", "vertical", "filler", "algorithm:patience", "indent-heuristic" +} + +-- menu: use a popup menu to show the possible completions +-- preview: show extra information +vim.opt.completeopt = {"menu", "menuone", "noselect"} + +if vim.fn.executable("rg") then + vim.o.grepprg = "rg --vimgrep --no-heading --smart-case" + vim.o.grepformat = "%f:%l:%c:%m,%f:%l:%m" +end -- cgit v1.2.3-70-g09d2