feat: add obsidian and added some config

This commit is contained in:
jujekebab 2026-01-21 07:48:29 +09:00
parent 912622fbe4
commit b7899a5892
3 changed files with 138 additions and 3 deletions

View File

@ -344,6 +344,7 @@ require('lazy').setup({
-- Document existing key chains -- Document existing key chains
spec = { spec = {
{ '<leader>o', group = '[O]bsidian' },
{ '<leader>s', group = '[S]earch' }, { '<leader>s', group = '[S]earch' },
{ '<leader>t', group = '[T]oggle' }, { '<leader>t', group = '[T]oggle' },
{ '<leader>h', group = 'Git [H]unk', mode = { 'n', 'v' } }, { '<leader>h', group = 'Git [H]unk', mode = { 'n', 'v' } },
@ -984,7 +985,7 @@ require('lazy').setup({
-- This is the easiest way to modularize your config. -- This is the easiest way to modularize your config.
-- --
-- Uncomment the following line and add your plugins to `lua/custom/plugins/*.lua` to get going. -- Uncomment the following line and add your plugins to `lua/custom/plugins/*.lua` to get going.
-- { import = 'custom.plugins' }, { import = 'custom.plugins' },
-- --
-- For additional information with loading, sourcing and examples see `:help lazy.nvim-🔌-plugin-spec` -- For additional information with loading, sourcing and examples see `:help lazy.nvim-🔌-plugin-spec`
-- Or use telescope! -- Or use telescope!

View File

@ -5,14 +5,15 @@
"fidget.nvim": { "branch": "main", "commit": "e32b672d8fd343f9d6a76944fedb8c61d7d8111a" }, "fidget.nvim": { "branch": "main", "commit": "e32b672d8fd343f9d6a76944fedb8c61d7d8111a" },
"gitsigns.nvim": { "branch": "main", "commit": "5813e4878748805f1518cee7abb50fd7205a3a48" }, "gitsigns.nvim": { "branch": "main", "commit": "5813e4878748805f1518cee7abb50fd7205a3a48" },
"guess-indent.nvim": { "branch": "main", "commit": "84a4987ff36798c2fc1169cbaff67960aed9776f" }, "guess-indent.nvim": { "branch": "main", "commit": "84a4987ff36798c2fc1169cbaff67960aed9776f" },
"lazy.nvim": { "branch": "main", "commit": "306a05526ada86a7b30af95c5cc81ffba93fef97" }, "lazy.nvim": { "branch": "main", "commit": "85c7ff3711b730b4030d03144f6db6375044ae82" },
"lazydev.nvim": { "branch": "main", "commit": "5231c62aa83c2f8dc8e7ba957aa77098cda1257d" }, "lazydev.nvim": { "branch": "main", "commit": "5231c62aa83c2f8dc8e7ba957aa77098cda1257d" },
"mason-lspconfig.nvim": { "branch": "main", "commit": "3b3571b4dadbcb464804466e9872e7246c316af7" }, "mason-lspconfig.nvim": { "branch": "main", "commit": "3b3571b4dadbcb464804466e9872e7246c316af7" },
"mason-tool-installer.nvim": { "branch": "main", "commit": "517ef5994ef9d6b738322664d5fdd948f0fdeb46" }, "mason-tool-installer.nvim": { "branch": "main", "commit": "517ef5994ef9d6b738322664d5fdd948f0fdeb46" },
"mason.nvim": { "branch": "main", "commit": "57e5a8addb8c71fb063ee4acda466c7cf6ad2800" }, "mason.nvim": { "branch": "main", "commit": "57e5a8addb8c71fb063ee4acda466c7cf6ad2800" },
"mini.nvim": { "branch": "main", "commit": "a995fe9cd4193fb492b5df69175a351a74b3d36b" }, "mini.nvim": { "branch": "main", "commit": "a995fe9cd4193fb492b5df69175a351a74b3d36b" },
"nvim-lspconfig": { "branch": "master", "commit": "c4f67bf85b01a57e3c130352c0a0e453ab8cd5b9" }, "nvim-lspconfig": { "branch": "master", "commit": "c4f67bf85b01a57e3c130352c0a0e453ab8cd5b9" },
"nvim-treesitter": { "branch": "master", "commit": "42fc28ba918343ebfd5565147a42a26580579482" }, "nvim-treesitter": { "branch": "main", "commit": "42fc28ba918343ebfd5565147a42a26580579482" },
"obsidian.nvim": { "branch": "main", "commit": "f6b241fa08d157701b9b0850b1251d98f86b122e" },
"plenary.nvim": { "branch": "master", "commit": "b9fd5226c2f76c951fc8ed5923d85e4de065e509" }, "plenary.nvim": { "branch": "master", "commit": "b9fd5226c2f76c951fc8ed5923d85e4de065e509" },
"telescope-fzf-native.nvim": { "branch": "main", "commit": "6fea601bd2b694c6f2ae08a6c6fab14930c60e2c" }, "telescope-fzf-native.nvim": { "branch": "main", "commit": "6fea601bd2b694c6f2ae08a6c6fab14930c60e2c" },
"telescope-ui-select.nvim": { "branch": "master", "commit": "6e51d7da30bd139a6950adf2a47fda6df9fa06d2" }, "telescope-ui-select.nvim": { "branch": "master", "commit": "6e51d7da30bd139a6950adf2a47fda6df9fa06d2" },

View File

@ -0,0 +1,133 @@
return {
"obsidian-nvim/obsidian.nvim",
version = "*", -- use latest release, remove to use latest commit
ft = "markdown",
dependencies = {
"nvim-lua/plenary.nvim",
"nvim-telescope/telescope.nvim",
},
---@module 'obsidian'
---@type obsidian.config
opts = {
legacy_commands = false, -- this will be removed in the next major release
workspaces = {
{
name = "main",
path = "~/Documents/obsidian_git/Obsidian_vault/",
},
},
daily_notes = {
folder = "Journals",
date_format = "%Y%m%d",
},
},
config = function(_, opts)
require("obsidian").setup(opts)
local vault_path = vim.fn.expand("~/Documents/obsidian_git/Obsidian_vault/")
-- Custom function to search by alias
local function search_by_alias()
local pickers = require("telescope.pickers")
local finders = require("telescope.finders")
local conf = require("telescope.config").values
local actions = require("telescope.actions")
local action_state = require("telescope.actions.state")
-- Collect all files with their aliases
local entries = {}
local scandir = require("plenary.scandir")
local files = scandir.scan_dir(vault_path, { hidden = false, depth = 10, add_dirs = false })
for _, file in ipairs(files) do
if file:match("%.md$") then
local f = io.open(file, "r")
if f then
local content = f:read("*a")
f:close()
-- Parse YAML frontmatter
local frontmatter = content:match("^%-%-%-\n(.-)\n%-%-%-")
if frontmatter then
-- Extract aliases (supports both list and inline formats)
local aliases = {}
-- Match "aliases: [alias1, alias2]" format
local inline_aliases = frontmatter:match("aliases:%s*%[(.-)%]")
if inline_aliases then
for alias in inline_aliases:gmatch("[^,]+") do
alias = alias:match("^%s*(.-)%s*$") -- trim
alias = alias:gsub('^"(.-)"$', "%1"):gsub("^'(.-)'$", "%1") -- remove quotes
if alias ~= "" then
table.insert(aliases, alias)
end
end
end
-- Match YAML list format:
-- aliases:
-- - alias1
-- - alias2
local list_section = frontmatter:match("aliases:%s*\n(.-)\n%w")
or frontmatter:match("aliases:%s*\n(.-)$")
if list_section then
for alias in list_section:gmatch("%s*%-%s*([^\n]+)") do
alias = alias:match("^%s*(.-)%s*$")
alias = alias:gsub('^"(.-)"$', "%1"):gsub("^'(.-)'$", "%1")
if alias ~= "" then
table.insert(aliases, alias)
end
end
end
-- Add entries for each alias
local rel_path = file:gsub(vault_path, "")
local filename = vim.fn.fnamemodify(file, ":t:r")
for _, alias in ipairs(aliases) do
table.insert(entries, {
alias = alias,
filename = filename,
path = file,
display = alias .. " -> " .. rel_path,
})
end
end
end
end
end
pickers
.new({}, {
prompt_title = "Search Obsidian Aliases",
finder = finders.new_table({
results = entries,
entry_maker = function(entry)
return {
value = entry,
display = entry.display,
ordinal = entry.alias .. " " .. entry.filename,
path = entry.path,
}
end,
}),
sorter = conf.generic_sorter({}),
previewer = conf.file_previewer({}),
attach_mappings = function(prompt_bufnr, map)
actions.select_default:replace(function()
actions.close(prompt_bufnr)
local selection = action_state.get_selected_entry()
if selection then
vim.cmd("edit " .. vim.fn.fnameescape(selection.path))
end
end)
return true
end,
})
:find()
end
-- Set up keymaps
vim.keymap.set("n", "<leader>oa", search_by_alias, { desc = "[O]bsidian search by [A]lias" })
vim.keymap.set("n", "<leader>od", "<cmd>Obsidian today<cr>", { desc = "[O]bsidian [D]aily note (today)" })
end,
}