Last active
April 17, 2024 07:41
-
-
Save Konfekt/8e484af2955a0c7bfe82114df683ce0f to your computer and use it in GitHub Desktop.
Open GUI application / file from Vim in background
This file contains 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
" To start the GUI app, use :Silent! app | |
" Useful, say, to look up a keyword by :set keywordprg=:Silent!\ zeal | |
" To open file, use :Open! file | |
" Useful, say, to view a compiled HTML of a markdown file, by :Open! %:r.html | |
if executable('cmd.exe') " Win32 or WSL | |
command! -complete=shellcmd -nargs=1 -bang Silent | |
\ execute ':silent !' . | |
\ (&shell =~? '\v(^|\\)cmd\.exe$' ? '' : 'cmd.exe /c ') . | |
\ (<bang>0 ? 'start /b ' : '') . <q-args> | execute ':redraw!' | |
elseif 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!' | |
endif | |
command! -complete=shellcmd -nargs=1 -bang Sil Silent<bang> <args> | |
" Windows / Git Bash / WSL | |
if executable('cmd.exe') | |
let s:cmd = "explorer.exe" | |
" Linux/BSD | |
elseif executable("xdg-open") | |
let s:cmd = "xdg-open" | |
" MacOS | |
elseif executable("open") | |
let s:cmd = "open" | |
endif | |
exe 'command! -complete=file -nargs=1 -bang Open exe "Silent<bang> ' . s:cmd . ' " . shellescape(<q-args>)' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment