How can I set the clang format in Ubuntu

I am trying to use clang-tools, in particular the clang format, to automatically format the code in vim, but I could not find this tool using apt-get search.

Has anyone encountered this problem before, do you have any suggestions?

+16
code-formatting vim clang clang-format
source share
3 answers

Clang format is not available in Ubuntu-exact 12.04, but is available in Ubuntu Saucy http://packages.ubuntu.com/saucy/clang-format-3.4 .

To find this package with apt cache, we need to add the list below to our list of repositories. In fact, the list below is generated for Singapore servers, but if you want to search your country, you can use http://repogen.simplylinux.ch/generate.php

After creating your list, you should add them to your repository, you can find out how to do this by looking here. https://help.ubuntu.com/community/Repositories/CommandLine

There is a list of packages;

deb http://sg.archive.ubuntu.com/ubuntu/ saucy main restricted universe multiverse deb-src http://sg.archive.ubuntu.com/ubuntu/ saucy main restricted universe multiverse deb http://sg.archive.ubuntu.com/ubuntu/ saucy-security main restricted universe multiverse deb http://sg.archive.ubuntu.com/ubuntu/ saucy-updates main restricted universe multiverse deb http://sg.archive.ubuntu.com/ubuntu/ saucy-proposed main restricted universe multiverse deb http://sg.archive.ubuntu.com/ubuntu/ saucy-backports main restricted universe multiverse deb-src http://sg.archive.ubuntu.com/ubuntu/ saucy-security main restricted universe multiverse deb-src http://sg.archive.ubuntu.com/ubuntu/ saucy-updates main restricted universe multiverse deb-src http://sg.archive.ubuntu.com/ubuntu/ saucy-proposed main restricted universe multiverse deb-src http://sg.archive.ubuntu.com/ubuntu/ saucy-backports main restricted universe multiverse 

Then you must first find the clang format using the command below

sudo apt-cache search in clang format

Then you can install which version you want to install, for example;

sudo apt-get install clang-format-3.3

+12
source share

With Ubuntu 16.04, just do:

sudo apt install clang-format

+14
source share

Installation

Try it (in this order, one at a time, until it works):

 sudo apt install clang-format sudo apt install clang-format-9.0 sudo apt install clang-format-8.0 sudo apt install clang-format-7.0 sudo apt install clang-format-6.0 sudo apt install clang-format-5.0 sudo apt install clang-format-4.0 sudo apt install clang-format-3.6 sudo apt install clang-format-3.4 sudo apt install clang-format-3.0 

Then comment below this answer, which version of Linux or Linux Ubuntu you have, and which team worked for you.

To me:

Ubuntu 14.04 worked with sudo apt install clang-format-3.6

Additional settings and usage information and resources:

  1. Here is a Python script in git-clang-format so you can use git clang-format as a git command: https://llvm.org/svn/llvm-project/cfe/trunk/tools/clang-format/git- Clang format . Put it on your WAY; for example: in a file named "~ / bin / git-clang-format" and mark this file as executable ( chmod +x ~/bin/git-clang-format ).

    • The git workflow for invoking and using this file will be:

       git add my_changed_file.c # stage a file git clang-format # let clang-format fix it up (this runs your "~/bin/git-clang-format" Python script) git add my_changed_file.c # re-stage it since it been changed by clang-format git commit # commit the changed file 
  2. Instructions for setting up a Python script in git-clang-format : https://dx13.co.uk/articles/2015/4/3/Setting-up-git-clang-format.html
  3. instructions for use and workflow in git clang-format : https://electronjs.org/docs/development/clang-format
0
source share

All Articles