A useful little feature in vi (well vim anyway)



I've had to suffer various issues with charactersets over the past few years (don't get me started) - the words 'why am i getting upside down question makes when selecting from a table strike fear into many a DBA......

I blogged previously for some general tips about getting these characters into the database succesfully - see here:working with non english characters

While looking at another one of these recently i noticed something in vi on linux ( well improved vi or 'vim') - this may also work on other unixes but I'd not got one on hand to test.

Here is a quick sample - i insert the following character into a file

123ő456ű789
123ち456とく789
ちとしはは

A random selection of some numbers, some Hungarian characters in the first line and then some Japanese characters in the other lines.

Now when you open this file (as long as everything is set up right) - you can view then just fine - what's interesting is what is happening down in the bottom right hand corner.


In the case above you can see i have the line 1, character 1 with the cursor over it - this then reports 1,1 in the bottom corner. Nothing special there you say - but wait - look what happens when i move the cursor along





So on the first Hungarian character - but still nothing changed...

But If i move one more to the right

Now the display has changed - it shows 1,6-5. So what's this telling us?




We're still on line 1 (no prizes for that one...), but the next part is quite useful - it's now added we are on the 6th byte but only the 5th character - so the character before this one was a multibyte one - in this case 2 bytes!

Lets try it with the japanese characters now





Now here things change slightly - and confusingly. The bytes part of the display seems to be correct - the Japanese characters seem to be allocated 3 bytes each - however now the 'character' value seems wrong - instead of still being sequential now each single character seems to take 2 characters.... I'm not sure if this is somehow deliberate, a bug or what but anyway the information is still quite useful i think........








Comments

Post a Comment