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
Related
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
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?
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.
I would like to have a marker at column 80 in VIM, but only in file like *.cpp, *.h. but not in *.txt
For now I have this in my .vimrc
set cc=120
Cheers
Solution:
autocmd FileType cpp,c,cxx,h,hpp,python,sh setlocal cc=120
Vim doesn't directly use the file extension, it has an indirection called filetype, which is then used for syntax highlighting and specific settings.
Put your :set command (as :setlocal, so that it only affects the current buffer [1]) in a new file ~/.vim/after/ftplugin/cpp.vim. (You could also use :autocmd FileType cpp setlocal cc=120 directly in your .vimrc, but the separation is cleaner once you do a lot of that customization.)
[1] Note that 'colorcolumn' is window-local, not buffer-local, so the approach isn't perfect, but usually good enough. It can be perfected with additional BufWinEnter/Leave autocmds.
I'm looking for something to add to my .vimrc that would tell MacVim to always use Markdown syntax highlighting with TXT files.
Currently, I can do this manually with set filetype=markdown but I have to do that every time I open a file.
You can automatically set the filetype for particular file extensions using autocmd:
autocmd BufRead,BufNewFile *.txt,*.TXT set filetype=markdown
Add this line to your .vimrc.
Type :help autocmd within vim for more details; see also: :help autocmd-group. See also: :help filetype.