kis9a / vimsidian

Vim plugin for PKM like obsidian.md
Do What The F*ck You Want To Public License
55 stars 0 forks source link

Adding a Preview Pane - Inspired by Strange New Worlds #13

Open dlitvakb opened 3 months ago

dlitvakb commented 3 months ago

Thank you so much for developing this!

Given I cannot install Obsidian in my work machine, Vimsidian has been the savior to my note taking ability.

I've been adding a few customizations on top, that I believe are very useful for all users. Here's one to add quick previews as a popup.

image


function! PreviewInFloat()
  let lines = 30
  let width = 90

  let link_at_cursor = vimsidian#unit#CursorLink()

  if link_at_cursor ==# v:null
    echo 'Link is empty'
    return v:null
  endif

  if empty(link_at_cursor)
    echo 'Link is empty'
    return v:null
  endif

  let title = link_at_cursor

  let note = vimsidian#unit#FdNote(title . '.md')

  if note ==# v:null
    echo 'Note not found'
    return v:null
  endif

  let matches = split(note, '\n')
  if len(matches) > 0
    let note = matches[0]
  endif

  if empty(note)
    echo 'Note not found'
    return v:null
  endif

  let note_contents = readfile(note)

  let popup_options = {
        \ 'firstline': 1,
        \ 'line': 'cursor',
        \ 'col': 'cursor',
        \ 'pos': 'botleft',
        \ 'moved': 'WORD',
        \ 'minwidth': width,
        \ 'maxwidth': width,
        \ 'minheight': 5,
        \ 'maxheight': lines,
        \ 'padding': [0, 1, 0, 1],
        \ 'border': [],
        \ 'title': title}
  let s:id = popup_atcursor(note_contents, popup_options)
  call setbufvar(winbufnr(s:id), '&filetype', 'markdown')
endfunction

Feel free to adapt it.

Once again, thank you very much for building this project!

Cheers

kis9a commented 3 months ago

@dlitvakb

Thank you for your great suggestion! I will check it over the weekend and plan for implementation.

kis9a commented 3 months ago

I would like to implement this as one of the core features of vimsidian. I am still thinking about the details.

dlitvakb commented 3 months ago

Sounds great! Let me know if you need any further input from me