nb
nb copied to clipboard
Integrating nb with vim
I only found nb this morning, but I totally fell in love with it. Unfortunately, either 1) the name is really difficult to search (it is), or 2) there isn't a broad community that uses it, because I couldn't find any resources on integrating nb with vim.
In particular, I am currently replacing vimwiki with nb, as nb acts as a more robust vimwiki in a lot of ways. Maybe I should be using nb by itself more, but I created this because often I will be in the middle of working on another project in vim, when I think of something I'd like to add to my nb journal... so here we are. Here are a few keybinds I set up in my .vimrc to emulate vimwiki functionality:
nmap <Leader>ww :!nb browse <CR>
nmap <Leader>wi :!nb browse %:p:h:t/%:t <CR>
nmap <Leader>wt :e `='~/.nb/home/Journal/' . expand(strftime('%Y-%m-%d')) . '.md'` <CR>
nmap <Leader>wm :e `='~/.nb/home/Journal/' . expand(strftime('%Y-%m')) . '.md'` <CR>
nmap <Leader>wh :!nb export %:p:h:t/%:t ~/_site/%:t:r.html <CR>
nmap <Leader>whh :!i3-sensible-terminal -T "nb browser backend" -e "nb browse --gui %:p:h:t/%:t" <CR>
Note that %:p:h:t picks up the parent folder of the file (as I have my nb notes contained within a folder) and %:t picks up the file name.
In particular, <Leader>ww opens up the standard nb browser, and <Leader>wi opens up the nb browser on the current file. <Leader>wt creates a new file in my Journal folder in nb with the current date, and opens it in a new tab for editing in vim. <Leader>wm does the same thing but for my monthly note.
Finally, <Leader>wh runs nb's export function on the current file and exports it into a separate /_site/ folder as .html, so one could plausibly host this folder as a static site. <Leader>whh opens the current file within the browser via nb's browse --gui functionality. It specifically opens a new terminal, then runs the nb browse --gui in there; I did this so I could tell i3 to automatically move this new terminal and not get in my way :P
Some things that would really kick this up a notch:
- Highlighting the nb [[links]] within vim and incorporating the tab style keybinding similar to vimwiki to navigate to and from these files. Currently, the easiest workaround is to use <Leader>wi to open the current file in the browser, navigate the links as you like (and edit as you need within nb)
- More robust file directory checking; this won't work at all if you don't have a similar file structure as me
Honestly though, there's not much more that I personally require; this could be easily expandable to a full vimscript plugin... Let me know if anyone has any thoughts, suggestions or whatever!
@gjgress Very interesting. The browse
feature is new within the past few months and I haven't really posted anywhere about it. nb
is primarily developed in vim. I'll start thinking about this, too.
@gjgress
In particular, I am currently replacing vimwiki with nb, as nb acts as a more robust vimwiki in a lot of ways.
After quite some research and trying several apps, my list has shrunk to two options:
Each one has its possible pro/cons...for task management I'm using Taskwarrior, so 1st option would be kind of add-on, while, otoh, I really like nb
's simplicity, using it as bookmark manager etc., so I'd like to know if you've fully migrated to nb
and/or whether it's easy to switch from one to the other if using Markdown markup in both options?
@gjgress
In particular, I am currently replacing vimwiki with nb, as nb acts as a more robust vimwiki in a lot of ways.
After quite some research and trying several apps, my list has shrunk to two options:
1. [taskwiki](https://github.com/tools-life/taskwiki) by leveraging [vimwiki](https://github.com/vimwiki/vimwiki) and 2. [nb](https://github.com/xwmx/nb)
Each one has its possible pro/cons...for task management I'm using Taskwarrior, so 1st option would be kind of add-on, while, otoh, I really like
nb
's simplicity, using it as bookmark manager etc., so I'd like to know if you've fully migrated tonb
and/or whether it's easy to switch from one to the other if using Markdown markup in both options?
@gour Cool. I am not too familiar with Taskwarrior, I'll check this out.
Unfortunately my answer is to the contrary; I have neglected using nb lately. Even with the shortcuts set up, it is too clunky and fragile for me to use regularly... I find myself using a kanboard more often than not.
I don't know anything about taskwiki/Taskwarrior so I can't speak to their integrability. But I'll look into it and see if I can get them to work together.
@gour and @gjgress Just a fair warning: I ditched TaskWarrior (and before that watson) for one simple reason: no stable IDs. The fact that nb doesn't modify the ID on its own is worth far more (to me) than all the features taskwarrior/watson provide. With those tools you can literally run 'delete [id xy]' multiple times, and it will delete different notes. That's especially dangerous if you delete ranges. Basically you have to read the IDs every time you want to edit anything. That's a huge no-go for me.
I ditched TaskWarrior (and before that watson) for one simple reason: no stable IDs.
Take a look at man taskrc
:
gc=1 Can be used to temporarily suspend garbage collection (gc), so that task IDs
don't change. Note that this should be used in the form of a command line
override (task rc.gc=0 ...), and not permanently used in the .taskrc file, as
this significantly affects performance in the long term.
So, it's possible to have a stable IDs...
@meredrica Do you use nb now? Does it do all the things you'd want out of it? @gour That flag isn't meant to be enabled permanently... I do admit that stable IDs are really nice. I have only done a cursory scan of taskwarrior, but I am concerned that it would be difficult to support a Zettelkasten-type system within it (please correct me if I am wrong).
Initially, I was hoping to find a tool that I could use for both prose and task management. But since my use-case is more organizational than prose, I'm starting to reconsider nb as a whole. At this point, I'm starting to consider orgmode and their variants...
Surprisingly, kanboard has proven the most robust for me so far. I have to admit, having a frontend that I can access and modify from my phone, tablet, etc. is rather convenient, as long as you are willing to run a server.
For prose purposes, its simpler for me to just use Obsidian.md or variants. As nice as it would be to have everything under one umbrella, perhaps this is a situation where separate tools would be more effective.
@xwmx this is brilliant! Although I'll most likely never use the Tasks (but that's still great to have). That you made nb is an amazing job and provides a lot of value. @gjgress yea I use nb now - not for long yet - but it's by far the best CLI tool I've seen so far for taking a note/todo within seconds from any of the million terminals I have open somewhere. The only thing I'm missing right now is time tracking. We're getting super off-topic here. @xwmx do you mind?
That flag isn't meant to be enabled permanently... I do admit that stable IDs are really nice. I have only done a cursory scan of taskwarrior, but I am concerned that it would be difficult to support a Zettelkasten-type system within it (please correct me if I am wrong).
I got the following reply from the (current) main developer of Taskwarrior:
Running task with gc=0 is no big deal, it's mostly a user preference. If people don;t mind having big ID numbers, nothing would break if you were to run task rc.gc=1 next only once a year I guess we could have some feature where gc settings would be `always, daily, weekly, monthly or yearly instead of just current 0/1 values. That would require a state file, which is however coming soon
Much like the original poster, I had been looking rather earnestly for a notes system with some rather specific requirements for almost a year, and somehow I never came across nb
until today (all search engines hate it). Thanks so much for the work on this!
Anyway, a vim plugin is the biggest "missing feature" in my mind. I don't think that much needs to be done: it just has to call nb
and do some simple stuff e.g. ensure that if you create a new note from vim it opens in the current session. Might be a good first full-blown lua plugin, if I ever get around to it (hopefully somebody will beat me to it, because it may be a while).
@meredrica Glad you like it! I appreciate the positive feedback a lot.
@ExpandingMan FWIW, currently I primarily use nb
in terminal splits in vim [screenshot (xwmx/dotvim)]. Notes open in vim within the terminal window. I have ideas coalescing around vim integration and would be interested to see what others come up with.
I'm using nb with vim-zettel. I configure them to share the same directory and file name pattern.
Vim-zettel uses metadata for the title, which can be identified by nb.
---
title: Your title
---
vim-zettel supports link auto-complete and link jump in vim.
They work well together except they use different tag and link content. So nb cannot recognize vim-zettel's tag and the link doesn't work for nb browse
@meredrica Glad you like it! I appreciate the positive feedback a lot.
@ExpandingMan FWIW, currently I primarily use
nb
in terminal splits in vim [screenshot (xwmx/dotvim)]. Notes open in vim within the terminal window. I have ideas coalescing around vim integration and would be interested to see what others come up with.
I like to use nb run vim .
which in vanilla vim opens netrw on the current notebook root. I have netrw configured to split vertically using let g:netrw_preview = 1
. The nice thing about this workflow is I can flip through my notes with a quick p
and netrw shows the note in the right split. Handy for browsing all my notes quickly in the same vim session. See :h netrw-p
for a nice suggestion on preview settings with tree view etc. @siero you might be interested in this.
I prefer this over w3m and wonder if vim shouldn't just be another browser option. That is, I'd rather use nb browse
than nb run vim .
I noticed that nb
still auto syncs if I make any note edits during this vim session, so great!
@xwmx thanks for your link to your dotvim configuration above, just installed it and love it!
@aguevara Glad you like it! I've thought a few times since your message about where netrw
could fit into this and it seems like it could make sense as a configurable option for peek
/ show
. I'll have to experiment more. I also added let g:netrw_preview = 1
to that dotvim config. Thanks for the heads up.
Thanks I will have to look into this. I mostly these days use VSCODE with a vim plugin, a Jupyter Notebook plugin, a Markdown plugin, and bash. I also use pandoc from the shell a lot.
I have a tool I created in Perl called mark and setd (set directory) which is like a CLI cache of recently visited directories with a Hansel and Gretel type aliasing of names for directories. I could not live without that. I am noticing that nb can also help with encryption of files, I wish to see something that makes compromises between encrypted github files for backups of secure data, and compression. Also it appears that nb can work with vscode. I think it is time for an old dog to learn new tricks and see if they are better. Thanks for the feedback.
--Marcelo
On Thu, Jun 16, 2022 at 6:21 PM Alex Guevara @.***> wrote:
@meredrica https://github.com/meredrica Glad you like it! I appreciate the positive feedback a lot.
@ExpandingMan https://github.com/ExpandingMan FWIW, currently I primarily use nb in terminal splits in vim [screenshot (xwmx/dotvim) https://github.com/xwmx/dotvim#dotvim]. Notes open in vim within the terminal window. I have ideas coalescing around vim integration and would be interested to see what others come up with.
I like to use nb run vim . which in vanilla vim opens netrw on the current notebook root. I have netrw configured to split vertically using let g:netrw_preview = 1. The nice thing about this workflow is I can flip through my notes with a quick p and netrw shows the note in the right split. Handy for browsing all my notes quickly in the same vim session. See :h netrw-p for a nice suggestion on settings to get a tree view etc. @siero https://github.com/siero you might be interested in this.
I prefer this over w3m and wonder if vim shouldn't just be another browser option. That is, I'd rather use nb browse than nb run vim . I noticed that nb still auto syncs if I make any note edits during this vim session, so great!
@xwmx https://github.com/xwmx thanks for your link to your dotvim configuration above, just installed it and love it!
— Reply to this email directly, view it on GitHub https://github.com/xwmx/nb/issues/115#issuecomment-1158360813, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAEQSDJ3AV3SUXASPHBMZCLVPPHJPANCNFSM45VQZEVQ . You are receiving this because you were mentioned.Message ID: @.***>