Hide invisible unicode character - vim

I don't know why but vim shows invisible unicode characters with space. Just enter this in vim and you'll see.
:tabe
:call setline(1, "\u2063hello")
There is a space after "hello". How can I hide this space? Or is there a way how I can mark text in vim with something invisible? For instance, there is a text in file
foo foo and I want to highlight first "foo". At this moment I mark first "foo" with "\u2063" character \u2063foo foo.

⁣hello
What you see depends on the terminal you're running Vim in. In GVIM (where Vim itself does the rendering), there indeed is an empty display cell at the beginning of the line. As Vim uses fixed, cell-based character addressing, this is expected. The U+2063 character is an invisible separator, but it still takes up one display cell.
Now, the terminal (I'm using Gnome Terminal) renders this character in a different way: It doesn't output anything. So Vim assumes the first cell has been occupied, and the h' of hello will be output at the second cell, but the terminal keeps the drawing cursor at the first cell, and all subsequent characters are rendered wrong. You can see the mismatch by moving around and using the ga command inside Vim.
Similar effects can be experienced with some combining characters, and other "funny" Unicode characters. I'm not sure whether the problem is with the terminal, Vim, or a mismatch in the interpretation of the terminal database.

Related

Why can't I get `< and `> to work in MacVim?

I have this line in a MacVim buffer:
abcdefghijklm
I then type fev3l<esc>, to move the cursor to e, visually select the text efgh, and go back to normal mode.
I then press `< , and expect the cursor to move to e. Instead, it moves to a. If I then press `>, the cursor moves to h. Where the cursor actually moves seems a bit arbitrary, but I haven't figured out if there is a consistent pattern.
When doing this in /usr/bin/vim on the command line, I get the expected behaviour.
Looking at :nmap, I do not have ` mapped.
What could I be doing wrong?
You should check your keyboard layout.
On a non-US layout that contains diacritics, keys that correspond to diacritic marks will behave differently. Instead of being produced right away, such keys now are meant to be used in combination with another one to produce a letter with a diacritic, which may alter their expected behavior with programs.

How can I use the commands defined in this vim tip?

I am looking for a way to use f followed by some character to jump to the next uppercase letter.
I ran across this question and want to use the accepted answer, since that did not appear to have any dependencies.
However, after I added the lines into my .vimrc, I cannot figure out how to actually jump to the next uppercase character.
I tried Ctrl-Right and Ctrl-o, and both orderings of them, but I could not jump to the next uppercase letter in the line. I also read the actual vim tip, but that also does not explain how to actually use the commands.
What is the correct sequence of commands, and in which mode, to actually jump to the next uppercase letter?
Does it have to be the find command? What about typing /[A-Z]? It'll find the next upper case character (even if it's on a different line), and it's fast to type. Pressing n will take you to the next one without retyping the command again.
What you found in the other answer was a macro command. VIM has a rich macro language that allows you to define functions. You can run a function by typing a colon and then its name.
Of course, typing :findNextCapitalCharacter is a bit long to type. You can use map to define a key macro that will basically type the letters for you to find the next command. I like prefixing my mapped macros with some character like %, so typing %c will find the next capital character.
Further Explanation
I'm currently just doing /\u, but I still want to know how to use the macro in that answer for my own learning. In the case of those macros, what is the actual means to invoke the macro command?
You're way ahead of me! I didn't know about \u being uppercase.
Looking at the answer, I see they're not defining a macro, but doing key mapping. Here's a quick intro:
In command mode (that's where you can't type in anything into your file, but where you can use commands), type in :map #$ iHello World and press return. Now, still in command mode, type #$. You'll see that VIM typed iHello World for you. The i put VIM into insert mode, so it could type in Hello World That's mapping!
In VIM, you have special map modes depending on the mode you're in. In the original VI, you had two modes: Command and Insert. In VIM, you have Command, Select, Visual, and Command-Pending modes. The different map command depend upon the mode. Type :help mapmode into VIM and press <RETURN> to see about the various map modes and their VIM commands. This will be VIM help manual sections 1.3 to 1.5. Read it thoroughly to understand what the different map command mean.
What the accepted answer is doing is entering the maps three different times, once for each mode. There are two different maps (one search to the previous and one search to the next), so six all together.
The accepted answer is mapping Cntrl-Left Arrow <C-left> and Cntrl-Right Arrow <C-Right> to each of these mappings. Much like I mapped #$ to Hello World.
Setting g:camelcase is setting a global variable called camelcase to a string. If the string is A-Z, it will be for just capital letters. If it's A-Z0-9, it's for capital letters and numbers. You should only define one instance of this variable.
I think you're problem is that you're typing in <C-Left> for the map. What you're suppose to type is ^V^-> where ^V is Ctrl-V and ^-> is Ctrl-Left Arrow. When you type that in, the map command will change those into <C-Left>.

Words containing ß in Vim

I am using gvim 7.3 on Windows to edit a German document; enc is utf8. There are words containing an "SZ", say großer. When my cursor is on g, and I press w, I expect the cursor to jump to the next word. Unfortunately vim seems to consider ß to be the border of the word and jumps to it. Anyway to tell vim it should consider ß a normal letter?
ä,ö,ü are not a problem, they are recognized correctly.
Word boundaries depend on the value of the iskeyword option. The default value on UNIX-y systems is #,48-57,_,192-255 which includes ß (#223 IIRC). Make sure you run Vim in "no compatible" mode to have the correct default value. Having a ~/.vimrc, even an empty one, should be enough.

How do I paste non-ASCII characters into vim?

My terminal emulator is configured for Unicode character encoding and my .vimrc contains the line
set encoding=utf-8
but when I try pasting the word "café" into vim, it comes out as "café".
I can make an "é" in vim by typing Ctrl-vu followed by the 4-character code point (00e9) but I'd like the ability to paste it in.
The solution was to uncheck the "Escape non-ASCII input" checkbox in the Advanced tab of the Terminal.app settings.
Instead of copying the character from the clipboard and pasting it into the text editor, you can add it to the file using vim's digraph feature.
So, with default settings, using your example, you could enter insert mode, then hit Control-k, and type e'. The result will be é.
You can see the list of defined digraphs by running
:digraphs
and general help by running
:help digraph
which also explains how to customize your mappings.
If you are truly set on pasting the characters in, Shift-Insert has always worked for me.
How to type a non ASCII code into vi
You'll have to know what your encoding is to enter the proper codes, I assume you left VI at the default.
In VI, go into insert mode, while in insert mode, press
Ctrl-v 172
That should insert the Logical Not (sideways and inverted L) character defined here:
http://www.htmlhelp.com/reference/charset/iso160-191.html
From where are you trying to paste it? If it is opera, then since opera-10.5* paste is broken in both directions. Before pasting anything you need to use xclip -o|xclip -i workaround (add -sel clip for clipboard).
What command do you use?

How to fix Home and End in Vim?

I'm using vim in gnome-terminal (2.26.0): although I use 95% of the time "$" to navigate to the EOL and "0" for the opposite, every now and then I hit "Home" or "End".
When I use Home, the text I have in the current line is moved on line down, leaving me in insert mode in the current line and the letter H appears at the beginning of the line.
When I hit End, it's the same but with an F instead of H.
Why does it happen? How can I fix it? (fixing would mean to have the standard functionality when hitting these keys).
This happens because pressing the home and end keys in a terminal sends an escape sequence consisting of several characters to vim, and vim isn't correctly associating these escape sequences back with the keys you pressed.
To fix this you need to adjust the term setting. Gnome-terminal is xterm compatible, so you could try adding this to your .vimrc:
set term=xterm-256color
The term setting is derived from the TERM environment variable, so you might want to investigate why it isn't set correctly in the first place.

Resources