preview.nvimgithub
Preview anything in neovimor vim.
- Platform
- Linux
- Editor
- neovimor vim
- vim 8 or later
- neovim is preferred
- Ensure editor can detech filetype, and set
&ft. try Running:set ftin a specific filetype file.
- neovimor vim
- Browser
- Ensure the browser support websocket
- Ensure the browser can open a html as an argument in command line
- You can set it by set
g:preview_browser
- golang
- Program is written by go language, so ensure go programs can works
make -B -f makefile.default
And then edit a file in test/ by neovim, like
nvim test/preview.c
ft/c/preiview.vimuseclangas compiler, ensureclangis valid.
And run :so ~/.vim/preview/preview.vim in neovim.
A browser will be opened and shows the resoult if code in preview.c is executed.
Try editing and see changes in web page.
If dot is valid,
try test/lwip_dhcp_renew_calltree.dot.
source ~/.vim/preview/preview.vim too.
And preview.r, ft/r/preview.vim is for R language.
And relative files will be:
| Description | path | Vim-variable |
|---|---|---|
preview.vim |
~/.vim/preview/preview.vim |
Not in a vim variabl, You shold source it directly |
Compiled websocket.go |
~/.vim/preview/websocket |
g:preview_websocket_program |
| Some example of specific filetypes | ~/.vim/preview/ft/*.vim |
'g:preview_'.&ft.'_vimrc' |
After make -f makefile.default,
assuming you are editing a
dot
file,
and :source ~/.vim/preview/preview.vim in neovim,
it will works as below:
The browser will update preview when neovim buffer change.
Enter subdirectories to learn about specific components.
Content below explain How I design preview.nvimgithub itself and What I actually do.
GRAPH above shows how I send data from a unsaved but changed edit buffer to browser.
This can be simply done by :w !. Just :help w_c.
The truly troublesome process is
convert various file types to
what browser can render(generally html).
See ft/ for more details.
Up to now, maybe websocket is the only choise.
More specifically, every time the edit bufffer changed was deteted by
autocmd InsertLeave,TextChanged,TextChangedI <buffer>
w ! will send the whole
buffer content to some programs
that convert it to renderable format,
and the converted data will be sent to
a socket.
And then websocket get it from socket,
and replace the web page content to it
by change <body/>'s innerHTML.
These are implememted in websocket.go
In preview.vim.
Besides, preview.vim
also startup a browser,
write socket number, websocket number to files,
and manage them by neovimor vim rpc.
Note that preview.nvimgithub is mainly for neovim. So maybe vim would not work, especially about rpc.