简体   繁体   English

在Vimrc中使用空格设置Pathvariable

[英]Set a Pathvariable in vimrc with whitespace

I try to set up my Vim to use omnicppcomplete. 我尝试将Vim设置为使用omnicppcomplete。

I followed the constructions c++ code completion to install it step by step. 我按照结构c ++代码完成的步骤逐步安装它。 First I always get the error "Omni-completion (^0^N^P) Pattern not found". 首先,我总是收到错误“找不到全完成(^ 0 ^ N ^ P)模式”。 It was hard to figure out but now i know why it doesn't work. 很难弄清楚,但现在我知道为什么它不起作用了。 Its because the following line in my vimrc 这是因为我的vimrc中的以下行

"set tags+=C:\\Program\\ Files\\ (x86)\\Vim\\vim74\\tags\\cpp" “设置标签+ = C:\\ Program \\ Files \\(x86)\\ Vim \\ vim74 \\ tags \\ cpp”

Vim can't handle the whitespaces in the path but i don't know how to get it work except to copy the tag-files into another directory (which i try and it worked). Vim不能处理路径中的空格,但是我不知道如何使它工作,除非将标记文件复制到另一个目录(我尝试并成功了)。 I tried these options but nothing worked: 我尝试了这些选项,但没有任何效果:

  • C:\\Program\\\\ Files\\\\ (x86)\\Vim\\vim74\\tags\\cpp C:\\ Program \\\\ Files \\\\(x86)\\ Vim \\ vim74 \\ tags \\ cpp
  • C:/Program\\ Files\\ (x86)/Vim/vim74/tags/cpp C:/程序\\文件\\(x86)/ Vim / vim74 /标签/ cpp
  • C:\\Program\\< Space >Files< Space >(x86)\\Vim\\vim74\\tags\\cpp C:\\ Program \\ <空间>文件<空间>(x86)\\ Vim \\ vim74 \\ tags \\ cpp
  • C:\\Program\\sFiles\\s(x86)\\Vim\\vim74\\tags\\cpp C:\\ Program \\ sFiles \\ s(x86)\\ Vim \\ vim74 \\ tags \\ cpp
  • C:\\Program\\\\sFiles\\\\s(x86)\\Vim\\vim74\\tags\\cpp C:\\ Program \\\\ sFiles \\\\ s(x86)\\ Vim \\ vim74 \\ tags \\ cpp
  • C:\\Program/\\sFiles/\\s(x86)\\Vim\\vim74\\tags\\cpp C:\\ Program / \\ sFiles / \\ s(x86)\\ Vim \\ vim74 \\ tags \\ cpp

How do I have to write the path so omnicppcomplete can use the tags? 我该如何写路径,以便omnicppcomplete可以使用标签?

See :help option-backslash . 参见:help option-backslash When using the :set command, you need to escape every backslash, and every space character, so you will need three backslashes to set paths with spaces! 使用:set命令时,需要转义每个反斜杠每个空格字符,因此需要三个反斜杠来设置带空格的路径! Ie set tags+=C:\\\\Program\\\\\\ Files\\\\\\ (x86)\\\\Vim\\\\vim74\\\\tags\\\\cpp set tags+=C:\\\\Program\\\\\\ Files\\\\\\ (x86)\\\\Vim\\\\vim74\\\\tags\\\\cpp

Sometimes a nicer way, is to use a :let command, so that you can use single-quoted strings and don't need to escape as much. 有时,更好的方法是使用:let命令,以便可以使用单引号引起来的字符串,而不必进行太多转义。 For example, :let &tags.=',C:\\Program\\ Files\\ (x86)\\Vim\\vim74\\tags\\cpp' 例如:let &tags.=',C:\\Program\\ Files\\ (x86)\\Vim\\vim74\\tags\\cpp'

Try this: 尝试这个:

let &tags .= ',C:\Program\ Files\ (x86)\Vim\vim74\tags\cpp'

An option opt can also be accessed as a variable &opt , which can be manipulated with let , can be used in expressions, and so on. 选项opt也可以作为变量&opt进行访问,该变量可以使用let进行操作,可以在表达式中使用,等等。 Unlike set , let has an almost sane syntax. set不同, let具有几乎合理的语法。

Also, paths in tags have to be separated by commas. 另外, tags路径必须用逗号分隔。

I had the same problem. 我有同样的问题。 Try just to use / in paths, and escape whitespace like this '\\ '. 尝试仅在路径中使用/ ,并使用“ \\”这样的空格进行转义。 For example I add this line in my vimrc: 例如,我在vimrc中添加以下行:

set rtp=C:/Program\ Files\ (x86)/Vim/vim74/vim.exe

Than if you will command :echo &rtp you can see: 比起执行:echo &rtp命令:echo &rtp您可以看到:

C:/Program Files (x86)/Vim/vim74/vim.exe

Note that here is no \\ before whitespace. 请注意,在空格前没有\\

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM