init.lua (5080B)
1 local config = require("config") 2 3 ------------------------- 4 -------- Options -------- 5 ------------------------- 6 vim.opt.autoindent = true 7 vim.opt.backup = false 8 vim.opt.breakindent = true 9 vim.opt.conceallevel = 2 10 vim.opt.expandtab = true 11 vim.opt.ignorecase = true 12 vim.opt.number = true 13 vim.opt.relativenumber = true 14 vim.opt.scrolloff = 8 15 vim.opt.shiftwidth = 0 16 vim.opt.smartcase = true 17 vim.opt.smartindent = true 18 vim.opt.softtabstop = 4 19 vim.opt.swapfile = false 20 vim.opt.swapfile = false 21 vim.opt.tabstop = 4 22 vim.opt.termguicolors = true 23 vim.opt.undodir = vim.fn.expand("~/.local/state/nvim/undodir") 24 vim.opt.undofile = true 25 vim.cmd("colorscheme retrobox") 26 27 -- Syntax highlighting will be handled by tree-sitter 28 vim.cmd('syntax off') 29 30 ------------------------- 31 -------- Keymaps -------- 32 ------------------------- 33 vim.g.mapleader = ' ' 34 35 local function map(mode, left, right, opts) 36 local default_opts = { 37 noremap = true, 38 silent = true, 39 } 40 opts = opts or {} 41 -- "keep" mode preserves the values from the leftmost table, 42 -- so prioritize any options provided over the defaults 43 local full_opts = vim.tbl_extend("keep", opts, default_opts) 44 vim.keymap.set(mode, left, right, full_opts) 45 end 46 47 -- Toggle background mode (light/dark) 48 map("n", "<leader>ct", function() 49 local target = vim.o.bg == "dark" and "light" or "dark" 50 vim.opt.background = target 51 end, { desc = "Toggle background mode (light/dark)" }) 52 53 -- Clear any highlighted searches when pressing Esc 54 -- This lets me leave hlsearch on by default while having an easy way to clear 55 -- it again. 56 map({ "i", "n" }, "<esc>", "<cmd>noh<cr><esc>", { desc = "Escape and clear hlsearch" }) 57 58 -- Move lines while in visual mode with J and K 59 map("v", "J", ":m '>+1<CR>gv=gv") 60 map("v", "K", ":m '<-2<CR>gv=gv") 61 62 -- Keep cursor in the same place when using J to join lines 63 map("n", "J", "mzJ`z") 64 65 -- Center the screen when jumping around with C-d and C-u 66 map("n", "<C-d>", "<C-d>zz") 67 map("n", "<C-u>", "<C-u>zz") 68 69 -- Center the screen when jumping to next / previous search terms 70 map("n", "n", "nzzzv") 71 map("n", "N", "Nzzzv") 72 73 -- Quick maps to paste/delete without overwriting the current buffer 74 map("x", "<leader>p", '"_dP') 75 map({ "n", "v" }, "<leader>d", '"_dP') 76 77 -- System clipboard 78 map({ "n", "v" }, "<leader>cd", '"+d', { desc = "Clipboard delete" }) 79 map({ "n", "v" }, "<leader>cp", '"+p', { desc = "Clipboard paste" }) 80 map({ "n", "v" }, "<leader>cy", '"+y', { desc = "Clipboard yank" }) 81 82 -- Compile faster 83 map("n", "<leader>cc", "<cmd>make %<cr><esc>", { desc = "Compile shortcut" }) 84 85 ------------------------- 86 -------- Plugins -------- 87 ------------------------- 88 vim.pack.add { 89 'https://github.com/stevearc/oil.nvim', 90 'https://github.com/nvim-treesitter/nvim-treesitter', 91 { src = "https://github.com/obsidian-nvim/obsidian.nvim", version = vim.version.range "*", }, 92 } 93 94 -- Obsidian 95 require("obsidian").setup { 96 legacy_commands = false, -- TODO: Remove legacy commands when/if this gets updated to v4.0 97 98 map("n", "<leader>o/", "<cmd>Obsidian search<cr>", { desc = "Open Obsidian search" }), 99 map("n", "<leader>op", "<cmd>Obsidian quick_switch<cr>", { desc = "Open Obsidian find files" }), 100 map("n", "<leader>on", "<cmd>Obsidian new<cr>", { desc = "Create new Obsidian note" }), 101 map("n", "<leader>ot", "<cmd>Obsidian today<cr>", { desc = "Open today's Obsidian daily note" }), 102 map("n", "<leader>oy", "<cmd>Obsidian yesterday<cr>", { desc = "Open yesterday's Obsidian daily note" }), 103 map("n", "<leader>ow", "<cmd>Obsidian tomorrow<cr>", { desc = "Open tomorrow's Obsidian daily note" }), 104 map("n", "<leader>od", "<cmd>Obsidian daily_note<cr>", { desc = "Open daily Obsidian note" }), 105 106 workspaces = config.obsidian_workspaces, 107 108 note_id_func = function(title) 109 local id = title:gsub(" ", "%-"):lower() 110 return id 111 end, 112 113 templates = { 114 folder = "templates", 115 date_format = "%Y-%m-%d-%a", 116 substitutions = { 117 friendly_date_format = function() 118 return os.date("%A %B %d, %Y") 119 end 120 }, 121 }, 122 123 daily_notes = { 124 folder = "dailies", 125 date_format = "%Y-%m-%d-%a", 126 alias_format = "%Y-%m-%d-%a", 127 template = "daily.md", 128 }, 129 130 -- Disable default behavior of entering insert mode by default 131 vim.api.nvim_create_autocmd("BufEnter", { 132 pattern = "*.md", 133 callback = function() 134 vim.cmd("stopinsert") 135 end, 136 }) 137 138 -- callbacks = { 139 -- enter_note = function() 140 -- -- The folds are too much for these notes 141 -- vim.opt_local.foldlevel = 99 142 -- vim.opt_local.foldlevelstart = 99 143 -- end, 144 -- }, 145 } 146 147 148 -- Oil 149 require('oil').setup({ 150 skip_confirm_for_simple_edits = true, 151 columns = {"size", "mtime"}, 152 map("n", "g-", vim.cmd.Oil, { desc = "Open Oil" }), 153 }) 154 155 -- Tree-sitter 156 require('nvim-treesitter').setup() 157 vim.api.nvim_create_autocmd('FileType', { 158 callback = function() pcall(vim.treesitter.start) end, 159 })