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?
Related
I created a dedicated syntax file
.vim/syntax/foo.vim
and I would like to apply this syntax file for all files having the coresponding ending "myfile.foo"
For doing this, I added the following line in the .vimrc
au BufNewFile,BufRead *.foo setf foo
this is perfectly working, but...
If the text inside the file is starting with a "#", a different filetype is applied:
filetype=conf
I can override this by using :set filetype=foo to get my desired type.
It is a bit annoying and I don't know how can I overcome this workaround.
Do not put anything to your vimrc!
Insert your command into ~/.vim/ftdetect/foo.vim instead.
The point is that your command must get into filetypedetect auto-group, otherwise any subsequent :filetype detect will overwrite your filetype to the defaults.
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
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.
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 noticed that with different colorschemes VIM is underlining/highlighting some words. Why is this and how to turn it off ?
with another colorscheme
I'm using spf13-vim configuration and connecting remotely with Putty.
VIM is correctly assuming this file to be a python file (:set filetype returns "python")
It seems like your Vim is doing spell-checking for you. You can turn this off by adding
set nospell
in your .vimrc file. To turn it back on in a file, you can do:
:setlocal spell spelllang=en_us
for spell-checking with American English. :setlocal changes settings for current buffer, while :set makes the changes for all currently open buffers. You can read more about how spell-checking with Vim works here.
It may be useful for you to automatically enable spell checking for certain files. For example, to enable spell checking in .tex files, you can add the following to your .vimrc:
" Enable spell checking when opening .tex files
autocmd!
au BufNewFile,BufRead *.tex setlocal spell spelllang=en_us
" Or if you have filetype detection enabled:
" au FileType tex setlocal spell spelllang=en_us
Note that autocmd! clears the previously defined au commands and is needed only once.
Most filetypes (like python) in Vim come with a syntax that defines highlight groups (see them via :highlight). A colorscheme then provides combinations of foreground / background color and/or formatting like bold and italic, for terminals, color terminals, and/or GVIM.
Choose a colorscheme that you find visually appealing; some come with Vim, many more can be found on the Internet, most at http://www.vim.org/.
If you're just annoyed by one or two minor things in a particular colorscheme, you can modify the items via the :highlight command. To disable a highlighting, use, e.g.
:highlight clear Statement
or (when the group is linked to another group, effectively inheriting its appearance)
:highlight link Statement NONE
(These must be issued after the :colorscheme command that sets your preference.)
I have came across two kinds of highlight that I don't like.
1.indent highlight and tab arrow reminder, you can solve it by adding
let g:indent_guides_enable_on_vim_startup = 0
set nolist
to ~/.vimrc.local
2.highlight the usual words, like Chinese words and wrong spell words, you can solve it by adding
set nospell
to ~/.vimrc.local