Syntax highlight not working in Janus for Vim - vim

I am using Linux Mint 13 Maya Cinnamon 64-bit. My Vim version is 7.3 and I installed the latest version of Janus.
I found that for any files with a hash "#" in its content, the syntax highlight for the file does not work. For example,
# test
print "Hello"
The 'print' has color while I am editing the file. But when I save it and open it again the whole file loses syntax highlight.
If I deleted the first line and save, the syntax highlight comes back after I open it again.
This applies to all kinds of files such as .py, .c and .h. If there is a hash "#" character in the file, syntax highlighting does not work.
I have already tried "syntax on" but nothing changes.

I don't know Janus so this answer might not be 100% useful for you, but let's see. You could try finding out where the settings have been set. Try this:
Get current settings:
:set filetype? syntax?
Check where these have been set:
:verbose set filetype? syntax?
Execute these commands when you lost your syntax highlighting:
:syntax on
:set ft=python
:verbose set ft? syn?
Here you should see which script changed your filetype after saving. Normally, vim uses heuristics to determine the correct filetype if the file extension is ambiguous. In cases where these heuristics don't work, you usually set a global variable in your vimrc to a fixed value. In your case this would be something like:
let g:filetype_py="python"

Related

Vim syntax doesn't highlight in real time

I have enabled vim syntax on (in ~/.vimrc syntax on) and it works but only on files with a code in when I view them. When I create a new file with vim and write there some code - no syntax highlight. After saving this file and reopening with vim - syntax highlight works perfect.
I am using manjaro KDE.
When you open a new file without an extension (vim mynewfile) none of vim’s filetype detection mechanisms can recognize it (they all use either extensions or first-couple-of-lines heuristics, which don’t work here).
When you enter code and reopen the file, the line-checks for filetypes work, causing the syntax to be set correctly, causing highlights to apply.
You can always set syntax=mine (though set filetype=mine is better) to set it manually.
This problem shouldnt happen when you do vim some.c or similar, because the extension will force detection based on extension rules.
Vim must know how to highlight your syntax in order to actually highlight it. One way to do this, is for Vim to check the file name and sometimes inspect the contents of the file, and set the file type. The file type is then used to highlight the syntax.
To enable detection of the file type (and load plugin and indent files), add the following to your vimrc:
filetype on plugin indent
If Vim is unable to detect the file type, and you have not yet saved your file with a known extension, you can set the file type manually, like this:
:set filetype=html
Vim will then highlight the syntax of the file as HTML syntax.
More information is available in the help pages.

How do you turn off syntax highlighting for new vim windows without a filename or file type?

After I installed the 'artesanal' theme for vim and turned syntax highlighting on, every vim window has syntax highlighting including brand new empty windows [No Name], without a name or file type. I'm wondering if any of you know how to keep syntax highlighting on for every file with an extension but have it disabled for any file without a name or file extension.
This should not happen. I don't know artesanal (and "theme" is an undefined term inside Vim; it has colorschemes, filetype plugins, and syntax scripts; I hope it's not a full Vim "distribution" like spf-13 and Janus, which lure you with a quick install and out-of-the-box settings, but you pay the price with increased complexity (you need to understand both Vim's runtime loading scheme and the arbitrary conventions of the distribution) and inflexibility (the distribution may make some things easier, but other things very difficult)).
It looks like a syntax is active even for plain files. Usually, the syntax is determined by the filetype, so check :verbose setlocal filetype? first. If this returns a value, you need to look into the detection of :help filetypes.
If this is empty, it could also be that something sets 'syntax' directly. You can check in the same way: :verbose setlocal syntax?.
Now, if that also is empty, and :syntax list doesn't show something, the highlighting could also come from :match or :call matchadd() commands; :call clearmatches() would remove this then. (And you still would need to find the source that defines those matches.)
You can check to see if a filetype has been set
if &filetype != ""
syntax enable
endif

Vim weird behaviour with backspace with empty .vimrc

I'm having a weird issue with vim on Ubuntu. I've been using it for the last few weeks, trying to learn, on Windows and it behaves differently now that I'm using it on Linux.
I noticed that while in insert mode pressing backspace will delete text just like any other editor on Windows, but on Linux the text is "deleted" yet it stays there until I press ESC or write over it.
I was trying to fix this but I'm confused as to whether this is intended behaviour or not. It happens in gvim too.
The reason of this question is this, however:
I deleted my .vimrc file to see if any of my config was at fault and it fixed it. Backspace was now back to its regular self.
But then I tried creating an empty .vimrc file and that made it go back to the delayed delete. It's empty. Why the hell?
So I have no idea what's causing this. Hope my question makes sense my English ain't the best. Thanks.
Alright so looking at :h compatible I found this:
"When a |vimrc| or |gvimrc| file is found while Vim is starting up,
this option is switched off, and all options that have not been
modified will be set to the Vim defaults. Effectively, this means
that when a |vimrc| or |gvimrc| file exists, Vim will use the Vim
defaults, otherwise it will use the Vi defaults. (Note: This doesn't
happen for the system-wide vimrc or gvimrc file, nor for a file given
with the |-u| argument). Also see |compatible-default| and
|posix-compliance|."
So if I'm getting this right, running Vim with a .vimrc file should automatically set nocompatible and running it without one should set compatible... ? Whatever the case, I tried checking with :verbose set compatible? and it always says nocompatible is on so the -N flag shouldn't do anything... Yet it fixes the issue.
Without a vimrc Vim will load /usr/share/vim/vim80/defaults.vim (depending on your vim version). In this file the bs/backspace parameter is set to 2, or actually it is indent,eol,start which is the same as 2 (see :h bs)
Now if you create an empty .vimrc, defaults.vim will not be loaded, so your bs will possibly be 0.
This behaviour is described in :h defaults.vim
So to solve your problem, just put set bs=2 in your .vimrc
Alright I fixed it.
Running vim with the -N command makes it work properly. I'm not sure why but that's what's happening.

LaTeX code was abbreviatedly displaied by Vimwiki in Vim

My GVim distribution on a Windows 8.1 machine has both vimwiki and Vim-Latex-Suite installed through Vundle.
It bothers me that the following display (on the left) will occur when I do the following:
Open a *.wiki file (thereby enter the filetype vimwiki once);
In the same GVim session, open another *.tex file.
Notice that almost all those math symbols are no longer readable on the left. The quoted code-segment was displayed correctly (on the right) when opened by itself, through a new Gvim.exe session.
For this specific case, my guess is that, Vim is incapable of:
Correctly identify and display all math symbols (e.g. subscripts are displayed as a square);
Correctly displaying math symbols in full-width. (By default, half-width is default and this is why those \phi or \int are hiding all its right part.)
The goal for this post is not to "display math symbols in Vim" correctly. It is too wild and LyX can handle it pretty well. Instead, I would like to know:
How can I stop Vimwiki from interfering the display of *.tex
documents?
Any suggestion? Thank you in advance :)
Original answer from #Sato Katsura
This is the conceal feature. It works better in gVim, provided that you use a font that has all the relevant symbols. You can disable it with:
set conceallevel=0
Further details for Vimwiki
Vimwiki has specified g:vimwiki_conceallevel=2 by default according to line 2100 of the help file. Unfortunately, this "default value" was set globally for all buffers.
Specific solution:
For ~\vimfiles\ftplugin\tex.vim, add the following to the end:
setlocal conceallevel=0
For ~\vimfiles\ftplugin\vimwiki.vim, add the following to the end:
setlocal conceallevel=2
I've had the same problem what made me research until reach this mapping:
nnoremap <Leader>c :let &cole=(&cole == 2) ? 0 : 2 <bar> echo 'conceallevel ' . &cole <CR>
It toggles between conceallevel=0 to conceallevel=2

VIM loses syntax highlighting when using split command

So I have created my own syntax highlighting file and it works well if there is only one file opened. However, if I do :split otherFile, the other buffer that gets opened does not have syntax highlighting. I have tried various things, like :syntax on etc. What can be the problem?
I am running Ubuntu 11.04, 64-bit version.
VIM version: VIM - Vi IMproved 7.3 (2010 Aug 15, compiled Mar 24 2011 07:07:34)
I have created a simple syntax highlighting file and put it in ~/.vim/plugin/syntax.vim
The last line of the syntax highlighting file is let b:current_syntax = "sth".
I haven't done any kind of wiring, like specifying the file location in .vimrc, the syntax works automatically (for one file opened).
I had this problem recently and much more generally. That is, the problem appeared for all filetypes. After debugging a bit, I discovered that the filetype was being properly recognized, but that for new splits, syntax was somehow becoming unset.
I'm still not 100% sure how this happened, but for future Google visitors, I'll write down what fixed the trouble for me: I moved set syntax = on much earlier in my .vimrc. After years of accretion, the line with set syntax = on had drifted down until it was below a number of other things. Moving it back up to (nearly) the top of the file fixed things for me. Here's what the start of my .vimrc looks like now:
" First two uncommented lines only useful if you use Tim Pope's vim-pathogen.
" https://github.com/tpope/vim-pathogen
execute pathogen#infect()
execute pathogen#helptags()
" Most general settings first
set nocompatible " Vim rather than Vi; implied by this file
syntax on " Syntax highlighting on
filetype plugin indent on " Filetype detection
" ... etc.
Syntax files belong into ~/.vim/syntax/sth.vim, not ~/.vim/plugin/syntax.vim. The latter is sourced only once on startup, that's probably why it only works for the first loaded file.
For your syntax to become active, you need to :setf sth, or insert a corresponding modeline into your files, or write a filetype detection for your syntax to automate that.
Resurrecting this, as I just observed the same behavior. The solution that I found was to add the filetype on setting to my .vimrc file. fwiw, I added it immediately after syntax on. syntax on happened to be at the top of my .vimrc file already. So, here are the first few lines of my .vimrc:
1 " Activates Syntax Highlighting
2 syntax on
3
4 " Filetype on
5 filetype on

Resources