Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
cpkio opened this issue Oct 3, 2022 · 7 comments

Comments

@cpkio
Copy link

cpkio commented Oct 3, 2022

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
Copy link
Owner

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

@cpkio
Copy link
Author

cpkio commented Oct 4, 2022

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
Copy link
Owner

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
Copy link
Author

cpkio commented Oct 4, 2022

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
Copy link

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
Copy link

juanlufont commented Dec 14, 2022

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
Copy link
Owner

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants