Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

on my ubuntu server vim got no syntax highlighting when i open files (configurations, scipts...).

i have tried with

:syntax on
:syntax enable

and it ways in vim that its enabled, but it doesnt work

someone knows how to fix it?

thanks!

share|improve this question
    
Are you sure you have you got vim installed rather than vim-tiny? –  kaerast Apr 4 '10 at 11:19
    
dont know actually. i made a "aptitude install vim". and the vim is pointing /usr/bin/vim.basic. is that the same as tiny version? if so, how do i install the full vim? –  ajsie Apr 4 '10 at 11:35
    
FWIW, on my system vim.basic does syntax highlighting. –  Dennis Williamson Apr 4 '10 at 12:57

4 Answers 4

up vote 1 down vote accepted

vim detects filetype by extension.
If you want syntax highlighting for extensionless file then do this after opening the file.

:set ft=sh

assuming the file is a bash script. ft stands for filetype. Similarly you can get syntax highlighting for other files by setting filetype to xml,html,php,python accordingly. If you need more info on this,

:help ft

Hope this helps.

edit:For retaining filetypes.
This is only a temporary solution.

if &filetype == ""
    set viewoptions=options
    autocmd BufWinLeave * mkview
    autocmd BufWinEnter * loadview
endif

Add this to your vimrc file. This code stores the filetype and other local options set for the file when vim exits. You need to set the filetype only once.
The stored options are lost when the file is renamed. You'll have to set filetype once again to store it.
For more info on this, read vim manual for the commands.

:help mkview
:help loadview
:help viewoptions
share|improve this answer
    
yes it helped! thanks! could you tell vim to open a file with this command? so you dont have to manually type this to all files you opened? –  ajsie Apr 10 '10 at 19:23

Do you have at least an empty .vimrc in HOME?

AFAIK, if that file is missing, vim will start in vi-compatible mode. That might be a reason for missing syntax highlighting.

share|improve this answer
    
how does it know which syntax file to use? i have tried "vim file.php" and "vim file.html" and it highlights using the right syntax file. but what if i want to highlight a script file and just type "vim file". then nothing is highlighted while im typing script commands. how can i highlight bash scripts (for loops, if statements etc)? –  ajsie Apr 5 '10 at 2:53
    
Type :h filetype in vim, this shall provide you insights about how vim manages to use proper highlight. –  geek Apr 7 '10 at 6:18

Adding as a comment to your comment;

how does it know which syntax file to use? i have tried "vim file.php" and "vim file.html" and it highlights using the right syntax file. but what if i want to highlight a script file and just type "vim file". then nothing is highlighted while im typing script commands. how can i highlight bash scripts (for loops, if statements etc)? – ajsie 6 hours ago

The shebang at the beginning of the file indicates for vim what kind of a script it is. IIRC, sometimes you have to save the file and then reopen it before syntax highlighting turns on, as well.

share|improve this answer

Since it's a server configuration, the problem is likely that you don't have the vim-common package installed. Try that and see if it works.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.