Skip to content

Instantly share code, notes, and snippets.

@Konfekt
Last active March 20, 2024 16:10
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Konfekt/c2066abc31b41430417310bd6e6d795e to your computer and use it in GitHub Desktop.
Save Konfekt/c2066abc31b41430417310bd6e6d795e to your computer and use it in GitHub Desktop.
A dead-simple markdown previewer in Vim thanks to KDE's document viewer Okular

KDE's document viewer Okular renders markdown as HTML (and reloads it automatically on changes.) Thus, simply open the markdown file currently edited in Vim in Okular to be all set!

To start an GUI application from Vim, without freezing, hit-<enter> prompts or scrambling screen lines, one can add a command such as

if has('unix')
  command! -complete=shellcmd -nargs=1 -bang Silent execute ':silent !' . (<bang>0 ? 'nohup ' . <q-args> . '</dev/null >/dev/null 2>&1 &' : <q-args>) | execute ':redraw!'
elseif has('win32')
  command! -complete=shellcmd -nargs=1 -bang Silent execute ':silent !start ' . (<bang>0 ? '/b ' : '') . <q-args> | execute ':redraw!'
endif
command! OK Silent! okular %:S

to call okular by

:OK
@Konfekt
Copy link
Author

Konfekt commented Mar 20, 2024

To use okular with &shell=pwsh or powershell as well, replace the fourth line by

  command! -complete=shellcmd -nargs=1 -bang Silent
        \ execute ':silent !' .
        \ (&shell =~? '\v(^|\\)cmd\.exe$' ? '' : 'cmd.exe /c ') .
        \ (<bang>0 ? 'start /b ' : '') . <q-args> | execute ':redraw!'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment