diff options
Diffstat (limited to '.config/nvim/lua/core')
-rw-r--r-- | .config/nvim/lua/core/keymaps.lua | 77 | ||||
-rw-r--r-- | .config/nvim/lua/core/lazy.lua | 30 | ||||
-rw-r--r-- | .config/nvim/lua/core/options.lua | 98 |
3 files changed, 205 insertions, 0 deletions
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 @@ | |||
1 | local map = require("helpers.keys").map | ||
2 | |||
3 | -- https://stackoverflow.com/questions/4256697/vim-search-and-highlight-but-do-not-jump | ||
4 | -- search & highlight but do not jump | ||
5 | map("n", "*", "<cmd>keepjumps normal! mi*`i<CR>", "search forwards") | ||
6 | map("n", "#", "<cmd>keepjumps normal! mi#`i<CR>", "search backwards") | ||
7 | |||
8 | -- save file as sudo on files that require root permission | ||
9 | map("c", "w!!", 'execute "silent! write !sudo tee % >/dev/null" <bar> edit!<CR>', "save file as sudo", { silent = false }) | ||
10 | |||
11 | -- replace ex mode with gq (format lines) | ||
12 | map("n", "Q", "gq", "format lines") | ||
13 | |||
14 | -- set formatprg to sentences, for prose | ||
15 | -- TODO: can we do this with vim.o.formatprg? | ||
16 | map("n", "<Leader>fp", "<cmd>set formatprg=~/.local/bin/sentences<CR>", "switch to sentences view", { silent = false }) | ||
17 | |||
18 | -- replace all is aliased to S. | ||
19 | map("n", "S", ":s//g<Left><Left>", "replace all", { silent = false }) | ||
20 | map("v", "S", ":s//g<Left><Left>", "replace all selection", { silent = false }) | ||
21 | |||
22 | -- jump to buffer | ||
23 | map("n", "<Leader>b", "<cmd>ls<cr>:b<space>", "jump to buffer") | ||
24 | |||
25 | -- up and down are more logical with g.. | ||
26 | map("n", "k", '(v:count == 0 ? "gk" : "k")', "up", { expr = true }) | ||
27 | map("n", "j", '(v:count == 0 ? "gj" : "j")', "down", { expr = true }) | ||
28 | map("i", "<Up>", "<Esc>gka") | ||
29 | map("i", "<Down>", "<Esc>gja") | ||
30 | |||
31 | -- space used to toggle folds, now it's x (because x is d) | ||
32 | map("n", "<Space>", '"_x') | ||
33 | |||
34 | -- separate cut and delete | ||
35 | map("n", "x", "d") | ||
36 | map("x", "x", "d") | ||
37 | map("n", "xx", "dd") | ||
38 | map("n", "X", "D") | ||
39 | |||
40 | -- change into pwd of current buffer | ||
41 | map("n", "<Leader>cd", "<cmd>lcd %:p:h<CR>:pwd<CR>", "cd to current buffer's pwd") | ||
42 | |||
43 | -- call CreatePaper on word below cursor | ||
44 | map("n", "<leader>np", 'gewi[[/papers/<ESC>Ea]]<ESC>bb:call CreatePaper(expand("<cword>"))<CR>', | ||
45 | "vimwiki new paper on word under cursor") | ||
46 | |||
47 | -- link paper | ||
48 | map("n", "<leader>lp", "gewi[[/papers/<ESC>Ea]]<ESC>", "vimwiki link wrap word under cursor") | ||
49 | |||
50 | -- call CreateReference on word below cursor | ||
51 | map("n", "<leader>nr", '<cmd>call CreateReference(expand("<cword>"))<CR>', "vimwiki new reference word under cursor") | ||
52 | |||
53 | -- create a new note | ||
54 | map("n", "<leader>nn", "<cmd>call CreateNote()<CR>", "vimwiki new note for slipbox") | ||
55 | |||
56 | -- :%% to get current file path | ||
57 | map('c', '%%', "getcmdtype() == ':' ? expand('%:h').'/' : '%%'", "get current file path", { expr = true, silent = false }) | ||
58 | |||
59 | -- reselect visual selection after indent | ||
60 | map('v', '>', '>gv') | ||
61 | map('v', '<', '<gv') | ||
62 | |||
63 | -- keep cursor position after visual yank | ||
64 | map('v', 'y', 'myy`y') | ||
65 | map('v', 'Y', 'myY`y') | ||
66 | |||
67 | -- ` is more useful than ' | ||
68 | map('n', "'", '`') | ||
69 | |||
70 | -- switch between light and dark modes | ||
71 | map("n", "<leader>ut", function() | ||
72 | if vim.o.background == "dark" then | ||
73 | vim.o.background = "light" | ||
74 | else | ||
75 | vim.o.background = "dark" | ||
76 | end | ||
77 | 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 @@ | |||
1 | -- install lazy.nvim if not already installed | ||
2 | local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" | ||
3 | if not vim.loop.fs_stat(lazypath) then | ||
4 | vim.fn.system({ | ||
5 | "git", | ||
6 | "clone", | ||
7 | "--filter=blob:none", | ||
8 | "https://github.com/folke/lazy.nvim.git", | ||
9 | "--branch=stable", -- latest stable release | ||
10 | lazypath, | ||
11 | }) | ||
12 | end | ||
13 | vim.opt.rtp:prepend(lazypath) | ||
14 | |||
15 | -- use a protected call so we don't error out on first use | ||
16 | local ok, lazy = pcall(require, "lazy") | ||
17 | if not ok then | ||
18 | return | ||
19 | end | ||
20 | |||
21 | -- we have to set the leader key here for lazy.nvim to work | ||
22 | require("helpers.keys").set_leader("\\") | ||
23 | |||
24 | -- load plugins from specifications | ||
25 | -- see: https://github.com/folke/lazy.nvim#-structuring-your-plugins | ||
26 | -- we are loading them as a lua module | ||
27 | lazy.setup("plugins") | ||
28 | |||
29 | -- easy-access keybindings | ||
30 | require("helpers.keys").map("n", "<leader>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 @@ | |||
1 | local opts = { | ||
2 | -- this might not be needed anymore | ||
3 | termguicolors = true, | ||
4 | |||
5 | -- copy indent on a new line | ||
6 | autoindent = true, | ||
7 | |||
8 | -- :h tabstop, 2. point | ||
9 | -- use appropriate number of spaces to insert a <Tab> | ||
10 | expandtab = true, | ||
11 | shiftwidth = 4, | ||
12 | softtabstop = 4, | ||
13 | tabstop = 8, | ||
14 | |||
15 | -- use english for spellchecking | ||
16 | spelllang = "en_gb", | ||
17 | |||
18 | -- tab completion, zsh style | ||
19 | wildmode = "longest:full,full", | ||
20 | |||
21 | -- put one space for join (not two) | ||
22 | joinspaces = false, | ||
23 | |||
24 | -- keep n lines above/below cursor while scrolling | ||
25 | scrolloff = 4, | ||
26 | |||
27 | -- line numbers | ||
28 | number = true, | ||
29 | |||
30 | -- manual folding | ||
31 | foldmethod = "marker", | ||
32 | |||
33 | -- set the terminal title | ||
34 | title = true, | ||
35 | |||
36 | -- wrap using 'breakat' character | ||
37 | linebreak = true, | ||
38 | |||
39 | -- new split panes will split to below and right | ||
40 | splitbelow = true, | ||
41 | splitright = true, | ||
42 | |||
43 | -- use relative line numbers | ||
44 | relativenumber = true, | ||
45 | |||
46 | -- we are already using a cursorline, don't clobber linter messages | ||
47 | showmode = false, | ||
48 | |||
49 | -- jump to the matching bracket briefly | ||
50 | showmatch = true, | ||
51 | |||
52 | -- persistent undo | ||
53 | undofile = true, | ||
54 | |||
55 | -- lower case searches ignore case, upper case searches do not | ||
56 | ignorecase = true, | ||
57 | smartcase = true, | ||
58 | |||
59 | -- https://stackoverflow.com/a/3445040/ | ||
60 | -- switch case labels | ||
61 | cinoptions = "l1", | ||
62 | |||
63 | } | ||
64 | |||
65 | for opt, val in pairs(opts) do | ||
66 | vim.o[opt] = val | ||
67 | end | ||
68 | |||
69 | -- set other options | ||
70 | -- local colorscheme = require("helpers.colorscheme") | ||
71 | -- vim.cmd.colorscheme(colorscheme) | ||
72 | |||
73 | -- interact with system clipboard | ||
74 | vim.opt.clipboard:append('unnamedplus') | ||
75 | |||
76 | vim.opt.wildignore = { | ||
77 | '*.o', '*.obj', '*.class', '*.aux', '*.lof', '*.log', '*.lot', '*.fls', | ||
78 | '*.toc', '*.fmt', '*.fot', '*.cb', '*.cb2', '.*.lb', '.dvi', '*.xdv', | ||
79 | '*.bbl', '*.bcf', '*.blg', '*-blx.aux', '*-blx.bib', '*.run.xml', | ||
80 | '*.fdb_latexmk', '*.synctex', '*.synctex(busy)', '*.synctex.gz', | ||
81 | '*.synctex.gz(busy)', '*.pdfsync' | ||
82 | } | ||
83 | |||
84 | -- iwhite: ignore changes in amount of white space. | ||
85 | -- vertical: start diff mode with vertical splits | ||
86 | -- filler: show filler lines, | ||
87 | vim.opt.diffopt = { | ||
88 | "iwhite", "vertical", "filler", "algorithm:patience", "indent-heuristic" | ||
89 | } | ||
90 | |||
91 | -- menu: use a popup menu to show the possible completions | ||
92 | -- preview: show extra information | ||
93 | vim.opt.completeopt = {"menu", "menuone", "noselect"} | ||
94 | |||
95 | if vim.fn.executable("rg") then | ||
96 | vim.o.grepprg = "rg --vimgrep --no-heading --smart-case" | ||
97 | vim.o.grepformat = "%f:%l:%c:%m,%f:%l:%m" | ||
98 | end | ||