I am attempting to use the google.vim (and on vim.org) indent style for my c++ project, but I can't seem to load it. I installed google.vim using vundle and opened up a cpp file and noticed that my tabstops, shiftwidths, etc did not change. If you set global ts and sw parameters, are they not overwritten? How do you force a certain indention when editing a file in vim? I want everything in my vimrc file to be overwritten by the google.vim file when I edit a cpp file.
Running the :filetype command in vim reveals this information:
detection:ON plugin:ON indent:ON
The bottom line is that I don't understand how to tell vim to use my google.vim file located under ~/.vim/vundle/google.vim/indent/google.vim. From what I have read, vim detects that filetype of your current file and uses the appropriate .vim file for syntax and indentation. So would I then have to rename my google.vim file to something like cpp.vim?
In most cases I like to use a tabstop of 3 and a shiftwidth of 3, so I set these in my .vimrc file. However, when I edit a cpp file, I want all my settings to be changed from what I have set globally to what the google.vim file sets.
You must rename the file from google.vim to cpp.vim, as indicated in the description of the plugin on vim.org.
General explanation:
Adding filetype plugin indent on to your ~/.vimrc allows Vim to detect the filetype of the files you edit (usually based on the file extention) and source filetype-specific plugins and indent scripts.
The idea is simple: you edit a file with {{LANGUAGE}} filetype and Vim tries to source any ftplugin/{{LANGUAGE}}.vim and indent/{{LANGUAGE}}.vim it finds in your runtimepath.
Because the filetype of your file is cpp, Vim will blissfully ignore your google.vim indent script so… you must rename it to cpp.vim for it to work.
Or you could rename all your C++ files foobar.google and teach Vim to recognize *.google files but, well… it doesn't sound right ;-)
Related
We have a custom .clang-format file in the root folder of our repository and use clang-format with -style=file for all C and C++ files.
I like to change the formatting rules of clang-format for one file only.
In particular I like to switch BinPackArguments form true to false.
I know, that I could place a .clang-format file in the corresponding folder. This option does effect all files in this folder.
Formatting it differently once is not an option, because our version control system will reject not formatted files.
I know, that I could turn off the formatter via the comment
// clang-format off
This has the drawback that the file is not formatted at all.
Is there a way to change one option for one file only (perhaps via a comment)?
I am using cpplint to check my sourcode agains the google style guide.
Cpplint's help says:
cpplint.py supports per-directory configurations specified in CPPLINT.cfg
files. CPPLINT.cfg file can contain a number of key=value pairs.
Currently the following options are supported:
"exclude_files" allows to specify a regular expression to be matched against
a file name. If the expression matches, the file is skipped and not run
through liner.
Example file:
filter=-build/include_order,+build/include_alpha
exclude_files=.*\.cc
The above example disables build/include_order warning and enables
build/include_alpha as well as excludes all .cc from being
processed by linter, in the current directory (where the .cfg
file is located) and all sub-directories.
How I use cpplint:
I use cpplint by this command to check all files in my source folder:
cpplint src/*.c
Well there is one special file foo.cc which must not be checked. So I tried to create a CPPLIN.cfg to use the exclude_files property. My file looks like this:
set noparent
filter=-build/include_dir
exclude_files=foo.cc
Nevertheless foo.cc is still checked.
What I have already tried to do:
I tried exclude_files=/.*\.cc/. This should exclude all files ending with *.cc. Nevertheless all files are still checked.
I tried to remove my filter from the file. This caused more errors than before. So I am now sure that my CPPLINT.cfg file is found by cpplint.
Question:
How to use the exclude_files regex in cpplint correctly?
Turns out apparently that the doc is wrong: exclude_files only excludes files in the same directory as CPPLINT.cfg, not in subdirectories. See https://github.com/google/styleguide/issues/220
So the solution would be to create src/CPPLINT.cfg and put exclude_files=.*\.cc in it.
I would like to indent lines in files (SQL files, XML...),
and in spite of all that I searched and tried, for some reason
on my Linux servers the command gg=G does nothing (all my lines
keep their first character stuck against the left part of my
terminal...), but displays the message "X lines indented" anyway !
Under Windows where I use gvim it works perfectly.
What does it depend on ? My shiftwidth is well set to 8,
I don't know what else I should check... (some config file
maybe ?, no idea)
Make sure you set set nocompatible and filetype plugin indent on in your .vimrc. Open your XML file and enter :set filetype?. Vi(m) should recognize your file now as XML file (if it does not, tell Vi(m) that the currently open file is an XML file by specifying :set filetype=xml). Try to indent your source code now with gg=G.
So I downloaded, installed, and inserted into path the clang formatting plugin. I also tested it and it works for Google (Mozilla, etc.) formatting options out of the box, yet I cannot get it working with my .clang-format file. (I've put my file into the same folder as my source file, changed its encoding into UTF-8, also tried to put it into clang install folder, add file into project, write its contents inside '{key:value}' yet formatting does not happen). So how do you feed formatting file to chrome-format extension?
My file contents:
{ BasedOnStyle: "LLVM", IndentWidth: 4 }
My file name:nm.clang-format
Go to Tools->Options->LLVM/Clang->ClangFormat and put file in the Style option field.
Then place your style file named .clang-format (this is the full filename, not an extension) either in the source file's directory or one of its parent directories. Windows Explorer won't let you create filenames with leading . so you need to go to the console for this.
If like me you got confused later on where the .clang-format was living, use procmon to track the file reads of clang-format.exe
For the record, it seems that if both "Fallback Style" and "Style" are set to "file", no formatting will happen even if the style file is at its correct location. Setting "Fallback Style" to something different than "file" (e.g. "none") helps.
In VS2019 works if the clang-format file is named as .clang-format.
It must be .clang-format, not .clang-format.txt or clang-format.txt.
I typed the source code in WordPad and saved it as addition.f90 but, unfortunately, the only options Windows provides are text files, rtf's, and so forth.
I am using the G95 compiler for Windows.
In the WordPad Save dialog, type the filename in double quotes, e.g. "addition.f90". This will override the default extension.
I suggest you use a decent text editor instead. Have a look at notepad++, VIM, GNU Emacs or similar.
To rename a file in Windows you either use the command prompt:
rename file.f90.rtf file.f90
Or you can use the Windows explorer. Make sure you set it up to display file extensions. Under Tools | Folder Options, unselect 'Hide extensions for known file types'. To rename a file, either select it and press F2, or right-click and select Rename.