Open pinpox opened 3 years ago
Looking at the source code, I see that the --preview
parameter is actually being set. Why is it not showing up though, do I need any configuration to enable it? I see there are a few options set here but the example in the README has no mention of them.
I'm seeing the same thing. Any chance you've figured this out?
I've tested bat works
I've tested fzf with the --preview command shown in the options above which works
I've tested :echom executable("cat")
which returns 1 in nvmim
I did modify the standard config for zk b/c it wasn't getting the path.
require("zk").setup({
debug = true,
log = true,
default_keymaps = true,
-- default_notebook_path = vim.env.ZK_NOTEBOOK_DIR or "",
default_notebook_path = vim.loop.cwd(),
fuzzy_finder = "fzf", -- or "telescope"
link_format = "wiki" -- "markdown" or "wiki"
})
But I still don't get previews from :ZkSearch
I've stripped everything down to the base that I can. I'm running with the following config.
call plug#begin()
" zk
Plug 'vijaymarupudi/nvim-fzf'
Plug 'neovim/nvim-lspconfig'
Plug 'megalithic/zk.nvim'
" fzf
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
Plug 'junegunn/fzf.vim'
call plug#end()
" Done with plugins
" zk
command! -nargs=0 ZkIndex :lua require'lspconfig'.zk.index()
command! -nargs=? ZkNew :lua require'lspconfig'.zk.new(<args>)
lua << EOF
require("zk").setup({
debug = true,
log = true,
default_keymaps = true,
-- default_notebook_path = vim.env.ZK_NOTEBOOK_DIR or "",
default_notebook_path = vim.loop.cwd(),
fuzzy_finder = "fzf", -- or "telescope"
link_format = "wiki" -- "markdown" or "wiki"
})
local lspconfig = require'lspconfig'
local configs = require'lspconfig/configs'
configs.zk = {
default_config = {
cmd = {'zk', 'lsp'};
filetypes = {'markdown'};
root_dir = lspconfig.util.root_pattern('.zk');
settings = {};
};
}
configs.zk.index = function()
vim.lsp.buf.execute_command({
command = "zk.index",
arguments = {vim.api.nvim_buf_get_name(0)},
})
end
configs.zk.new = function(...)
vim.lsp.buf_request(0, 'workspace/executeCommand',
{
command = "zk.new",
arguments = {
vim.api.nvim_buf_get_name(0),
...
},
},
function(_, _, result)
if not (result and result.path) then return end
vim.cmd("edit " .. result.path)
end
)
end
lspconfig.zk.setup({
on_attach = function(client, bufnr)
-- Key mappings
local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end
local opts = { noremap=true, silent=true }
buf_set_keymap("n", "<CR>", "<cmd>lua vim.lsp.buf.definition()<CR>", opts)
buf_set_keymap("n", "K", "<cmd>lua vim.lsp.buf.hover()<CR>", opts)
buf_set_keymap("n", "<leader>zi", ":ZkIndex<CR>", opts)
buf_set_keymap("v", "<leader>zn", ":'<,'>lua vim.lsp.buf.range_code_action()<CR>", opts)
buf_set_keymap("n", "<leader>zn", ":ZkNew {title = vim.fn.input('Title: ')}<CR>", opts)
buf_set_keymap("n", "<leader>zl", ":ZkNew {dir = 'log'}<CR>", opts)
end
})
EOF
Vim:
vim --version
NVIM v0.5.0
Build type: RelWithDebInfo
LuaJIT 2.1.0-beta3
Compilation: /usr/bin/gcc-11 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -DNVIM_TS_HAS_SET_MATCH_LIMIT -O2 -g -Og -g -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wmissing-prototypes -Wimplicit-fallthrough -Wvla -fstack-protector-strong -fno-common -fdiagnostics-color=always -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -DMIN_LOG_LEVEL=3 -I/home/runner/work/neovim/neovim/build/config -I/home/runner/work/neovim/neovim/src -I/home/runner/work/neovim/neovim/.deps/usr/include -I/usr/include -I/home/runner/work/neovim/neovim/build/src/nvim/auto -I/home/runner/work/neovim/neovim/build/include
Compiled by runner@fv-az242-526
Features: +acl +iconv +tui
See ":help feature-compile"
Other:
$ fzf --version
0.20.0
$bat --version
bat 0.12.1
That's all I can think to provide, if anyone see's anything I've got wrong.
@pinpox I've got a PR #38 up which makes this work for me.
However, in the process I saw how it was being displayed and tested something out.
$ time zk list -m Theil --format=path > /dev/null
Found 14 notes
real 0m0.051s
user 0m0.046s
sys 0m0.015s
$ time ag Theil > /dev/null
real 0m0.013s
user 0m0.009s
sys 0m0.012s
$ time rg Theil > /dev/null
real 0m0.012s
user 0m0.019s
sys 0m0.003s
zk does a full text search, throws away the results and returns just the file, which zk.vim then configures fzf to display with bat. So you need bat installed. If you instead install Silver Searcher (Ag) or Ripgrep (Rg) FZF.vim already includes full text search with those programs. They're blazing fast and Rg by default highlights the search term.
Now that I've fixed it, I'm not actually sure what the use case is for ZkSearch.
@chris-sanders So basically replace zk.nvim with custom ripgrep bindings? I already have ripgrep installed
Until/unless ZkSearch gains additional features, yes just use ripgrep and fzf already has an :Rg
command built it that will do what ZkSearch currently does.
zk --match
is not particularly useful when doing a basic full text search, compared to dedicated tools. It becomes more interesting when combining terms or lemmatisation (matching both cooked
and cooking
).
Personally I don't even use zk.nvim
. I find that the LSP server is enough for my usage, with a few bindings to create notes as described here. For searching my notes from Neovim I use the fzf.nvim
plugin directly.
@mickael-menu thanks for the clarification. Is your full configuration available somewhere? I'm having some issues and just want to start from a clean ZK LSP that is known working.
Is your full configuration available somewhere?
Would be interested in this as well if you are willing to share some insights
Sure, I don't have anything really special but here you go:
call plug#begin('~/.vim/plugged')
" Neovim 0.5 LSP
Plug 'neovim/nvim-lspconfig'
Plug 'hrsh7th/nvim-compe'
" Markdown
Plug 'plasticboy/vim-markdown'
Plug 'dhruvasagar/vim-table-mode'
Plug 'ferrine/md-img-paste.vim'
call plug#end()
" Set <leader> to space
let mapleader=' '
" Open my notebook index
"https://www.reddit.com/r/vim/comments/8xzpkz/you_probably_dont_need_vimwiki/e26yhr6/?utm_source=reddit&utm_medium=web2x&context=3
nnoremap <Leader>zz :e ~/Dropbox/Notes/index.md<CR>
" https://github.com/plasticboy/vim-markdown
let g:vim_markdown_folding_disabled = 1
let g:vim_markdown_no_extensions_in_markdown = 1
let g:language_client_log_level = 'debug'
let g:completion_trigger_character = ['#', '[']
lua << EOF
local lspconfig = require'lspconfig'
local configs = require'lspconfig/configs'
-- Initialize the zk language server
configs.zk = {
default_config = {
cmd = {'zk', 'lsp', '--log', '/tmp/zk-lsp.log'};
filetypes = {'markdown'};
root_dir = lspconfig.util.root_pattern('.zk');
settings = {};
};
}
-- Index the notebook of the current note.
configs.zk.index = function()
vim.lsp.buf.execute_command({
command = "zk.index",
arguments = {vim.api.nvim_buf_get_name(0)},
})
end
-- Create a new note in the current notebook.
configs.zk.new = function(...)
vim.lsp.buf_request(0, 'workspace/executeCommand',
{
command = "zk.new",
arguments = {
vim.api.nvim_buf_get_name(0),
...
},
},
function(_, _, result)
if not (result and result.path) then return end
vim.cmd("edit " .. result.path)
end
)
end
lspconfig.zk.setup({
on_attach = function(client, bufnr)
-- Key mappings
local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end
local opts = { noremap=true, silent=false }
buf_set_keymap("i", "<S-tab>", "<cmd>lua vim.lsp.buf.completion()<CR>", opts)
-- Follow a Markdown link with <CR>.
buf_set_keymap("n", "<CR>", "<cmd>lua vim.lsp.buf.definition()<CR>", opts)
-- Preview a note with K when the cursor is on a link.
buf_set_keymap("n", "K", "<cmd>lua vim.lsp.buf.hover()<CR>", opts)
-- Create a new note using the current visual selection for the note title. This will replace the selection with a link to the note.
buf_set_keymap("v", "<CR>", ":'<,'>lua vim.lsp.buf.range_code_action()<CR>", opts)
-- Reindex the notebook. Usually the language server does this automatically, so it's not often needed.
buf_set_keymap("n", "<leader>zi", ":ZkIndex<CR>", opts)
-- Create a new note after prompting for a title.
buf_set_keymap("n", "<leader>zn", ":ZkNew {title = vim.fn.input('Title: ')}<CR>", opts)
-- Create a new daily note in my `log/` notebook directory.
buf_set_keymap("n", "<leader>zl", ":ZkNew {dir = 'log'}<CR>", opts)
-- Find the backlinks for the note linked under the cursor.
buf_set_keymap('n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>', opts)
end
})
EOF
" Declare some custom Neovim commands as shortcuts to the zk functions.
command! -nargs=0 ZkIndex :lua require'lspconfig'.zk.index()
command! -nargs=? ZkNew :lua require'lspconfig'.zk.new(<args>)
" https://github.com/hrsh7th/nvim-compe
let g:compe = {}
let g:compe.enabled = v:true
let g:compe.autocomplete = v:true
let g:compe.debug = v:false
let g:compe.min_length = 1
let g:compe.preselect = 'enable'
let g:compe.throttle_time = 80
let g:compe.source_timeout = 200
let g:compe.incomplete_delay = 400
let g:compe.max_abbr_width = 100
let g:compe.max_kind_width = 100
let g:compe.max_menu_width = 100
let g:compe.documentation = v:true
let g:compe.filter_text = v:true
let g:compe.source = {}
let g:compe.source.path = v:false
let g:compe.source.buffer = v:false
let g:compe.source.nvim_lsp = v:true
let g:compe.source.nvim_lua = v:false
let g:compe.source.vsnip = v:false
inoremap <silent><expr> <C-Space> compe#complete({'filter_text': true})
inoremap <silent><expr> <CR> compe#confirm('<CR>')
inoremap <silent><expr> <C-e> compe#close('<C-e>')
inoremap <silent><expr> <C-f> compe#scroll({ 'delta': +4 })
inoremap <silent><expr> <C-d> compe#scroll({ 'delta': -4 })
autocmd CursorHold * lua vim.lsp.diagnostic.show_line_diagnostics()
highlight LspDiagnosticsDefaultError ctermfg=red guifg=red
highlight LspDiagnosticsUnderlineError ctermfg=red guifg=red
highlight LspDiagnosticsDefaultHint ctermfg=yellow guifg=yellow
highlight LspDiagnosticsUnderlineHint cterm=none gui=none
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 setupa) Is it possible to show matching titles instead of the filename? b) Is it possible to show the preview window?
Example using
:Zksearch something
:For comparison, this is what
fzf
usually looks like, e.g. when searching/showing vim buffers, there is a preview window to the right: