From a28b24c94312b3219f8b2b53e112304889c8e610 Mon Sep 17 00:00:00 2001 From: pro100ton Date: Mon, 3 Feb 2025 20:55:31 +0300 Subject: [PATCH] Add obsidian plugin --- lua/custom/obsidian.lua | 64 +++++++++++++++++++++++++++++++++ lua/custom/oil.lua | 51 +++++++++++++------------- lua/custom/plugins/obsidian.lua | 12 +++++++ 3 files changed, 101 insertions(+), 26 deletions(-) create mode 100644 lua/custom/obsidian.lua create mode 100644 lua/custom/plugins/obsidian.lua diff --git a/lua/custom/obsidian.lua b/lua/custom/obsidian.lua new file mode 100644 index 0000000..fa1f09f --- /dev/null +++ b/lua/custom/obsidian.lua @@ -0,0 +1,64 @@ +require("obsidian").setup { + -- Set workspace setting + workspaces = { + { + name = "personal", + path = "~/Documents/t0xa_vault", + } + }, + -- Disable conceal level to supress varning log message + ui = { + enable = false + }, + -- Set notes subdir to store new notes + notes_subdir = "Unsorted", + new_notes_location = "notes_subdir", + -- Set template params + templates = { + folder = "Templates", + date_format = "%Y-%m-%d", + time_format = "%H:%M", + substitutions = { + yesterday = function() + return os.date("%Y-%m-%d", os.time() - 86400) + end + } + }, + -- Set behaviour of following links + follow_url_func = function(url) + -- vim.fn.jobstart({ "open", url }) -- Mac OS + vim.fn.jobstart({ "xdg-open", url }) -- linux + -- vim.cmd(':silent exec "!start ' .. url .. '"') -- Windows + -- vim.ui.open(url) -- need Neovim 0.10.0+ + end, + -- Set behaviour for opening images + follow_img_func = function(img) + -- vim.fn.jobstart { "qlmanage", "-p", img } -- Mac OS quick look preview + vim.fn.jobstart({ "xdg-open", url }) -- linux + -- vim.cmd(':silent exec "!start ' .. url .. '"') -- Windows + end, + -- Set sorting for creation date + sort_by = "created", + -- Set attachements new folder + attachments = { + img_folder = "Media" + } +} + + +-- Obsidian-related keybinds +vim.keymap.set("n", "oit", "ObsidianTemplate", + { silent = true, noremap = true, desc = "Obsidian: insert template" }) +vim.keymap.set("n", "oo", "ObsidianQuickSwitch", + { silent = true, noremap = true, desc = "Obsidian: open file" }) +vim.keymap.set("n", "opi", "ObsidianPasteImg", + { silent = true, noremap = true, desc = "Obsidian: paste image" }) +vim.keymap.set("n", "or", "ObsidianRename", + { silent = true, noremap = true, desc = "Obsidian: rename file" }) +vim.keymap.set("n", "ol", "ObsidianToggleCheckbox", + { silent = true, noremap = true, desc = "Obsidian: toggle checkbox" }) +vim.keymap.set("n", "on", "ObsidianNew", { silent = true, noremap = true, desc = "Obsidian: new file" }) +vim.keymap.set("n", "otoc", "ObsidianTOC", + { silent = true, noremap = true, desc = "Obsidian: open TOC" }) +vim.keymap.set("n", "ofl", "ObsidianFollowLink", + { silent = true, noremap = true, desc = "Obsidian: follow link" }) diff --git a/lua/custom/oil.lua b/lua/custom/oil.lua index 0b43a33..865c855 100644 --- a/lua/custom/oil.lua +++ b/lua/custom/oil.lua @@ -1,27 +1,26 @@ -require("oil").setup{ - opts = { - keymaps = { - ["g?"] = "actions.show_help", - [""] = "actions.select", - [""] = { "actions.select", opts = { vertical = true }, desc = "Open the entry in a vertical split" }, - [""] = false, - [""] = { "actions.select", opts = { tab = true }, desc = "Open the entry in new tab" }, - [""] = "actions.preview", - [""] = "actions.close", - [""] = false, - ["-"] = "actions.parent", - ["_"] = "actions.open_cwd", - ["`"] = "actions.cd", - ["~"] = { "actions.cd", opts = { scope = "tab" }, desc = ":tcd to the current oil directory", mode = "n" }, - ["gs"] = "actions.change_sort", - ["gx"] = "actions.open_external", - ["g."] = "actions.toggle_hidden", - ["g\\"] = "actions.toggle_trash", - }, - view_options = { - show_hidden = true, - }, - }, - -- Open parent directory in current window - vim.keymap.set("n", "-", "Oil", { desc = "Open parent directory" }), +require("oil").setup { + keymaps = { + ["g?"] = "actions.show_help", + [""] = "actions.select", + [""] = { "actions.select", opts = { vertical = true }, desc = "Open the entry in a vertical split" }, + [""] = false, + [""] = { "actions.select", opts = { tab = true }, desc = "Open the entry in new tab" }, + [""] = "actions.preview", + [""] = "actions.close", + [""] = false, + ["-"] = "actions.parent", + ["_"] = "actions.open_cwd", + ["`"] = "actions.cd", + ["~"] = { "actions.cd", opts = { scope = "tab" }, desc = ":tcd to the current oil directory", mode = "n" }, + ["gs"] = "actions.change_sort", + ["gx"] = "actions.open_external", + ["g."] = "actions.toggle_hidden", + ["g\\"] = "actions.toggle_trash", + }, + view_options = { + show_hidden = true, + }, + -- Open parent directory in current window } + +vim.keymap.set("n", "-", "Oil", { desc = "Open parent directory" }) diff --git a/lua/custom/plugins/obsidian.lua b/lua/custom/plugins/obsidian.lua new file mode 100644 index 0000000..849fa2a --- /dev/null +++ b/lua/custom/plugins/obsidian.lua @@ -0,0 +1,12 @@ +return { + "epwalsh/obsidian.nvim", + version = "*", + lazy = true, + ft = "markdown", + dependencies = { + "nvim-lua/plenary.nvim", + }, + config = function() + require "custom.obsidian" + end +}