kiwi.nvim
kiwi.nvim copied to clipboard
Duplication of path on new entry creation (MacOS)
While this plugin looks promising, I cannot get it work as expected with more than one notes location.
My configuration:
return {
'serenevoid/kiwi.nvim',
dependencies = {
"nvim-lua/plenary.nvim"
},
opts = {
{
name = "work",
path = "/Users/avastmick/notes/edu-docs"
},
{
name = "personal",
path = "/Users/avastmick/notes/local-notes"
}
},
keys = {
{ "<leader>kw", ":lua require(\"kiwi\").open_wiki_index(\"work\")<cr>", desc = "Open Wiki index" },
{ "<leader>kp", ":lua require(\"kiwi\").open_wiki_index(\"personal\")<cr>", desc = "Open index of personal wiki" },
{ "T", ":lua require(\"kiwi\").todo.toggle()<cr>", desc = "Toggle Markdown Task" }
},
lazy = true
}
Usage:
I open the personal
and add in a line 'Daily Plan', select words and <CR>, I get the following path (see the status line)
I hit Ctrl+o
to return to index.md
, hovered link does not show duplicated path elements:
If I remove the leading ./
from the new link, <CR> navigates to a new file in the directory I opened nvim
.
Sorry, update, the behaviour is now regardless of the number of wiki locations: I thought it was working for one, but it was actually creating files in the wrong place.
Hi @avastmick! Thanks for reporting this issue. I have two questions though.
- Is the index file created in the correct location for these two wiki locations?
- This path trimming is failing only when the notes are created from the wiki note?
Hi @avastmick! Thanks for reporting this issue. I have two questions though.
- Is the index file created in the correct location for these two wiki locations?
- This path trimming is failing only when the notes are created from the wiki note?
Firstly, yes, an index.md
is created.
Secondly, yes, when I create a new note the path is duplicated as per the screenshot in the OP.
I spent a bit of time trying to reproduce and when I create two empty wiki, the path handling is consistent with your GH README. In fact, I thought that the issue was resolved and all good. However, when I return to either wiki with an index.md
created (say in a new nvim
session), any new pages show the path duplication issue.
The path issue only occurs on an existing wiki. The behaviour is consistent. Have an index.md
, create a new page, and the page is created in a nonexistent path that is duplicated.
Could this be a plugin clash? My list of plugins are as follows:
.
├── alpha-nvim.lua
├── cmp.lua
├── db-ui.lua
├── harpoon.lua
├── init.lua
├── kiwi.lua
├── leap.lua
├── lsp.lua
├── lualine.lua
├── neogit.lua
├── no-neck-pain.lua
├── noice.lua
├── oil.lua
├── rustaceanvim.lua
├── surround.lua
├── telescope.lua
├── themes.lua
├── todo-comments.lua
├── treesitter.lua
├── undotree.lua
└── which-key.lua
Thanks for the work on this and getting back so promptly on the issue I raised. The issue may be found between the computer and the chair 😀
Thank you for the details! I could reproduce the issue. Will update the plugin soon! And to answer your questions,
- No, its not caused by your plugins clashing since I could reproduce it
- Yes, the plugin is currently meant for flat directory structure since that is easier for fast wiki note creation. But you could create a custom wiki link by typing the proper path relative to the wiki directory and use it as normal. You can't create notes in custom subdirectories. That's all
Thanks for resolving. Great stuff!
@avastmick
It seems the variable "relative_path" includes "config.path", which is the absolute path to each wiki, such as "path like path = '/Users/testuser/personal-wiki'" on Mac. Therefore, "relative_path" works as an absolute path.
To bypass this issue for now, I overwrote the method "utils.get_relative_path" as shown below in "init.vim". (Of course, you can simplify it further by returning empty strings without an if clause.)
lua << EOF
-- https://github.com/serenevoid/kiwi.nvim/issues/21
local utils = require'kiwi.utils'
local is_windows = vim.loop.os_uname().version:match('Windows')
utils.get_relative_path = function (config)
local relative_path = vim.fs.dirname(vim.fn.expand('%:p'))
if is_windows then
-- For Windows, replace backslashes with forward slashes in the config path
return relative_path:gsub(config.path:gsub("\\", "/"), "")
else
-- For macOS, return the relative path directly
return ""
end
end
EOF
@avastmick @tarurata I have added a new commit for fixing this issue. Please have a look when you find time. Hope to hear from you soon.
The latest change broke my setup using Obsidian and iCloud. I think this line in ensure_directories
:
props.path = props.path:gsub("$HOME", get_home()):gsub("~", get_home())
conflicts with my config:
local wikiPath = '/Users/mwarner/Library/Mobile Documents/iCloud~md~obsidian/Documents/my_notes'
require('kiwi').setup({
{
name = 'personal',
path = wikiPath,
},
})
@mlwarner Thanks for your response. I have rolled back the plugin. Please try updating the plugin again. If update fails, try reinstalling the plugin.
Thanks! I unpinned the commit and it is working as expected.
I think you are looking for path expansion here rather than a substitution. Quick scan through vim help docs has vim.fn.expand
. Testing with :lua =vim.fn.expand("/Users/mwarner/Library/Mobile Documents/iCloud~md~obsidian/Documents/my_notes")
yields the same path, and :lua =vim.fn.expand("~/wiki")
also works as expected.
I do not know if this is the right place for this issue, as I am not on MacOS. However, I seem to have the same issue: If I create links to new notes inside my index.md, I can not save the new notes because the path to my wiki is dublicated.