为什么不能在gvim map函数中用chrome打开html? [英] why can't open the html with chrome in gvim map function?

查看:134
本文介绍了为什么不能在gvim map函数中用chrome打开html?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 :nnoremap< F6>:w< cr>我们已经在vimrc文件中映射了F6和F7。 :!start cmd C:\程序文件(x86)\Google\Chrome\Application\chrome.exe%< CR> 

:nnoremap< F7>:w< cr> :exe'!C:\程序文件(x86)\Google\Chrome\Application\chrome.exe%< CR>

在CMD中,它适用于我。

C:\ Users \pengsir>C:\程序文件(x86)\Google\Chrome\Application\chrome.exeg:\\my。 html

当我在gvim中打开g:\my.html并进入正常状态时,按F6或F7,为什么我的chrome无法打开my.html?

 <!DOCTYPE html> 
< html>
< HEAD>
< META CHARSET =UTF-8/>
< TITLE> FIRST WEB< / TITLE>
< body>
这是我的第一个网站
< / body>
< / html>

当我按F6 IN GVIM时,



解决方案

好的,让我们一步步解决这个问题: / p>

 :nnoremap< F6>:w< cr> :!start cmd C:\程序文件(x86)\Google\Chrome\Application\chrome.exe%< CR> 

首先,lhs之间缺少空格(< F6> code>)和:w ... rhs;您目前正在映射关键组合< F6>:w< cr>

 :nnoremap< F6> :W< CR> :!start cmd C:\程序文件(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> 

现在我得到'C:\Program'不被识别为内部或外部命令,可操作程序或批处理文件。;我们需要引用。我们可以用双引号将路径手工封装,但是您可能想要处理通过传递的任何文件名,最好让Vim执行引用。为此,我们需要:execute (插入表达式)和 shellescape()



另一个 cmd.exe 的怪癖是,一旦你使用了引用,你需要引用整个命令再次,线。 (如果这件事情已经过去了,不要感到愚蠢; Microsoft和MS-DOS的兼容性应该归咎于这一混乱,Vim也在这方面进行了改进;确保至少使用7.3.800版本,或者7.4。)

 :nnoremap< F6> :W< CR> :'执行'!start cmd / K''shellescape('C:\程序文件(x86)\Google\Chrome\Application\chrome.exe',1)shellescape(展开('%'),1 )。''''< CR> 

在Chrome中为我打开当前的HTML文件。为了完成触摸操作,只需删除左侧的命令提示符( / C ),然后加入两个Ex命令,替换:w 与$ :update

  :nnoremap< F6> :'更新< Bar>执行'!start cmd / C''shellescape('C:\Program Files(x86)\Google\Chrome\Application\chrome.exe',1)shellescape(expand(' '),1)''''< CR> 

您可以通过始终传递完整绝对路径来提高灵活性:

 :nnoremap< F6> :'更新< Bar>执行'!start cmd / C''shellescape('C:\Program Files(x86)\Google\Chrome\Application\chrome.exe',1)shellescape(expand(' :p'),1)''''< CR> 


I have mapped F6 and F7 in vimrc file.

: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

When i open g:\my.html in gvim and enter into normal status ,press F6 or F7,why my chrome can not open the my.html?

<!DOCTYPE html>
<html>
<HEAD>
<META CHARSET="UTF-8" />
<TITLE> FIRST WEB</TITLE>
<body>
   it is my first web
</body>
</html>

When i press F6 IN GVIM ,

解决方案

Okay, let's solve this step by step:

:nnoremap <F6>:w<cr> :!start cmd  C:\Program Files (x86)\Google\Chrome\Application\chrome.exe %<CR>

First, there's whitespace missing between the lhs (<F6>) and the :w... rhs; you're currently mapping the key combo <F6>:w<cr>.

:nnoremap <F6> :w<cr> :!start cmd  C:\Program Files (x86)\Google\Chrome\Application\chrome.exe %<CR>

That gives me an open command prompt, but no Chrome. You need to pass either /C or /K so that the remainder is executed as a command; cmd.exe /? tells you this. Let's first use /K to be able to read any errors.

:nnoremap <F6> :w<cr> :!start cmd /K C:\Program Files (x86)\Google\Chrome\Application\chrome.exe %<CR>

I now get 'C:\Program' is not recognized as an internal or external command, operable program or batch file.; we need quoting. We could manually enclose the path in double quotes, but as you probably want to handle any file names passed via %, it's better to let Vim do the quoting. For that, we need :execute (to insert the expressions) and shellescape().

Another hairy quirk of cmd.exe is that once you use quoting, you need to quote the entire command-line again, too. (Don't feel stupid if this is over your head; Microsoft and compatibility down to MS-DOS is to blame for this mess. Vim underwent improvements in that area, too; be sure to use at least a version 7.3.800, or 7.4.)

:nnoremap <F6> :w<cr> :execute '!start cmd /K "' shellescape('C:\Program Files (x86)\Google\Chrome\Application\chrome.exe', 1) shellescape(expand('%'), 1) . '"'<CR>

That one opens the current HTML file in Chrome for me. For finishing touches, just get rid of the left-behind command prompt (/C), and join the two Ex commands, replacing :w with the on-demand :update:

:nnoremap <F6> :update<Bar>execute '!start cmd /C "' shellescape('C:\Program Files (x86)\Google\Chrome\Application\chrome.exe', 1) shellescape(expand('%'), 1) . '"'<CR>

You can make that a bit more resilient by always passing the full absolute path:

:nnoremap <F6> :update<Bar>execute '!start cmd /C "' shellescape('C:\Program Files (x86)\Google\Chrome\Application\chrome.exe', 1) shellescape(expand('%:p'), 1) . '"'<CR>

这篇关于为什么不能在gvim map函数中用chrome打开html?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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