Git Product home page Git Product logo

Comments (6)

LibrEars avatar LibrEars commented on June 9, 2024 1

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

from vim-zettel.

michal-h21 avatar michal-h21 commented on June 9, 2024 1

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

from vim-zettel.

michal-h21 avatar michal-h21 commented on June 9, 2024

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     

from vim-zettel.

LibrEars avatar LibrEars commented on June 9, 2024

This is exactly what I had dreamed of! Thank you very much! Should be added to vim-zettel default functions =)

from vim-zettel.

michal-h21 avatar michal-h21 commented on June 9, 2024

I've added a :ZettelSelectBuffer command, it should do this trick. It even hides the filenames, unless the file is missing a title.

from vim-zettel.

LibrEars avatar LibrEars commented on June 9, 2024

Nice!
For some it might be convenient to still see the filenames in parallel.
I close the Issue. Thank you again :)

from vim-zettel.

Related Issues (20)

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.