Vim doesn't highlight syntax after using "tabe" open multiple files - vim

I just started to learn Vim, and I found it is very annoying that vim dose not highlight syntax after using tabe command to open multiple files. Any solutions for that?
Let me explain more details of this situation.
I open file A using vim
I type ":tabe file B" to open the second file.
Two files now are opened in a same vim window. However, only file A has syntax highlight, file B does not have syntax highlight. Same situation also happens in ":sp file B".

If that really happens, then you found a bug in vim! But before we jump to any conclusions, my advice is that you first try to debug your vimrc: vi.stackexchange.com/questions/2003/how-do-i-debug-my-vimrc-file
BTW, it is very annoying that every newbie vim user tries to make it behave like every other graphical editor. So another suggested read: stackoverflow.com/questions/102384/using-vims-tabs-like-buffers

Related

vim syntax highlight not working (MacOs Ventura)

I use vim as my text editor, and I want to make use of highlighted syntax. However, I cannot get it to work when I use the command “syntax on” in my ~/.vimrc file.
The strange thing is that it does the syntax is highlighted in the ~/.vimrc file itself, but not in other files.
When I use the command “syntax on” in my ~/.vimrc file, it does highlight the text in the ~/.vimrc file itself, but not in other files. If I provide other commands in the ~/.vimrc file they work: colorscheme wors, set number also works. So the ~/.vimrc file itself is actually used and works correctly, only the “syntax on” command does not work.
Anybody who can help me with this?
Thanks in advance!
I have found the issue. Beginners mistake I guess...
As mentioned the comments, in the .vimrc file syntax highlighting worked fine. In the files I made myself, I just opened a file without extension (i.e. vim testfile).
In a file without extension, the syntax highlighting does not work because vim does not know how to highlight the syntax. When I now for instance open a file vim testfile.py (with the Python extension), it works fine.
Thanks anyway for your comments!

How to add Syntax Highlighting in Vim for .ini files

I recently started using Vi Improved and being a Rainmeter Skin Specialist, when editing my .ini files I can't find a way to add syntax highlight for such files. I searched for a lot of time on stack and git and turned up to nothing. Requesting help at the latest.
TLDR; Need .ini file syntax highlighting for Vim
Vim already has syntax highlighting for *.ini files.
If your Vim is reasonably recent, say 8.0 and up, and you didn't set anything up with regards to Vim (no $HOME\_vimrc, nothing), then your *.ini files should be highlighted without any human intervention at all.
The screenshot below was taken in a test VM with a basic Vim without any setup:
If you have already customised Vim, with a $HOME\_vimrc file and/or with a $HOME\vimfiles directory, then you are in full control, which means that the automatic stuff described above is no longer done for you anymore. And being in full control of Vim pretty much requires that you learn it properly and configure it as you go.
Having EITHER of the following lines in your $HOME\_vimrc or $HOME\vimfiles\vimrc is going to give you automatic syntax highlighting for any recognised filetype:
syntax enable
syntax on

Why vi doesn't show syntax highlighting when create script

When I use vi to create a script, it doesn't show any syntax highlighting. But once I exit vi and use vi to open the script again, It will highlight the syntax.
What I want is to highlight the syntax for the first time when I create the file. So is there anything wrong with my configuration or it is the common situation?
When vim opens a file, it tries to guess the file type in order to enable syntax highlighting. When you open a new file called "myscript", vim has nothing to go on in order to guess the type.
When you write the file, the first file you write is #!/bin/sh (or similar), followed by the rest of the script. By this point, vim has already determined this is a plain text file, and does not syntax highlighting.
When you reopen the file, vim sees the first line of the file, and understands this is a shell script. It sets the type appropriately, and does syntax magic.
In order to solve, either name the file with an extension that suggests its type (an empty file called "myscript.sh" is, likely, a shell script), or manually set the type using :set filetype=sh
Personally, I find the first form ugly (why include the file type in the file name?), and the second one hard to remember. I just close and reopen the file :-)
vi usually guess the kind of syntax highlighting to use from the filename extension. If you're editing a file that doesn't yet have a name, you will need to tell it how to highlight:
:set filetype=html

How to get the value of minlines in Vim

Vim often shows wrong highlight when opening perl files contain pod paragraphs, use command
:syn sync minlines=9999
can handle this problem.I am curious about the value of minlines,so,which command will show minlines's value of current opened file? I didn't find that in vim reference manual.
I do not think there is a native command for that. I suggest you to check it out directly in syntax files. For example, about Perl, take a look at perl.vim. I am on Arch Linux and this file is available here: /usr/share/vim/vim80/syntax/perl.vim. If you go to line 435, you should see this: syn sync minlines=0.
Be aware that some syntax files define specific minlines rules. In Ruby/Java files, you should be able to call :echo ruby_minlines or :echo java_minlines respectively. This will not work with Python, PHP or JavaScript.
Finally, if you are ready to sacrifice a bit of performance for better ergonomics, you can add the following command to your .vimrc: autocmd BufEnter * :syntax sync fromstart
I use it to avoid annoying issues with syntax highlighting. It works great, but Vim will be extremely slow if you try to edit huge files...

Editing .vimrc file to make 'set ft=python' a default setting and something more

I am a new comer to the vim world, and I have just installed spf13-vim for a quick start. Apart from that I have not touched my .vimrc file.
I mainly use vim to write some python scripts on a remote server, so I have to type 'set ft=python' each time I open a file using vim. I am wondering if it's possible to edit my .vimrc file to make python a default choice of vim.
Another confusing thing is that each time I type a blank in vim, it shows a inverted question mark on my vim screen. I think it's because of some mismatch in file encoding, but I have no more idea about it.
I know it's a stupid question, but right now I can't solve it myself. Any help is appreciated.
Edit:
I have solved the problem of setting python default by write 'set ft=python' to my .vimrc file. (I didn't know contents in .vimrc are commands in vim) But I still don't know how to eliminate the inverted question mark when I typed a blank char, even after I do some search.
Name the buffer you're editing from the start, don't forget the :filetype plugin in your .vimrc and then things will work correctly.
In any way having :set ft=whatever in your .vimrc is twice wrong. First it'll apply to all new sessions opened without a file. Moreover it'll only apply to the first buffer. I.e. it won't work with :new.

Resources