Skip to content

riku-ri/preview.nvim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

preview.nvimgithub

Preview anything in neovimor vim.

How to use it

Requirement

  • Platform
    • Linux
  • Editor
    • neovimor vim
      • vim 8 or later
      • neovim is preferred
      • Ensure editor can detech filetype, and set &ft. try Running :set ft in a specific filetype file.
  • 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

Quick start

make -B -f makefile.default

And then edit a file in test/ by neovim, like

nvim test/preview.c

ft/c/preiview.vim use clang as compiler, ensure clang is 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.

What makefile.default will do

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'

How does it work

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.

More details

Enter subdirectories to learn about specific components.

For developers

Content below explain How I design preview.nvimgithub itself and What I actually do.

What we need to do

For sending data from neovimor vim edit buffer to browser

GRAPH above shows how I send data from a unsaved but changed edit buffer to browser.

From neovimor vim edit buffer to other programs

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.

For auto refresh page content when edit buffer changed

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

Combine steps above

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.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •