Vim. Can't yank non-eng chars to system clipboard - vim

When I yank russian characters, say тест, to system clipboard ("+y) and then paste it in a shell or a browser I get this —Ç–µ—Å—Ç. How to fix this?
Vim
:set encoding?
encoding=utf-8
:set fileencoding
fileencoding=utf-8
Shell
echo $LC_CTYPE
UTF-8

I had the same issue and fixed it by adding lang en_US.UTF-8 to my ~/.config/nvim/init.vim (using Neovim). You could try adding that to your ~/.vimrc.
Source: https://github.com/neovim/neovim/issues/5683#issuecomment-420833679

Setting correct locale for a shell with these lines added to .zshenv solves the issue.
set -a
LC_CTYPE=en_US.UTF-8
LC_ALL=en_US.UTF-8
set +a

Related

Pasting copied text to vim encoding issue

I copy some russian text from browser to vim then in insert mode pasting it via CTRL-R + * and getting a whole bunch of unreadable characters. I tried to set some fileencoding encoding and termencoding to utf-8 but that did not work.
My OS is Ubuntu 12.04
I use standard bash terminal
The problem appears only in non-gui vim version.
these are my .vimrc settings:
set termencoding=utf-8
set encoding=utf-8
set fileencoding=utf-8

Vim doesn't support unicode?

I'm trying to get the following into my .vimrc
" Use the same symbols as TextMate for tabstops and EOLs
set listchars=tab:▸\ ,eol:¬
Those lines are from here are worked perfectly in vim 7.2
I recently compiled and installed vim 7.3 and now those characters aren't understood by vim.
Also: Ctrl+V then U in insert doesn't let me insert any characters, it just seems to ignore that.
Any ideas?
This is what I see:
set listchars=tab:�~V�\ ,eol:¬
You need to compile vim with multi-byte support.
The easiest way to do this is to run
./configure --with-features=big
make
This will build vim with the correct support.
You can verify that it was compiled correctly with
:version
in vim or by running
vim --version
and looking for +multi_byte. If it says -multi_byte it will not work.
I have the following in my .vimrc
scriptencoding utf-8
set encoding=utf-8
and that in my .gvimrc
set listchars=trail:·,precedes:«,extends:»,eol:↲,tab:▸\
and works fine(notice there is a space after the ▸\ ).
I had the same issue with the vim that ships with OS X Lion although it was compiled with multi_byte.
The issue was the encoding used by vim. I added set encoding=utf-8 in my ~/.vimrc and the issue was solved.
Ref: Terminal Vim redraw issues in OS X Lion
Make sure you're using a compatible font. My problem was that inconsolata-g does not support the utf-8 characters in my document.
also, this was all I needed in my gvimrc:
set enc=utf-8
set fileencoding=utf-8
set fileencodings=ucs-bom,utf8,prc
set guifont=Monaco:h14
set guifontwide=NSimsun:h14
I had this issue while being in a screen session.
It's gone with setting the following in my .bashrc:
export LANG=en_US.UTF-8
Don't forget, if you're running vim in a terminal, make sure the terminal itself is using utf-8 as well.
When all else failed, telling vim to save with UTF-8 encoding seemed to work (for now at least):
:write ++enc=utf-8
Do you need a
scriptencoding utf-8
or whatever encoding your .vimrc is actually in?
The accepted answer didn't work for me. Working off of the downloaded source on a Mac running Lion, I went into the src directory and ran:
make clean
export CONF_OPT_MULTIBYTE='--enable-multibyte'
make reconfig
Running: ./vim --version to check for +muti_byte then:
make install
Via: http://vim.1045645.n5.nabble.com/compiling-vim7-1-huge-version-gets-build-with-normal-version-td1162314.html

How to set default vim colorscheme

The latest upgrade of Ubuntu made my vim colorscheme unusable. I know how to set it manually (:colo evening, for example), but I want to set the default for all vim sessions. I see reference in other places to .vimrc, but the right location and syntax have eluded me thus far.
Put a colorscheme directive in your .vimrc file, for example:
colorscheme morning
See here: http://vim.wikia.com/wiki/Change_the_color_scheme
Your .vimrc file goes in your $HOME directory. In *nix, cd ~; vim .vimrc. The commands in the .vimrc are the same as you type in ex-mode in vim, only without the leading colon, so colo evening would suffice. Comments in the .vimrc are indicated with a leading double-quote.
To see an example vimrc, open $VIMRUNTIME/vimrc_example.vim from within vim
:e $VIMRUNTIME/vimrc_example.vim
It's as simple as adding a line to your ~/.vimrc:
colorscheme color_scheme_name
You can try too to put this into your ~/.vimrc file:
colorscheme Solarized
What was asked for was to set:
the 'default', not some other color profile, and
'for all vim sessions', not simply for the current user.
The default colorscheme, "for all vim sessions", is not set simply by adding a line to your ~/.vimrc, as all of the other answers here say, nor is the default set without the word 'default' being there.
So all of the other answers here, so far, get both of these wrong. (lol, how did that happen?)
The correct answer is:
Add a line to your system vim setup file in /etc/vim/ that says
colorscheme default
or using the abbreviation
colo default
but not capitalized as
colo Default
(I suggest using the full, un-abbreviated term 'colorscheme', so that when you look at this years later you'll be able to more easily figure out what that darn thing does. I would also put a comment above it like "Use default colors for vim".)
To append that correctly, first look at your /etc/vim/vimrc file.
At the bottom of mine, I see these lines which include /etc/vim/vimrc.local:
" Source a global configuration file if available
if filereadable("/etc/vim/vimrc.local")
source /etc/vim/vimrc.local
endif
So you can append this line to either of these two files.
I think the best solution is to append your line to /etc/vim/vimrc.local like this:
colorscheme default
You can easily do that in bash with this line:
$ echo -e "\"Use default colors for vim:\ncolorscheme default" \
| sudo tee -a /etc/vim/vimrc.local
#
# NOTE: This doesn't work:
#
# $ sudo echo 'colorscheme default' >> /etc/vim/vimrc.local
#
# It's the same general idea, and simpler, but because sudo doesn't
# know how to handle pipes, it fails with a `Permission denied` error.
Also check that you have permission to globally read this file:
sudo chmod 644 /etc/vim/vimrc.local
With $ tail /etc/vim/vimrc.local you should now see these lines:
"Use default colors for vim:
colorscheme default
You can just use the one-liner
echo colorscheme koehler >> ~/.vimrc
and replace koehler with any other available colorscheme. Imho, all of them are better than default.
Once you’ve decided to change vim color scheme that you like, you’ll need to configure vim configuration file ~/.vimrc.
For e.g. to use the elflord color scheme just add these lines to your ~/.vimrc file:
colo elflord
For other names of color schemes you can look in /usr/share/vim/vimNN/colors
where NN - version of VIM.
Ubuntu 17.10 default doesn't have the ~/.vimrc file, we need create it and put the setting colorscheme color_scheme_name in it.
By the way, colorscheme desert is good scheme to choose.
Copy downloaded color schemes to ~/.vim/colors/Your_Color_Scheme.
Then write
colo Your_Color_Scheme
or
colorscheme Your_Color_Scheme
into your ~/.vimrc.
See this link for holokai
OS: Redhat enterprise edition
colo schema_name works fine if you are facing problems with colorscheme.

Where should I look when my .vimrc is overridden

I wrote
set tw=0
into my .vimrc file.
But when I verify options with
:set
it's still
textwidth=78
Why ?
You can use :
:verbose set tw?
Which should tell you where it was last setted, for example :
textwidth=80
Last set from ~/.vimrc
Why don't you just grep through your .vim directory for it?
If you have modelines enabled, vim will read the last few lines of the file for vim settings, so check that as well.

How can I change a file's encoding with vim?

I'm used to using vim to modify a file's line endings:
$ file file
file: ASCII text, with CRLF line terminators
$ vim file
:set ff=mac
:wq
$ file file
file: ASCII text, with CR line terminators
Is it possible to use a similar process to change a file's unicode encoding? I'm trying the following, which doesn't work:
$ file file.xml
file.xml: Unicode text, UTF-16, little-endian
$ vim file
:set encoding=utf-8
:wq
$ file file.xml
file.xml: Unicode text, UTF-16, little-endian
I saw someone say that he could "set fileencoding=utf-8, then update and write the file, and it works," but I seem to be missing something, or else he was confused. I don't know what he meant by "then update."
From the doc:
:write ++enc=utf-8 russian.txt
So you should be able to change the encoding as part of the write command.
Notice that there is a difference between
set encoding
and
set fileencoding
In the first case, you'll change the output encoding that is shown in the terminal. In the second case, you'll change the output encoding of the file that is written.
While using vim to do it is perfectly possible, why don't you simply use iconv? I mean - loading text editor just to do encoding conversion seems like using too big hammer for too small nail.
Just:
iconv -f utf-16 -t utf-8 file.xml > file.utf8.xml
And you're done.
Just like your steps, setting fileencoding should work. However, I'd like to add one "set bomb" to help editor consider the file as UTF8.
$ vim file
:set bomb
:set fileencoding=utf-8
:wq
It could be useful to change the encoding just on the command line before the file is read:
rem On MicroSoft Windows
vim --cmd "set encoding=utf-8" file.ext
# In *nix shell
vim --cmd 'set encoding=utf-8' file.ext
See starting, --cmd.
auto GUIEnter * set encoding=utf-8
should help

Resources