How to re-enable syntax highlighting in Vim? - vim

Vim language highlighting has quit working only for one specific file.
I've been using Vim in WSL (Ubuntu) for several months now without problems. My PC is Windows 10 Professional. Strangely, Vim is no longer highlighting properly when I open a particular file. Everything works fine with every other file, but if I open this one file, it does not display correctly. The language highlighting is gone. Line numbers, tabs, and end-of-file-tildes still follow the color scheme, but my actual code is simply colored white. Does anyone know how to fix this?
More details:
The file type is *.v
If I rename the file, it displays correctly.
If multiple files are open at once (i.e. split view), every other file displays fine while this one file does not.
The problem arose in the middle of a work session, and I changed nothing in the vimrc before the problem arose.
After seeing the problem, I ran apt-get update and apt-get upgrade, followed by a restart.
I tried changing the color scheme in my vimrc.
Nothing I tried worked. Any ideas or insight would be greatly appreciated. Thanks!
EDIT: This question will be moved to vim.stackexchange.com

I have one mapping to toggle syntax, maybe it will help you
nnoremap <silent> <expr> <Leader>s exists('g:syntax_on') ? ':syntax off<cr>' : ':syntax enable<cr>'

Related

Cmder cursor and highlight issues with Neovim

Currently in normal mode and the cursor is still just a | instead of the usual block
This doesn't change regardless of the mode, I have tried reinstalling both neovim and cmder and the same result happens regardless of the .vim file being used.
using the / command to search for the word "there" and it makes the word im searching for invisible with or without a stock config for both cmder and neovim
currently in visual select highlighting all of the text but the highlight on the text is clear/can't see it but it is working.
For all of these issues I have tried using a new .vim file and a stock cmder config and have reinstalled both and the issue still occurs, the issue doesn't happen when I use neovim through the command prompt or from powershell.
Note:
The highlight issue doesn't occur when using regular vim through cmder only with Neovim, however the cursor staying a | persists in regular vim as well.
Update with regular vim:
Regular vim is working properly with highlighting cursor and everything, the issue only happens with neovim now, if this doesn't get fixed then ill just switch to regular vim.
I've never used cmder before, but for iterm2, for example, there is a setting associated to this:
If you're on osx you can hit <⌘ + ,> to get to the preferences for the current application.

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.

VIm How to fix - Already at oldest change Press ENTER or type command to continue

I read all the other posts on this problem and tried them all. I am posting this since those solutions did not work for me. I am a vim beginner, so part of the problem here is not understanding all the workings of the .vimrc. Still, I need it to work in order to learn.
I added a line to open Chrome with a shortcut and ever since this I get the above message. I've since deleted the line, which never even worked, as well I've tried all the following which came from other posts, deleting each and trying them in combination.
Adding-
set shortmess=a
set cmdheight=2
Adding-
if v:version >= 703
"undo settings
set undodir=~/.vim/undofiles
set undofile
set undolevels=99999
set undolevels=10000
(Point here was to up the undo levels)
Adding- set nomore
When I enter into Vim, and then try to exit with q!, it always makes me enter the command twice. This never used to happen and must be connected to this error.
On vim 7.4, Sierra, regular terminal.
The last time I had some weird behaviour like that in Vim, I had something invalid in my ~/.viminfo file. This file keeps your Vim history: searches, commands, buffers, where you were in files you edited, etc.
My guess is that there are lines in the command line history section that are causing trouble.
To test my theory, rename your ~/.viminfo to some other name (effectively deleting it to Vim) and see if the behaviour is still there. Should that work and you don't mind losing your Vim history, just delete the file. Otherwise you can try to find the offending lines in it, but be careful to work on a differently named copy because Vim writes to this file.

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.

Vim is (seemingly) Ignoring My Configurations

I've been using vim daily at work for almost 2 years now, and I've never really had any issues except for in the last two days...
My initial problem was that vim was using 8 spaces for tabs despite my settings in .vimrc. It even refused to let me reset the tab settings from within the vim instance itself. Furthermore, this problem was only happening when editing a specific file, and only while it was named a specific thing (i.e., renaming it fixed the problem). I assumed this must be due to some kind of per-file configuration that I was unaware of, and some searching led me to another post which prompted me to try the following command:
:so ~/.vimrc
This fixed my original problem, but I still don't know what caused it. I didn't do anything that I recall, it just sort of started happening as far as I can tell.
Today I deleted a swap file and all of the sudden my syntax highlighting is gone for a single file (the same one that was affected by the original issue). Again, renaming the file fixes the problem, and it running syntax on has no effect. This time :so ~/.vimrc doesn't alleviate the problem.
Does anyone have any idea what is happening here?
Update:
Thanks to Benoit's suggestion I found out that my vim was looking at a file in ~/.vim/view for some settings. When I moved this file, the issue was resolved (and vim created a new version). I'm still not 100% sure happened, but at least now I have something to look into.
Thanks Benoit!!
Your settings are probably modified by filetype specific files.
To know when a setting has been modified:
:verbose set setting?
for example:
:verb set tabstop?
:verb set expandtab?
:verb set shiftwidth?
Also, you could find autocmds for your file type:
:autocmd *.ext
probably some autocmd sets the file type, thus triggering .vim files that modify your settings.
FWIW, I've kept my vim settings in ~/.exrc for the last half-decade or so, without trouble.

Resources