How to change vim settings which each language has?

I use vim with many languages ​​(C, C ++, Java, shell, etc.). I know that vim already has predefined settings for each language, but I want to change the settings for each individual language in accordance with my personal considerations. I already have a settings .vimrc file, but I want a few more files to declare more specific settings according to the language used. What files are supposed to be called? c.vim? java.vim?

Example: in C, I want my comments to be green, and in Java, I want them to be light purple.

ALSO, I hate vim preset colorschemes. How can I create my own color scheme?

I hope this is clear and complete and makes sense.

Thanks in advance!

+4
source share
4 answers

You can use either autocmds:

autocmd FileType java colorscheme desert 

or put the commands in ~/.vim/ftplugin/java_mycolors.vim . (This is for new settings, if you want to override the data from the standard flippins by default, you put them in ~/.vim/after/ftplugin/java.vim .)

As you can see, the first approach is quick and dirty, and the latter allows modularity and many settings. Your call.


As for color change, this is a global setting; you cannot mix them at the same time; but you will only notice that when you break windows or use tabs, however, this may be good.

However, you can change the individual syntax colors. By default, comments in all languages ​​are associated with the Comment highlight group. Read the syntax file (for example, $VIMRUNTIME/syntax/java.vim ) or use the SyntaxAttr.vim plugin to determine the name of the group. Then you can override it in your .vimrc :

 :highlight javaLineComment guifg=Purple :highlight javaComment guifg=Purple 

This is tedious (depending on how much you want to configure), but more accurately and works in parallel. I would recommend this if you really don't need a completely different coloring for each type of file.

+11
source

In the ftplugin directory you should put all your language settings:

 ~/.vim/ftplugin/c.vim 
+8
source

Do you want autocmd

 :help autocmd autocmd FileType c,java map something somethingelse " Colorscheme just for PHP autocmd FileType php colorscheme desert 

By checking FileType , you can specify additional specific settings. Or, inside ~/.vim/ftplugin/ , create files for individual types:

 ~/.vim/ftplugin/java.vim ~/.vim/ftplugin/c.vim 
+5
source

Romanil gave you the correct answer , ftplugins is the way to go, but it is incomplete.

As your question is repetitive, here are some more complete other answers that I found:

+3
source

All Articles