-- ########################### -- the heart of neovim ####### -- ########################### require("helpers.functions") -- gloabal settings vim.keymap.set('n', 'q', function() local success, _ = pcall(function() vim.cmd('wa') -- Write (save) all buffers end) vim.cmd('qa!') -- Quit all buffers forcefully end) vim.keymap.set("n", "w", "w") vim.keymap.set('v', 'p', function() vim.cmd('normal! "+p') end, { desc = 'Yank to clipboard and keep the selection' }) -- branching depeding on diff mode if vim.g.diffm then -- diff view commands vim.keymap.set('n', 'do', ":DiffviewClose:DiffviewOpen") vim.keymap.set('n', 'df', ":DiffviewClose:DiffviewFileHistory") vim.keymap.set('n', 'dt', ":DiffviewToggleFiles") vim.keymap.set('n', 'dc', ":DiffviewClose") vim.keymap.set('n', 'dl', ":DiffviewLog") -- vim.keymap.set("n", "e", "ww") else -- not in diff mode -- TODO: make this dynamic local season = "S2" local links = require("helpers.linker") -- replace with real file path local user = vim.fn.system('whoami'):gsub('\n', '') local api = require("nvim-tree.api") local builtin = require('telescope.builtin') local current_date = os.date("%Y-%m-%d") local week_number = os.date("%W") + 1 -- Week number (starting from Sunday) local day_of_week = os.date("%a") -- Abbreviated weekday name (e.g., Mon, Tue) -- this is how to access global vars function set_obs() -- _G is the global table. this creates variable 'obs' attached to -- the global table with the value 'some text value' _G.season = season end --------------------- NORMAL ------------------------- -- vim.keymap.set("i", "", "", { silent = true }) vim.keymap.set("n", "L", ":BufferNext", { silent = true }) -- also update the root with the bang vim.keymap.set("n", "n", "nzz", { silent = true }) -- also update the root with the bang vim.keymap.set("n", "N", "Nzz", { silent = true }) -- also update the root with the bang vim.keymap.set("n", "H", ":BufferPrevious", { silent = true }) -- also update the root with the bang vim.keymap.set("n", "", "zz", { silent = true }) -- also update the root with the bang vim.keymap.set("n", "", "zz", { silent = true }) -- also update the root with the bang vim.keymap.set("n", "", "zz", { silent = true }) -- also update the root with the bang vim.keymap.set("n", "", "zz", { silent = true }) -- also update the root with the bang vim.keymap.set('n', 'a', 'm9ggVG"+y`9') vim.keymap.set('n', 'va', 'ggVG') -- Launch panel if nothing is typed after z vim.keymap.set("n", "z", "Telekasten panel") -- Most used functions vim.keymap.set("n", "zf", "Telekasten find_notes") vim.keymap.set("n", "zg", "Telekasten search_notes") vim.keymap.set('n', 'zq', ':e ~/synced/brainstore/zettelkasten/input.txt`.zz') vim.keymap.set("n", "zd", "Telekasten goto_today") vim.keymap.set("n", "zr", "Telekasten rename_note") vim.keymap.set("n", "zz", "Telekasten follow_link") vim.keymap.set("n", "zn", "Telekasten new_note") vim.keymap.set("n", "zb", "Telekasten show_backlinks") vim.keymap.set("n", "zw", "Telekasten find_weekly_notes") vim.keymap.set("n", "zI", "Telekasten insert_img_link") vim.keymap.set("n", "me", ":mes") vim.keymap.set("n", "", ":ToggleTerm") vim.keymap.set("t", "", ":ToggleTerm") vim.keymap.set("n", "snt", "set nu") vim.keymap.set("n", "snf", "set nonu") -- Call insert link automatically when we start typing a link vim.keymap.set("n", "il", "Telekasten insert_link") require("custom.uni") vim.keymap.set("n", "nv", function() select_course_directory() --pick_unicourse("/home/jonas/projects/university/S2") -- Change path accordingly end, { desc = "Open UniCourse menu" }) vim.keymap.set('n', 'ca', 'ggVGd') vim.keymap.set("n", "bd", ":BufferDelete", { silent = true }) -- also update the root with the bang -- Typstar stuff vim.keymap.set("n", "ti", ":TypstarInsertRnote", { silent = true }) -- also update the root with the bang vim.keymap.set("n", "to", ":TypstarOpenDrawing", { silent = true }) -- also update the root with the bang -- Get a ready to use terminal vim.keymap.set('n', 'tr', ':tabnew:termi') vim.keymap.set("n", "tt", ":Telescope", { desc = "Follow Link" }) vim.keymap.set('n', 'tw', watch_and_open, { noremap = true, silent = true }) -- This needs to be refined for quick access to a new file or a recently edited one vim.keymap.set('n', 'ov', open_vorlesung) -- new quick note file -- TODO: make this smarter vim.keymap.set("n", "nn", ":e ~/synced/brainstore/zettelkasten/quick", { silent = true }) -- also update the root with the bang vim.keymap.set("n", "r", set_root) -- Custom journal plugin disable temporary -- local journal = require("custom.journal") -- vim.keymap.set("n", "jt", journal.open_today, { desc = "Open Today's Journal" }) -- vim.keymap.set("n", "ja", journal.list_all_journals, { desc = "Open Today's Journal" }) -- vim.keymap.set("n", "jm", journal.search_this_month, { desc = "Search This Month's Journals" }) -- Quickly open some buffers -- Open all the vim configs instant vim.keymap.set('n', 'occ', ':e ~/.config/nvim/init.lua`.zz') vim.keymap.set('n', 'oct', ':e ~/synced/vault/contacts/contacts.txt`.zz') vim.keymap.set('n', 'ock', ':e ~/.config/nvim/lua/config/keymaps.lua`.zz') vim.keymap.set('n', 'ocd', ':e ~/.config/nvim/lua/config/autocmds.lua`.zz') vim.keymap.set('n', 'oco', ':e ~/.config/nvim/lua/config/options.lua`.zz') vim.keymap.set('n', 'ocl', ':e ~/.config/nvim/lua/config/lazy.lua`.zz') vim.keymap.set('n', 'oczl', ':e ~/.config/nvim/lua/config/lsp.lua`.zz') vim.keymap.set('n', 'ocp', ':e ~/.config/nvim/lua/plugins/main.lua`.zz') vim.keymap.set('n', 'ocf', ':e ~/.config/nvim/lua/helpers/functions.lua`.zz') vim.keymap.set('n', 'oca', ':e ~/.config/nvim/lua/helpers/after.lua`.zz') vim.keymap.set('n', 'oq', ':e ~/synced/brainstore/input.txt`.zz') vim.keymap.set('n', 'ohh', ':e ~/configuration/nixos/users/' .. user .. '/home.nix`.zz') vim.keymap.set('n', 'op', ':e ~/configuration/nixos/users/' .. user .. '/packages.nix`.zz') vim.keymap.set('n', 'on', ':e ~/configuration/nixos/configuration.nix`.zz') vim.keymap.set('n', 'om', ':e ~/configuration/nixos/modules') vim.keymap.set('n', 'ow', ':e ~/synced/brainstore/waste.txt') vim.keymap.set('n', 'oho', ':e ~/configuration/nixos/hosts') vim.keymap.set('n', 'os', ':e ~/configuration/nixos/modules/server') vim.keymap.set('n', 'ot', ':e ~/synced/brainstore/todos/todo.txt`.zz') vim.keymap.set('n', 'od', ':e ~/synced/brainstore/todos/done.txt`.zz') vim.keymap.set('n', 'ou', ':e ~/projects/university/' .. season .. '/input.txt`.zz') vim.keymap.set('n', 'oz', ':e ~/.zshrc`.zz') vim.keymap.set('n', 'oaa', ':e ~/.common_shell`.zz') -- Map the function to a keybinding (e.g., lf to open the last file) vim.keymap.set("n", "or", "lua open_last_file()", { noremap = true, silent = true }) -- open the calendar -- function open_cal() local current_date = os.date("%Y-%m-%d") local week_number = os.date("%V") local day_of_week = os.date("%a") local path = "~/synced/brainstore/calendar/calendar_" .. os.date("%Y") .. ".txt" local keys = ":e " .. path .. "/" .. current_date .. " w" .. tonumber(week_number) .. " " .. day_of_week .. "$" vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(keys, true, false, true), 'n', true) end vim.keymap.set('n', 'ok', open_cal) ------------------------------------------------------------------------------------- vim.keymap.set("n", "lf", links.insert_brainstore_link, { desc = "Link Brainstore file" }) vim.keymap.set("n", "lm", links.insert_mail_link, { desc = "Link Mail" }) vim.keymap.set('n', 'll', ':Lazy') vim.keymap.set("n", "lp", links.insert_project_link, { desc = "Link Project" }) vim.keymap.set("n", "lc", links.insert_contact_link, { desc = "Link Contact" }) vim.keymap.set("n", "ld", links.insert_date_link, { desc = "Link Contact" }) -- nvim tree vim.keymap.set("n", "e", function() api.tree.toggle({ find_file = true, update_root = true, focus = true, }) end, { silent = true }) -- also update the root with the bang vim.keymap.set('n', 'ia', 'gg=Gzz') vim.keymap.set('n', 'ya', 'ggVG"+y') -- Map q to save and quit all buffers with error handling -- Dangerous but feels good vim.keymap.set('n', 'ss', ':wa') vim.keymap.set('n', 'sw', function() local word = vim.fn.expand("") local replacement = vim.fn.input("Replace '" .. word .. "' with: ") if replacement ~= "" then vim.cmd(string.format("%%s/\\<%s\\>/%s/gI", vim.fn.escape(word, '\\/'), vim.fn.escape(replacement, '\\/'))) end end, { desc = "Substitute word under cursor (prompt)" }) vim.keymap.set('v', 'sv', function() -- Save the current selection local save_reg = vim.fn.getreg('"') local save_regtype = vim.fn.getregtype('"') -- Yank the visual selection into the " register vim.cmd('normal! ""y') local selection = vim.fn.getreg('"') -- Escape magic characters for the search selection = vim.fn.escape(selection, '\\/.*$^~[]') -- Prompt for the replacement text local replacement = vim.fn.input("Replace '" .. selection .. "' with: ") if replacement ~= "" then vim.cmd(string.format("%%s/%s/%s/gI", selection, replacement)) end -- Restore previous register vim.fn.setreg('"', save_reg, save_regtype) end, { desc = "Substitute selection in file" }) -- vim.keymap.set('n', 'sl', search_brain_links) vim.keymap.set('n', 'pp', function() vim.api.nvim_command('normal! "+p') end, { desc = 'Paste from system clipboard' }) -- vim.keymap.set('n', 'fg', builtin.live_grep, { desc = 'Telescope live grep' }) vim.keymap.set('n', 'fr', function() require('telescope.builtin').oldfiles({ disable_devicons = true, }) end, { noremap = true, silent = true }) vim.keymap.set('n', 'fb', builtin.buffers, { desc = 'Telescope buffers' }) vim.keymap.set('n', 'fh', builtin.help_tags, { desc = 'Telescope help tags' }) vim.keymap.set("n", "fl", links.follow_link, { desc = "Follow Link" }) vim.keymap.set('n', 'g', function() require('telescope.builtin').live_grep({ disable_devicons = true, cwd = vim.fn.getcwd(), -- set the starting directory additional_args = function() return { '--hidden', '--glob', '!.git/*' } -- include hidden files but exclude .git end, }) end, { noremap = true, silent = true }) vim.keymap.set('n', '', find_eff, { desc = 'Telescope find files (with dotfiles and folders but excluding .git, .cache, .local, and large files)' }) ------------------------ VISUAL ------------------ vim.keymap.set('v', 'p', function() local unnamed_content = vim.fn.getreg('""') vim.api.nvim_command('normal! p') vim.fn.setreg('""', unnamed_content) end, { desc = 'Paste from unnamed register (don\'t overwrite it) in visual mode' }) vim.keymap.set('v', 'y', function() vim.cmd('normal! "+y') vim.cmd('normal! gv') end, { desc = 'Yank to clipboard and keep the selection' }) ---------------------------- INSERT --------------------------- vim.keymap.set('i', '', function() local col = vim.fn.col('.') local line = vim.fn.line('.') local line_len = vim.fn.col('$') - 1 if col <= line_len then vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes('', true, false, true), 'n', true) else if line < vim.fn.line('$') then vim.cmd('normal! j^') end end end) -- Move left with wrapping vim.keymap.set('i', '', function() local col = vim.fn.col('.') local line = vim.fn.line('.') if col > vim.fn.indent(line) + 1 then -- not at very beginning (after indent), move left vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes('', true, false, true), 'n', true) else if line > 1 then vim.cmd('normal! k$') vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes('', true, false, true), 'n', true) end end end, { noremap = true, silent = true }) end