Closed LibrEars closed 2 years ago
Hi again,
I found a first workaround. By adding
noremap <Leader>v :Lines<CR>title:<Space>
to my vimrc. Like this the command 'Lines' from fzf is used to search for 'title:'. This will show a list of all open Zettels that include a 'title:' in the YAML-header. Then by typing the desired title and hitting enter you can directly jump to that Zettel.
Nonetheless it is still a workaround since you can not see the status of the buffer. This would help for example to see if you need to save a Zettel before closing it:
:ls[!] [flags] Show all buffers. Example:
1 #h "/test/text" line 1 2u "asdf" line 0 3 %a + "version.c" line 1
[...]
Indicators (chars in the same column are mutually exclusive): u an unlisted buffer (only displayed when [!] is used) unlisted-buffer % the buffer in the current window # the alternate buffer for ":e #" and CTRL-^ a an active buffer: it is loaded and visible h a hidden buffer: It is loaded, but currently not displayed in a window hidden-buffer - a buffer with 'modifiable' off = a readonly buffer R a terminal buffer with a running job F a terminal buffer with a finished job ? a terminal buffer without a job: :terminal NONE + a modified buffer x a buffer with read errors
Here is a function that uses a modified example of buffer selection function from FZF. It loops over lines returned from :ls
, extracts filenames, and retrieves titles using the zettel#vimwiki#get_title
function.
function! s:buflist()
" redirect :ls to a variable
redir => ls
silent ls
redir END
let lines = split(ls, '\n')
let newlines = []
" run over buffers
for line in lines
let filename = matchstr(line, '\v"\zs([^"]+)')
" we need to expand the matched filename to a full path
let filename = fnamemodify(filename, ":p")
" use vim-zettel command to read title
let title = zettel#vimwiki#get_title(filename)
" add title to the result of :ls
call add(newlines, line . " - " . title)
endfor
return newlines
endfunction
function! s:bufopen(e)
execute 'buffer' matchstr(a:e, '^[ 0-9]*')
endfunction
nnoremap <silent> § :call fzf#run({
\ 'source': reverse(<sid>buflist()),
\ 'sink': function('<sid>bufopen'),
\ 'options': '+m',
\ 'down': len(<sid>buflist()) + 2
\ })<CR>
The result looks like this:
1 %a "markdown/pokus.md" line 16 - First file
2 # "~/scratchbox/vimwiki/markdown/200908-1431.md" line 1 - Title one
> 3 "~/scratchbox/vimwiki/markdown/200226-1314.md" line 13 - Title two
This is exactly what I had dreamed of! Thank you very much! Should be added to vim-zettel default functions =)
I've added a :ZettelSelectBuffer
command, it should do this trick. It even hides the filenames, unless the file is missing a title.
Nice! For some it might be convenient to still see the filenames in parallel. I close the Issue. Thank you again :)
@LibrEars I've added a new formatting variable, g:zettel_bufflist_format
for that. You can set it to "%filename - %title"
to see both title and filename.
Hi,
i am exploring vim-zettle an I really like it. As suggested by rhelmstedter I would like to save my zettle in the format
g:zettel_format = "%Y%m%d%H%M"
Here is the question: There exists a real handy way of navigating buffers: flying buffers
By setting
nnoremap <Leader>b :ls<CR>:b<Space>
in your vimrc you can display a list of the open zettlels and move between them quickly by their number N or name. But since the name is only a date with the format"%Y%m%d%H%M"
this feature becomes unusable :(Does someone knows how to have the same "zettel flying" in vim-zettle? Or does someone knows how to modify
ls
to insert the%title
after the buffer name into the list of open buffers?Thx LibrEars