Giter VIP home page Giter VIP logo

zk.nvim's Introduction

zk.nvim (archived/deprecated)

NOTE: This plugin is now archived/deprecated. Please see #41 for more information.

A lightweight neovim, lua-based wrapper around zk.

The primary goals of this plugin are to provide handy maps, commands, and user-interface elements around the fantastic golang zettelkasten project, zk.

For more information with how to fully use zk, please visit zk's docs

LSP support within zk is new and still under development. It works quite well as-is, though. ๐Ÿ˜„

Prerequisites

Install

paq-nvim

paq { "megalithic/zk.nvim" }

packer.nvim

use { "megalithic/zk.nvim" }

vim-plug

Plug "megalithic/zk.nvim"

Configuration

-- with default config options:

require("zk").setup({
  debug = false,
  log = true,
  default_keymaps = true,
  default_notebook_path = vim.env.ZK_NOTEBOOK_DIR or "",
  fuzzy_finder = "fzf", -- or "telescope"
  link_format = "markdown" -- or "wiki"
})

Usage

For all usages of this plugin, the parlance of notebook is common place, and refers to a sub-directory within your root ZK_NOTEBOOK_DIR; or more specifically, a notebook is any directory that contains a .zk directory (think of it like a .git-controlled directory). These notebooks also relate to your groups setup within your config.toml.

Install zk

Install the zk binary (as long as go is installed in your system's PATH).

:ZkInstall

Create a new note

:lua require('zk.command').new({ title = "my note title" })

Default arguments:

{
  title = "",
  notebook = "",
  content = "",
  action = "vnew",
  start_insert_mode = true
}

Search/filtering of notes

zk offers such a wealth of power with searching, filtering and more for your notes, notebooks, etc.

Presently only supports interacting with fzf, via a flexible and fast lua-based API plugin, nvim-fzf. Searching via vim command, :ZkSearch only supports query searches at the moment. Using the lua command, the option to pass tags, notebook, and query are supported.

Future support for telescope.nvim integration, coming soon.

:lua require('zk.command').search({ query = "hiring NOT onboarding" })
" or
:ZkSearch "hiring NOT onboarding"

Default arguments:

{
  query = "",
  notebook = "",
  tags = "",
}

Generate a new note and inline link

Quickly change the word under cursor (or visually selected) to markdown or wiki syntax:

:lua require('zk.command').create_note_link({ title = "my note title", notebook = "wiki", action = "e" })

Default arguments:

{
  title = "",
  notebook = "",
  action = "vnew",
  open_note_on_creation = true
}

Default keymaps:

vim.api.nvim_set_keymap(
  "x",
  "<CR>",
  "<cmd>lua require('zk.command').create_note_link({})<cr>",
  {noremap = true, silent = false}
)
vim.api.nvim_set_keymap(
  "n",
  "<CR>",
  "<cmd>lua require('zk.command').create_note_link({title = vim.fn.expand('<cword>')})<cr>",
  {noremap = true, silent = false}
)

Telescope support

Load the zk extension to enable zk support in telescope.

require('telescope').load_extension('zk')

Register a keymap to open the picker for the zk notes.

nnoremap <leader>n <cmd>lua require('telescope').extensions.zk.zk_notes()<cr>
nnoremap <leader>zg <cmd>lua require('telescope').extensions.zk.zk_grep()<cr>
nnoremap <leader>zb <cmd>lua require('telescope').extensions.zk.zk_backlinks()<cr>

Credit

zk.nvim's People

Contributors

chris-sanders avatar cormacrelf avatar eric-hansen avatar megalithic avatar mickael-menu avatar pstuifzand avatar thecontinium avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

zk.nvim's Issues

Fails to create a new note if the title contains an apostrophe (')

Observed that attempting to create a new note (from a valid notebook-initialized directory) with a title that includes an apostrophe ' fails to create the note.

  • Reproduction step: :ZkNew Here's my title
  • Results in the error: E5107: Error loading lua [string ":lua"]:1: ')' expected near 's'

We should handle properly parsing arguments passed to :ZkNew command.

In-note linking to another note, or to a new note via FZF

One major piece of functionality we'd like, is to be able to easily create a link from existing text in the current selection/buffer to a new note with that selection text as a title, AND to be able to get an existing note/file and/or related note/file to the current one and link it in the current note..

Here's some examples of how to do it in straight up viml, using FZF and some other things:
https://github.com/joakin/.vim/blob/master/autoload/notes.vim

Using pre-built releases with :ZkInstall

:ZkInstall is currently building zk from scratch, which has a few advantages:

  • Able to install the latest HEAD version
  • Simpler to implement in zk.nvim
  • It can build the right architecture needed by the user

But it also poses a few problems:

  • The user must have the Go toolkit installed
  • zk requires specific Go tags to build, which might change from one version to the other (see this PR for an example)
  • The installed zk build will be "unversioned" and might not be 100% stable

An alternative could be to use the GitHub JSON API to fetch the latest pre-built releases from https://api.github.com/repos/mickael-menu/zk/releases/latest

This requires to know the architecture of the computer. If the architecture is not covered, we could always fall back on the go get solution.

Documentation needs work

Whilst walking @evantravers through setup and usage of zk + zk.nvim recently; it came to the surface that we really need better documentation around this plugin and how best to use it with zk. In addition, more of a spotlight needs to be put on the LSP support and how this plugin might support it (or not).

So, @evantravers, you have been deemed worthy to go forth and multiply the knowledge in any way you see fit here in this repo.

ZKNew fails to create a new note

Presently :ZkNew fails to complete successfully due to the fact that zk needs to have its cwd set to a dir with an initialized notebook.

Possible solution is to allow a user to define minimal config to set the zk_default_notebook_path and all commands from that point forward would be run from that path as the cwd, using the .zk dir as a root marker.

See #2

Creating wikilinks are broken

If I try to create a note via code action it completely replaces the text with the link to the page ([[yzcw]] was originally testing) and the text isn't carried over to the page either.

If I use the default keymappings and hit enter over a word (highlighted or not), it gives the full path and is quoted, which then makes the LSP say it can't be found.

This is a [[yzcw]] [['/home/ehansen/Projects/notebook/dvga.md'|for you]]

[['/home/ehansen/Projects/notebook/47id.md'|what]]

The cause for issue 2 above is here: https://github.com/megalithic/zk.nvim/blob/main/lua/zk/util.lua#L85 I'm really not sure why shellescape is being called on a filename. But it would also fair better I think to be relative instead of absolute.

This is how I get it (I always call nvim .):

  local file = vim.fn['expand']('%:p')
  local relative_file = vim.fn['fnamemodify'](file, ':.:gs?//?/?')

It's not clean but it does the job and is moldable to this project.

No preview or title with FZF

I've got fzf setup and it seems to work. The selection based on filenames without preview is not very useful though when using non-title filenames. It would also be great if the preview window to the right would show up, fzf does that normally on my setup

a) Is it possible to show matching titles instead of the filename?
b) Is it possible to show the preview window?

Example using :Zksearch something:
image

For comparison, this is what fzf usually looks like, e.g. when searching/showing vim buffers, there is a preview window to the right:
image

New note links full path on system

When I create a new note with the nice <CR> bindings, it links the full path to the note (including the path to the zk notebook itself) which will break on other systems. How can I avoid that?

Also it seems to put the path in quotes, which the zk LSP then complains about. Is this a bug in the neovim plugin or zk LSP server?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.