Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can't get syntax highlighting to work with R code in vim

This is a naive (and likely dumb) question, but I can't seem to get the R syntax highlighting to work with my Linux setup.

I've downloaded a r.vim file that has improved syntax highlighting, and it works on my Windows gvim setup. Does this r.vim file need to be in the /usr/share/vim/v70/syntax directory? Right now, I have it in my home directory and trying out source ~/r.vim in the ~/.vimrc file. However, this doesn't seem to do anything. Perhaps I'm barking up the wrong tree?

like image 734
andrewj Avatar asked Mar 17 '10 13:03

andrewj


People also ask

How do I enable syntax highlighting in vim?

After opening login.sh file in vim editor, press ESC key and type ':syntax on' to enable syntax highlighting. The file will look like the following image if syntax highlighting is on. Press ESC key and type, “syntax off” to disable syntax highlighting.

Does vim support syntax highlighting?

VIM is an alternative and advanced version of VI editor that enables Syntax highlighting feature in VI. Syntax highlighting means it can show some parts of text in another fonts and colors. VIM doesn't show whole file but have some limitations in highlighting particular keywords or text matching a pattern in a file.

How do I enable colors in vim?

You can change color schemes at anytime in vi by typing colorscheme followed by a space and the name of the color scheme. For more color schemes, you can browse this library on the vim website. You can enable or disable colors by simply typing "syntax on" or "syntax off" in vi.

How do I highlight in vim editor?

Press 1 to highlight the current visually selected text, or the current word (if nothing is selected). Highlight group hl1 is used. Press 2 for highlight hl2 , 3 for highlight hl3 , etc. Press 0 to remove all highlights from the current visually selected text, or the current word.


2 Answers

Try adding this line to the file filetype.vim. filetype.vim is generally located in the folder ~/.vim. Create the file if it doesn't exist.

au! BufNewFile,BufRead *.R,*.Rout,*.r,*.Rhistory,*.Rt,*.Rout.save,*.Rout.fail setf r

On startup, vim links all the file extensions listed above to the filetype r, which is likely used by your syntax file. Your syntax file will not define the file extension for you typically.

See this reference for more information. For syntax highlighting, this tutorial might be helpful.

like image 167
gkb0986 Avatar answered Nov 15 '22 06:11

gkb0986


Is the file type getting detected?

:set ft?

That should print out something like filetype=r in your case. If it's not set, try:

:set ft=r

Still nothing? Try:

:syntax on

I place all downloaded plugins in ~/.vim/plugins/. You shouldn't have to place any plugins in the system folders.

In your .vimrc:

filetype plugin on
syntax on
like image 22
Curt Nelson Avatar answered Nov 15 '22 04:11

Curt Nelson