Open current file in web browser in Vim

前端 未结 9 539
自闭症患者
自闭症患者 2020-12-24 15:01

I\'d like to be able to send the HTML file I\'m currently editing in vim to my web browser, Chrome. I\'m running Linux.

This gets me very close:

相关标签:
9条回答
  • 2020-12-24 15:12

    From my .vimrc:

    nnoremap <F12>f :exe ':silent !firefox %'<CR>
    nnoremap <F12>c :exe ':silent !chromium-browser %'<CR>
    nnoremap <F12>o :exe ':silent !opera %'<CR>
    

    These three commands open the current file in the chosen browser without side effects. The use of <F12> makes it GVim-only, though.

    0 讨论(0)
  • 2020-12-24 15:13

    What about :!open % -a Google\ Chrome ?

    0 讨论(0)
  • 2020-12-24 15:24

    I use the shell.vim plugin to run commands in background on Windows. I don't know exactly what it does, but I believe it also works for that on Linux:

    http://www.vim.org/scripts/script.php?script_id=3123

    Shell.vim does allow for asynchronous external commands, but I don't know whether it allows you to keep focus with Vim terminal, avoid moving back manually.

    Another plugin that allows asynchronous calls is below, although it relies on having Vim compiled with Python support and I haven't tested: https://github.com/MarcWeber/vim-addon-background-cmd

    0 讨论(0)
  • 2020-12-24 15:28

    You can exec chrome silently:

    nmap <silent> <leader>w :exec 'silent !google-chrome % &'
    

    :exe[cute] {expr1} .. Executes the string that results from the evaluation of {expr1} as an Ex command.

    0 讨论(0)
  • 2020-12-24 15:30

    For windows 7 or 10 put this line into your .vimrc file:

    nnoremap <silent> <F5> :!start file://C:/Users/<your username here>/AppData/Local/Google/Chrome/Application/chrome.exe %:p<CR>
    

    or try:

    nnoremap <silent> <F5> :!start file://C:/Program Files (x86)\Google\Chrome\Application\chrome.exe %:p<CR>
    

    for more details see this link: Preview current HTML file

    0 讨论(0)
  • 2020-12-24 15:31

    I wrote a small plugin with 7 commands to handle web searches.

    After installing you could use:

    • :WSearchInit to start a sites repository in the current folder
    • :WSearchSaveTagAndSite google www.google.com/search?q={WSearch} to save a site with corresponding tag

    and then search with:

    • :WSearch will run your latest saved or searched site replacing {WSearch} with the cursored word
    • :WSearch Manual Search will do the same as WSearch but instead will replace {WSearch} with Manual+Search.

    I hope it can help you or other people with the same problem.

    0 讨论(0)
提交回复
热议问题