Created
February 27, 2025 17:21
-
-
Save dlitvakb/26bbb9101ba26a34edd0e72af2e09488 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let $VIMSIDIAN_PATH_PATTERN = g:vimsidian_path . '/*.md' | |
| 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 | |
| augroup vimsidian_augroup | |
| au! | |
| au BufNewFile,BufReadPost $VIMSIDIAN_PATH_PATTERN nn <silent> <Leader>? :call PreviewInFloat()<CR> | |
| augroup END |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment