在 Vim 中的 Web 浏览器中打开当前文件 [英] Open current file in web browser in Vim

查看:25
本文介绍了在 Vim 中的 Web 浏览器中打开当前文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够将我当前在 vim 中编辑的 HTML 文件发送到我的网络浏览器 Chrome.我正在运行 Linux.

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.

这让我非常接近:

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

浏览器打开并显示正确的文件.但是,该命令并未在后台运行,而这正是 & 应该做的.取而代之的是 vim 进入后台,我的终端窗口输出了一些文本.然后我必须点击并按下 Enter 来让我的 vim 回到前台.

The browser opens and displays the correct file. However, the command isn't running in the background, which is what the & is supposed to do. Instead vim drops to the background and I get some text output to my terminal window. I then have to do some clicking and Enter pressing to get my vim to come back to the foreground.

我错过了什么吗?

更新:感谢所有建议.问题似乎是当浏览器窗口打开时,焦点似乎从我的终端窗口转移了.不知道我能不能对此做些什么.

UPDATE: Thanks for all the suggestions. The issue seems to be that the focus seems to shift away from my terminal window when the browser window opens. Not sure if there's anything I can do about this.

推荐答案

来自我的 .vimrc:

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>

这三个命令在选择的浏览器中打开当前文件,没有副作用.不过, 的使用使它成为 GVim-only.

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

这篇关于在 Vim 中的 Web 浏览器中打开当前文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆