michal-h21 / vim-zettel

VimWiki addon for managing notes according to Zettelkasten method
MIT License
564 stars 73 forks source link

Should this work in Neovim? I cannot make it create notes anywhere but current directory #132

Open cpkio opened 2 years ago

cpkio commented 2 years ago

init.lua

local zk = {}
zk.path = vim.fn.expand("~/zettel")
zk.auto_tags = 1
local wiki = {}
wiki.path = vim.fn.expand("~/vimwiki")
wiki.auto_tags = 1
wiki.auto_diary_index = 1
g.vimwiki_list = { zk, wiki }

vim.cmd [[
so c:/nvimdata/nvim/zettel.vim
]]

zettel.vim

let g:zettel_options = [ { "front_matter": [["tags", ""], ["type","note"]] }, {} ]
let g:zettel_format = "%Y%m%d-%H%M%S"
let g:zettel_fzf_command = "rg"
michal-h21 commented 2 years ago

It can create notes only in the root directory of the current wiki, but multiple wikis should work.

cpkio commented 2 years ago

If I configured it right (my config above), it should create new notes in root of ~/zettel, but it always creates notes in current directory anyway. I'm on Windows if this matters.

michal-h21 commented 2 years ago

Ah, that's weird. And normal Vimwiki commands create notes correctly? Try to visually select some words and press enter. This should create a normal Vimwiki note named after the selected text in the current wiki dir. If even this doesn't work, then it may be a possible issue with your configuration. I don't know much about configuring Neovim using Lua, so I cannot tell what can be the problem.

cpkio commented 2 years ago

And normal Vimwiki commands create notes correctly?

Yes, Vimwiki in Neovim works fine, been using it for a year already. It creates notes on enter, saves them in correct places etc.

juanlufont commented 1 year ago

I am having a similar (same?) problem with Vim 9.0 (Debian testing), Vimwiki (dev branch) and vim-zettel.

When I use :ZettelNew or I capture a string, the new note is always created on the current directory, no matter if it is outside my wiki.

I have a single wiki configuration:

let g:vimwiki_ext2syntax = {}
let g:vimwiki_list = [{
            \'path': '~/syncthing/vimwiki/',
            \'syntax': 'markdown',
            \'ext': '.md',
            \'links_space_char': '_',
            \'auto_tags': 1,
            \'auto_toc': 1,
            \'auto_diary_index': 1
            \}]
let g:vimwiki_global_ext = 0
let g:vimwiki_dir_link = 'index'
let g:vimwiki_auto_chdir = 1

let g:zettel_format = "%Y-%m-%dT%H%M%S-%title"
let g:zettel_options = [ { "front_matter": [["tags", ""]] }, {} ]
juanlufont commented 1 year ago

After playing around with the code, notes are created in the vimwiki/zettel path when I comment/uncomment these lines in the function zettel#vimwiki#create(...) in the file autoload/zettel/vimwiki.vim:

  " the following command doesn't work correctly with the vimwiki navigation
  call vimwiki#base#open_link(':e ', format, s:vimwiki_dir.path)  " add third argument
  " call vimwiki#base#open_link(':e ',  "./". format, )  
  " add basic template to the new file

I do not use most of the Vimwiki features, so I do not totally understand the consequences of this change (beyond it kind of fix this issue)

michal-h21 commented 1 year ago

@juanlufont thanks for the pointer. You are right, it is necessary to pass the full path to vimwiki#base#open_link, otherwise capturing from outside of the wiki directory will not work. It has a downside in that it will break Vimwiki navigational commands, so when you create a new note using the z key from visual selection, you cannot get back to the previous page using backspace.

My solution is to detect if the current file is in wiki, and select the opening method accordingly. This should support the navigation when you create notes from the wiki.