Why is vim syntax highlighting on different terminals? - linux

I am running a standard installation of OpenSuse 42.3. I ssh to the Opensuse machine via my MacOS computer. When I use vim to view files in the terminal window the syntax highlighting is pleasant to look at. I also have a Docker image of a stock installation of OpenSuse 42.3 installed on my OpenSuse machine. If I boot up the container and open a python file with vim within the container, the syntax highlighting looks different. I did a diff on the contents of the /usr/share/vim/vim74/syntax/python.vim, and there were no differences between the syntax file that is being used on the OpenSuse host and the OpenSuse container.
Below on the left is what I see when I ssh from my Mac to the OpenSuse machine and open a python file. On the right is what I see when I start the docker container ( still in the same terminal window that I started for the image on the left).
Shouldn't the display on the terminal window of the syntax highlighted file be the same if the vim syntax files are the same?

The highlighting in the terminal can depend on the number of available colors. Some colorschemes have separate branches of color definitions depending on how many are available. You can check for yourself via
:set t_Co?
You probably get 256 for TERM=xterm-256color and only 16 for TERM=xterm.
Though you can just force :set t_Co=256 and reload your colorscheme, it's better to fix the root cause, i.e. the wrong TERM value.

Related

Git bash, using VIM 8.1 on Windows :Term command. Node REPL not working correctly

I'm working on a corporate network (windows pc) with little access to tools like tmux, cmder etc.. however after recent update to git bash, we have access to Vim v8.1 which has a terminal built in.
I can load up vim and the type :term to load up a terminal... it works for standard terminal operations such as ls or git push etc.. but when you run node it seems to crash. And it doesn't render the node repl prompt.
Anyone know how I can get this working? (As predicted it works on the mac)... this is really useful to test out an algorithm quickly without leaving vim.
I also tried just typing !node to execute outside of vim and this has the same effect.
Any clues would be much appreciated.
Many thanks
Kevin
I figured it out...
You just type node -i for interactive (This isn't needed on the vim 8.1 on the mac)

How can I load my emacs configuration when I'm in -nw mode (opening emacs in terminal)

Well like the question says, my problem refers when I start emacs on terminal (in Linux).
My packages appears but my configuration (init.el file) it's not loaded.
My keybindings are not working, and yes, I searched about and only I can think is that I need have other specific file for run in terminal.
Any help?

vim - _vimrc file on Windows 8 not working

I found this question but it didn't help. The solution in this is what I tried but it didn't work.
I am trying to create an _vimrc file on my Windows 8 computer so that the syntax of my code in vim is 1) highlighted by default and 2) maintains indents.
I entered
echo %UserProfile%
into the command prompt and it gave me C:\Users\Username.
I used vim to create a _vimrc file in C:\Users\Username and added
set autoindent
syntax on
to it. However, these changes do not register in vim.
Most questions I could find online are for Unix where the home directory is ~. The questions that did apply to Windows said to create the file in the C:\Users\Username directory which is what I'm doing.
I tried closing and reopening my command prompt but it didn't help.
Sorry if this is a really simple question; I don't use user variables that often.
The presence of /usr/share/vim/vimrc in the output of :scriptnames indicates that you are using a version of Vim provided by some unix-like compatibility layer like cygwin instead of a regular Windows build.
From the user's perspective, the cygwin environment is completely segregated from the Windows environment and you are expected to use/customize it like you would on an actual unix-like system. Mixing Windows and "Linux" (huge quotes, here) concerns is not a very good idea in such a context.
In Vim, :echo $HOME should tell you what your $HOME is from Vim's POV.
If you are indeed using cygwin, cygwin's $HOME is usually located here from Windows' POV:
C\cygwin\home\username
while Windows' $HOME is usually located here from cygwin's POV:
/cygdrive/c/Users/username
In short…
if your Vim is a regular Windows program, the standard location for your config is:
C\Users\username\_vimrc
C\Users\username\vimfiles\
You can use both the console and the explorer to deal with those files and directories.
if your Vim is provided by cygwin, the standard location for your config is:
/home/username/.vimrc
/home/username/.vim/
You are pretty much forced to use the "Cygwin Terminal" to deal with those files and directories unless you get how those are mapped to Windows paths.
Avoid thinking in Windows terms.
I ran into a similar problem on Windows 7 and 10. VIM's installer created a default vimrc file in the installation directory (in my case c:\Program Files (x86)\Vim).
After deleting this file, VIM looks in my home directory.

Vim Syntax Highlighting does not work

I've installed a fresh Arch Linux system on my laptop and downloaded the vim package.
I haven't altered the .vimrc file, but the syntax highlighting doesn't seem to work with any of the languages I tried (Python, Ruby, CSharp, C...).
Auto formatting (gg, =, G) also fails.
Until now when playing with vim (because I can't really say I've extensively used it) in other OSs (Ubuntu, Fedora), the syntax highlighting came on automatically.
Is there something I am missing here?
You need to have following settings in .vimrc file as per arch linux documentation
filetype plugin on
syntax on
This is the absolute minimum you need to put in your ~/.vimrc if you intend to use vim as your primary editor:
" activates filetype detection
filetype plugin indent on
" activates syntax highlighting among other things
syntax on
" allows you to deal with multiple unsaved
" buffers simultaneously without resorting
" to misusing tabs
set hidden
" just hit backspace without this one and
" see for yourself
set backspace=indent,eol,start
Anything else depends on your taste, workflow and needs.
vi /etc/profile
alias vi=vim
maybe you use vi instead of vim
I had this problem in Opensuse Leap 42.2 cloud. And solved it by installing vim-data
sudo zypper install vim-data
or just re-installing vim will include vim-data automatically.
sudo zypper remove vim
sudo zypper install vim
Type
:syntax on
to get it to work. It is not a default option for vim. Probably in the other systems, it was set to on in the system default vimrc
Or put
syntax on
in ~/.vimrc
Another reason syntax highlighting won't work is you might have a theme/colorscheme set that VIM cannot find.
colorscheme darkblue
Either delete the line or comment it out:
"colorscheme darkblue
I had a similar problem. I could not have syntax highlighting on. I also found that gvim launched without pulldown menus or toolbar icons. It turned out I did not have the vim-runtime package properly installed. In my case I was on debian jessie with a large set of files missing under /usr/share/vim/vim74/ directory.
$ ls /usr/share/vim/vim74/
debian.vim doc/ rgb.txt
The solution was to run:
$ sudo aptitude reinstall vim-runtime
That fixed the problem for me, for syntax highlighting and for missing menus/icons in gvim. I'm not sure why my system was in this state, but the reinstall of the above package solved both issues.
in my case , I changed the term(terminal type) from vt100 to xterm. And it works.
To change the terminal type:
in bash:
export TERM=xterm
in bourne shell or ksh:
TERM=xterm
export TERM
in csh or tcsh:
setenv TERM xterm
On my Ubuntu 18.04 system i.e. c-highlighting works but Icinga2 config file highlighting being provided by the vim-icinga2 package does not. Quote from https://packages.debian.org/sid/vim-icinga2:
As per the Debian vim policy, installed addons are not activated automatically, but the "vim-addon-manager" tool can be used for this purpose.
Executing vim-addon-manager -w install icinga2 following a regular vim-icinga2 package installation solved the issue. The -w option forces a system wide rather than a just per current user activation. Notice that executing vim-addon-manager without arguments yields a list of 39 modes being disabled by default:
> vim-addon-manager
# Name User Status System Status
align removed removed
alternate removed removed
...
icinga2 removed installed # Due to above command
...
If you do miss highlighting chances are your mode is among this list.
NB: Ubuntu 18.04 seemingly inherits Debian's policy. None of the above answers solved my issue. No ~/.vimrc configuration or manual activation was being required after the above described activation.

Vim at Ubuntu 11.04: Working with clipboard of Unity

The problem is, the old-way method to work with X11 clipboard (through "plus" register) doesn't work in Unity. Has anyone met the problem? And how it was solved?
The problem solves itself after GVim installation. Then "plus" register works as it should be.
Even if you do not have gvim installed or xterm_clipboard enabled, you may use xsel to manage your clipboard (install it via apt-get).
I hope my script will help you: https://github.com/FUT/config-files/blob/master/vim-dotfiles/vim/settings/clipboard.vim
Use :
sudo apt-get install vim-gtk
This will install vim with clipboard support.Run as before: vim
I don't know the unity desktop but I know that it is based on gnome libraries. So if you can use dbus to interact with unitys clipboard, you may consider writing a shell script which uses dbus to set the clipboard content. This script can in turn receive its input from vim if you assign a map to a filter command. Of course this works similarly if you know any other commandline utility which can set the clipboard content.
I used to have the following maps in .vimrc for the old dcop and klipper (the KDE clipboard) which you might customize:
:vmap k :w! $HOME/.vimclip<CR>:silent execute "!dcop klipper klipper setClipboardContents \"$(cat $HOME/.vimclip)\" &>/dev/null &"<CR>:redraw!<CR>
:nmap z :silent execute "!dcop klipper klipper getClipboardContents > $HOME/.vimclip"<CR>:r $HOME/.vimclip<CR>:redraw!<CR>
E.g. to copy press k after making a selection in visual mode. Note, that it copies and pasts line wise.
I have faced the problem again after while. Must say I use vim in GNOME Terminal, not GVim that is also installed.
What is interesting the plus register stopped working approximately at the same time on different computers of mine.
First I though it was a bug because the graphical version was installed as before. But at the end I just started GVim and tested the plus register there. It was working. After that the register began working in the terminal too.
So if you meet the problem again, when you have already installed GVim, just start it. This should help.

Resources