I installed clang-format-3.8
via apt-get.
Now I try to use it in gVim, but it is not working.
I checked and clang-format-3.8 exists in the folder /usr/share/vim/addons/syntax
.
But when I enter :pyf /usr/share/vim/addons/syntax/clang-format-3.8.py
in my vim command line, it returns:
E319: Sorry, the command is not available in this version
.
I use gVim 7.4 under Ubuntu 16.04.
You can install clang-format and git-clang-format via npm install -g clang-format . To automatically format a file according to Electron C++ code style, run clang-format -i path/to/electron/file.cc . It should work on macOS/Linux/Windows.
Configuring Style with clang-format clang-format supports two ways to provide custom style options: directly specify style configuration in the -style= command line option or use -style=file and put style configuration in the . clang-format or _clang-format file in the project directory.
clang-format is located in clang/tools/clang-format and can be used to format C/C++/Java/JavaScript/JSON/Objective-C/Protobuf/C# code.
Short answer: YES. The clang-format tool has a -sort-includes option. Changing the order of #include directives can definitely change the behavior of existing code, and may break existing code.
Dahn's answer is correct that the Vim binary that ships with Ubuntu 16.04 is compiled with Python 3 rather than Python 2. The clang-format-3.8.py
script in the Ubuntu 16.04 clang-format-3.8
package is not compatible with Python 3.
But the latest clang-format.py
does work with Python 3. You can get it here:
https://llvm.org/svn/llvm-project/cfe/trunk/tools/clang-format/clang-format.py
I think it was just a matter of putting parentheses around the print
statements.
Save this file somewhere on your computer such as /usr/local/share/vim/addons/syntax/
.
This script uses clang-format
as the binary name, so you'll want to install the clang-format
package, which installs the clang-format
command as a symlink to clang-format-3.8
.
Since Vim is now loading a Python 3 script, replace your :pyf
(not available) command with :py3f
:
:py3f /usr/local/share/vim/addons/syntax/clang-format.py
The Vim binary shipped with Ubuntu 16.04 is compiled with Python 3. The vim addons of clang-format is written by Python 2.
You need to either:
The instructions to build vim with Python can be found by Google.
In addition to the above answers I had to do a few more things. I downloaded a new python file and changed the key mapping recommended by in the clang python file to the following in my .vimrc:
map <C-I> :py3file <path-to-this-file>/clang-format.py<cr>
imap <C-I> <c-o>:py3file <path-to-this-file>/clang-format.py<cr>
This solved the E319 problem I was getting.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With