Vim syntax colouring for gcov not working as inteded - vim

I'm new to Vim, and am a little puzzled.
I'm using gcov (through clang), and installed a .gcov vim syntax file from here by placing it in my vim syntax folder - but the highlighting doesn't appear.
What am I missing? Thanks!

You need these two lines in your ~/.vimrc for syntax highlighting to work properly:
filetype on
syntax on
Because it's generally what people want, you should probably use:
filetype plugin indent on
syntax on
The first line ensures that Vim recognizes the filetype, loads any filetype-specific options/mappings/autocmds and applies the filetype's built-in indent rules.
The second line activates synatx highlighting.

Related

Why is Vim and vi adding leadings characters instead of a blank line?

On macOS v10.13 (High Sierra), the o command adds a new line leading with a # instead of a blank line as expected. This is off of a "#include <stdio.h>" line. Other lines do similar things. How can I revert back to normal Vim (vi does the same thing)?
I checked :version and all those rc files do not exist. The issue started after I tried to install an add on to do advanced syntax help.
The behavior you describe is caused by the presence of o in the current value of the :help 'formatoptions' option, which doesn't have it by default.
The issue started after I tried to install an add on to do advanced syntax help.
During that process, you probably added some variant of the following line in your vimrc:
filetype plugin on
which enables filetype detection and filetype plugins. The latter are filetype-specific plugins that, among other things, may redefine some options for the buffers belonging to that filetype.
In this case, Vim sets the filetype of the buffer to c (or maybe cpp but I will asume c from now on for simplicity), which triggers the sourcing of the corresponding ftplugin, which contains this:
" Set 'formatoptions' to break comment lines but not other lines,
" and insert the comment leader when hitting <CR> or using "o".
setlocal fo-=t fo+=croql
Note the o in croql.
If you don't like that, you can either avoid enabling ftplugins by removing plugin from the vimrc line mentioned above, or write your own ftplugin override:
" in ~/.vim/after/ftplugin/c.vim
setlocal formatoptions=xxxxxxx
See :help fo-table for the potential values of formatoptions.

Disable syntax highlighting, but only for one filetype

I want to disable syntax highlighting for a particular programming language. I'm currently using this
au FileType foo syntax off
however this has the problem that it disables syntax highlighting for any new buffers that I open in the same window, even when they have different filetypes. Is it possible to disable syntax highlighting only for this filetype? (e.g. any other buffers in the same window that has different filetype should have syntax highlighting enabled)
One of the things that could solve this problem is to create a syntax/foo.vim file that doesn't highlight anything, but I'm not sure how to implement this when foo is one of the languages that vim highlights by default.
au FileType foo setlocal syntax=OFF
If you want to isolate the config a bit, create a file called ~/.vim/after/ftplugin/foo.vim and put this in it:
setlocal syntax=OFF

Which language's syntax highlighting does .vimrc use?

My .vimrc looks nice and syntax-highlighted:
I'd like to have the same style of syntax highlighting for my own file which is not called .vimrc.
What would I have to name my file so it gets the right syntax highlighting or, alternatively, which language's syntax highlighting is being used, so I can select it manually?
The filetype (as in what vim internally refers to as filetype) is 'vim'. You should be able to use any extension, really. Putting something along these lines into your .vimrc might work.
au BufNewFile,BufRead *.yourextension set filetype=vim

Vim autoindent indents incorrectly

When writing code in vim, I've noticed that it sometimes messes up the indentation of the current line after pressing return. (In the gif, I go into insert mode, with the cursor at the end of the date function. When I press return, the whole "echo date('Y');" part looses its indentation when it should not).
I have a ton of directives in my vimrc to try and stop all kinds of autoindentation, but much to my irritation, the problem persists.
filetype plugin indent off
filetype plugin off
set noautoindent
set nosmartindent
set nocindent
set indentexpr=''
let b:did_indent = 1
set ft?
filetype indent off
I wish there was a way to have vim indent files much like your "more standard" text editors, whereby they don't try to be smart, but just maintain the current indentation of the current line in the new line. Like this:
Is this possible?
set smartindent is only needed on my VIM to get the effect you shown by gedit.
So it seems that this line was causing the first issue displayed in the vim. Its part of the Vundle plugin manager inclusion code:
filetype plugin indent on
Ensuring that my indent rules were after this fixed the problem completely.

Vim Only Highlighting ~/.vimrc

I am a new vim user and trying to turn on syntax coloring for vim on Mac OS X. I followed http://vim.wikia.com/wiki/Turn_on_syntax_coloring_in_Mac_OS_X's instructions, and my ~/.vimrc file has the following content
set term=builtin_ansi
filetype plugin indent on
syntax on
And the text above in ~/.vimrc is highlighted perfectly fine. However, whenever I use vim to edit a current text file or create a new one, I only see black and white text, and manually calling :syntax on does nothing. Any help is apprecaited!
You can use the :highlight command to list all defined groups (according to your colorscheme). A plain text file probably has no filetype and therefore no syntax assigned; you want to try this with any programming language (e.g. *.py or *.c) to see syntax highlighting in action.
Your ~/.vimrc looks fine. (Do you really need the :set term, though?!)
You should remove that useless line:
set term=builtin_ansi
Do you use the default Vim? What filetypes are you editing?

Resources