Google chrome 为什么可以';是否在gvim映射功能中使用chrome打开html?
我已经在vimrc文件中映射了F6和F7Google chrome 为什么可以';是否在gvim映射功能中使用chrome打开html?,google-chrome,vim,Google Chrome,Vim,我已经在vimrc文件中映射了F6和F7 :nnoremap <F6>:w<cr> :!start cmd C:\Program Files (x86)\Google\Chrome\Application\chrome.exe %<CR> :nnoremap <F7>:w<cr> :exe '!"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" %'<CR
:nnoremap <F6>:w<cr> :!start cmd C:\Program Files (x86)\Google\Chrome\Application\chrome.exe %<CR>
:nnoremap <F7>:w<cr> :exe '!"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" %'<CR>
In CMD ,it works fine for me.
C:\Users\pengsir>"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" g:\\my.html
:nnoremap:w:!启动cmd C:\Program Files(x86)\Google\Chrome\Application\Chrome.exe%
:nnoremap:w:exe'!“C:\ProgramFiles(x86)\Google\Chrome\Application\Chrome.exe”%”
在CMD中,它对我来说很好。
C:\Users\pengsir>“C:\ProgramFiles(x86)\Google\Chrome\Application\Chrome.exe”g:\\my.html
当我在gvim中打开g:\my.html并进入正常状态时,按F6或F7,为什么我的chrome无法打开my.html
<!DOCTYPE html>
<html>
<HEAD>
<META CHARSET="UTF-8" />
<TITLE> FIRST WEB</TITLE>
<body>
it is my first web
</body>
</html>
第一网
这是我的第一个网站
当我在GVIM中按F6时
好的,让我们一步一步地解决这个问题:
:nnoremap <F6>:w<cr> :!start cmd C:\Program Files (x86)\Google\Chrome\Application\chrome.exe %<CR>
这给了我一个打开的命令提示符,但没有Chrome。您需要传递/C
或/K
,以便余数作为命令执行cmd.exe/?
告诉您这一点。让我们首先使用/K
来读取任何错误
:nnoremap <F6> :w<cr> :!start cmd /K C:\Program Files (x86)\Google\Chrome\Application\chrome.exe %<CR>
那一个在Chrome中为我打开当前的HTML文件。最后,只需去掉遗留的命令提示符(/C
),加入两个Ex命令,将:w
替换为按需:update
:
:nnoremap <F6> :update<Bar>execute '!start cmd /C "' shellescape('C:\Program Files (x86)\Google\Chrome\Application\chrome.exe', 1) shellescape(expand('%'), 1) . '"'<CR>
:nnoremap:updateexecute'!启动cmd/C“'shellescape('C:\Program Files(x86)\Google\Chrome\Application\Chrome.exe',1)shellescape(expand('%”),1)。”
通过始终通过完整的绝对路径,您可以使其更具弹性:
:nnoremap <F6> :update<Bar>execute '!start cmd /C "' shellescape('C:\Program Files (x86)\Google\Chrome\Application\chrome.exe', 1) shellescape(expand('%:p'), 1) . '"'<CR>
:nnoremap:updateexecute'!启动cmd/C“'shellescape('C:\Program Files(x86)\Google\Chrome\Application\Chrome.exe',1)shellescape(expand('%:p'),1)。”
这可能与需要转义的空格或反斜杠有关。我已经测试过了,无法打开它。这是提供少量信息以进一步帮助您的方式!问题出在哪里?我特意一步一步地开发了这个程序,这样你就可以跟随并理解每一步了!这是一个路径问题,当我在chrome中打开g:\my.html时,路径是file:///G:/my.html
,当我按F6时,路径为http://my.html/
,如何将其更改为file:///G:/my.html
?您从今天开始尝试过我的编辑吗?我在这里介绍了扩展('%:p')
?!干得好,:nnoremap:updateexecute'!启动cmd/C“'shellescape('C:\Program Files(x86)\Google\Chrome\Application\Chrome.exe',1)shellescape(expand('%:p'),1)。”
:nnoremap <F6> :update<Bar>execute '!start cmd /C "' shellescape('C:\Program Files (x86)\Google\Chrome\Application\chrome.exe', 1) shellescape(expand('%'), 1) . '"'<CR>
:nnoremap <F6> :update<Bar>execute '!start cmd /C "' shellescape('C:\Program Files (x86)\Google\Chrome\Application\chrome.exe', 1) shellescape(expand('%:p'), 1) . '"'<CR>