Why does different char-width occur in Vim and Nvim? - vim

Why does different char-width occur in Vim and Nvim ? And how to make it same?
Like the following graph. In Vim, the char is double-width, but in Nvim it is single-width.
12345
│││
│││
│x
You can copy the words and test.

I found the reason is 'ambiwidth' option.
set ambiwidth=double make it difference behavior.
set ambiwidth=single display one-width normally.

Related

Adding timestamp in vim, in config file

I have added the following line to my vim config file:
inoremap <leader>dt r! date "+\%Y-\%m-\%d<CR>
In order to add a shortcut for printing the current date. But when I use the shortcut in normal mode it only prints the string: "r! date "+%Y-%m-%d".
Why is that? What am I doing wrong?
But when I use the shortcut in normal mode it only prints the string: "r! date "+%Y-%m-%d".
You are doing that in insert mode, not "normal mode".
Why is that?
Vim is doing exactly what you ask it to do, which is to insert the string r! date "+\%Y-\%m-\%d<CR> when you press <leader>dt in insert mode.
What am I doing wrong?
The most salient item in the list would be that you didn't explain what, exactly, you are trying to achieve, asking instead for a fix to your flawed solution. This is known as the XY problem and a very common trap to fall into. In fact, since you appear to be surprised by Vim doing exactly what you ask it to do, it is possible that you are not sure about it yourself. Can you clarify this, please?

Vimdiff - How to hide all same lines in both files and show only different ones

vimdiff file1 file2
besides differences shows also same lines from both files. Is it possible to hide them? How to do it?
As Vim is a text editor (not a specialized diff viewer), the full contents of both files are kept (so you can do edits and persist them). Vim usually just "hides" multiple identical lines by folding them away; they are still present, just not visible.
You can influence how many identical lines are kept around changes (default: 6 lines above and below) via the context value of the 'diffopt' option. So, to completely fold all identical lines:
:set diffopt+=context:0
It is still showing common lines if common line is going in sequence with different. one after another
The solution suggested by Ingo Karkat worked perfectly in Linux. Thanks for sharing it. However, it's not working on Mac.

Describe vim replacements

In almost every copy of vim that I have used, the program will give a description of changes after replacing text. (For example, something like "92 substitutions on 20 lines" would be displayed.)
I'm now working with a copy of vim that does not do that by default.
Is there a simple command (or addition I can make to my vimrc file) that will enable this behavior?
It's governed by option report.
You can see you current setting with
set report?
To report even the minimal change
set report=0
I think you experience the effects of the 'report' option. If the (substitution, or any other command's) changes cover more than those (default 2), you'll see the message, else nothing.
So, you can put the following into your ~/.vimrc to always see those messages:
set report=0
Although not exactly your question,
in vim's substitutions, you can use the "n" flag to count the number of
matches and lines (without real substitutions).
Example
:%s/a//gn
55311 matches on 17459 lines

Use Vim to "colourize" files or input streams

This may be an odd question, but still. I use cat to display a file in bash (KDE Konsole),
cat foobar.rb
Now, I would like to use Vim to colourize that foobar.rb file according to what you would get when you start foobar.rb in Vim. Edit: But only for display purpose, on the terminal.
I am not sure this is possible, but I thought it would be neat if I could use Vim for that.
I really just want colourized keywords, and Vim has the perfect colour definitions.
So I thought combining this would be great.
Is this possible in Vim out of the box though?
One approach would be to use a library such as Pygments, which is a general purpose syntax highlighter. You could write a wrapper called ccat or something that would apply syntax highlighting to an input file and write to stdout.
If you want to page up and down in a highlighted file, you can use less with the -R switch, which passes control characters through to the terminal directly, preserving colours. So:
ccat file.rb | less -R
But at that point, you're pretty much at the capabilities of view.
I'm not sure if I understand your question correctly, but if you are only looking for a command that will give you a read-only view of the input file (like cat) but with coloured keywords, use view. view is an alternative way to start vim in read-only mode, so you have all syntax highlighting possibilities. From the vim man page:
view Start in read-only mode. You will be protected from writing
the files. Can also be done with the "-R" argument.
gvim gview
The GUI version. Starts a new window. Can also be done with
the "-g" argument.
evim eview
The GUI version in easy mode. Starts a new window. Can also
be done with the "-y" argument.
rvim rview rgvim rgview
Like the above, but with restrictions. It will not be possi-
ble to start shell commands, or suspend Vim. Can also be
done with the "-Z" argument.
I have always seen view on systems that have vim installed.
Closest is the less script that comes with vim:
cat myfile | vim -u /usr/share/vim/vim72/macros/less.vim -
Note the - argument to vim. You may need to change the vim72 to your version (and the whole path if you have it installed elsewhere)
Now, this isn't exactly what you want, because its behaviour is less-like, in that you have to press keys to make it scroll down or complete. However, they are briefer than usual vim. For example, space to scroll down; and q to quit (not :q).
You want a cat-like version; me too. But there doesn't seem to be one.
EDIT uh, there's also a vimpager project, that includes vimcat - exactly what you want. But it doesn't come with vim, and I haven't tried it yet.
vim.org: http://www.vim.org/scripts/script.php?script_id=1723
github: https://github.com/rkitover/vimpager

changing vim's vertsplit character to │

This is, I assume, codepage related, but doesn't hurt asking.
How would one, on windows xp's cmd, gvim 7.2 change vertsplit character, so that instead of default | it is │ (so that it makes a full, and not an splitted line) ?
That character is usually changed with
set fillchars=vert:\|
and I can copy paste the ascii graphics line there, but it comes out as garbage. I suppose I would have to change vim's internal codepage for it to show correctly ?
Anyone knows how to do this ?
Ok, I'm really late to the party but this is what I do.
The way the characters are rendered depends on the font so you can get a continuous line using some fonts and not with others. I've found that using one of the following gives me an unbroken line.
Menlo
Monaco
Inconsolata
DejaVu Sans Mono
Consolas
Bitstream Vera Sans Mono
As far as settings go, the following is sufficient. Note that this is different from the | character commonly present on keyboards.
set fillchars=vert:\│
I've tried the following :
set enc=utf-8
set fillchars=vert:\│
And it worked, but the result weren't has good as you can hope, it's still not a full line (using the Consolas font, if you get a straight line with another font, I'd be interested to know which one).
This isn't exactly what you want, but I've set fillchars=\ and just use highlighting to color the blank space a different color. It's less elegant, but it looks fine to me.
Digging through the digraph table, I found that the "Box drawings light vertical" is perfect for this purpose. Vim's digraph table entry:
│ vv 2502 9474 BOX DRAWINGS LIGHT VERTICAL
To use it, press <c-k>vv in insert or command mode to get the character (see :h i_CTRL-K).
As pointed out by others, the setting is applied with set fillchars=vert:|

Resources