【问题标题】:Prepare vim environment to work with clang-format准备 vim 环境以使用 clang 格式
【发布时间】:2017-04-02 20:54:56
【问题描述】:

问题:

E319:抱歉,此版本不支持该命令

问题
当我运行 vim 环境并尝试重新格式化代码 (CTRL+K) 时,我在屏幕上收到此警告

环境:
系统:Mac OS X

设置:
维姆:

VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Nov 17 2016 20:17:27)
MacOS X (unix) version
Included patches: 1-91

蟒蛇:

python --version: Python 3.5.2

我做什么

谢谢,

【问题讨论】:

  • 1. clang-format.py 不做“重构”。 2. 你构建了 Vim 吗?如何? 3.向我们展示$ vim --version的完整输出。

标签: c++ macos vim clang clang-format


【解决方案1】:

解决方案:

1. 进入.vimrc文件并添加命令

map <C-K> :pyf <path-to-this-file>/clang-format.py<cr>
imap <C-K><c-o>:pyf <path-to-this-file>/clang-format.py<cr>

2.将此https://llvm.org/svn/llvm-project/cfe/trunk/tools/clang-format/clang-format.py源代码添加到clang-format.py文件中,可以将这个文件保存到i.e

<path-to-this-file>/clang-format.py

其中 path-to-this-file 是指向您放置此文件的方向的路径。

3.保存 clang-format.py 文件并运行 vim。检查命令是否有效。

您也可以为 OSX 安装 macvim。您可以在此处找到说明。 How can I install MacVim on OS X?

PS:如果您收到“抱歉,该命令在此版本中不可用”错误,请尝试:

map <C-K> :py3f <path-to-this-file>/clang-format.py<cr>
imap <C-K><c-o>:py3f <path-to-this-file>/clang-format.py<cr>

【讨论】:

  • E319: Sorry, the command is not available in this version 也在 macvim 上
  • 您无权访问此服务器上的/svn/llvm-project/cfe/trunk/tools/clang-format/clang-format.py。
【解决方案2】:

这里

$ which clang-format

返回

/usr/local/bin/clang-format

然后

ls -ls /usr/local/bin/clang-format

指向

/usr/local/Cellar/clang-format/2018-04-24/share/clang/clang-format.py

所以我愿意

$ vim ~/.vimrc

map <C-K> :pyf /usr/local/Cellar/clang-format/2018-04-24/share/clang/clang-format.py<cr>
imap <C-K> <c-o>:pyf /usr/local/Cellar/clang-format/2018-04-24/share/clang/clang-format.py<cr>

这适用于 vim(从终端)但不适用于 macvim。

【讨论】:

    【解决方案3】:

    只要提到项目https://github.com/rhysd/vim-clang-format

    使用起来非常方便,让我们免于重复工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-03
      • 2011-05-31
      • 2016-11-17
      • 2016-08-01
      • 1970-01-01
      相关资源
      最近更新 更多