Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

while using vim over ssh I copied some content from a webpage to my ssh/vim session and got the following result

SIZE=`df -h|grep $DISC|awk <91>{print $2}<92>`

apparently <91> and <92> stand for ' but how can I search and replace this stuff and what does 91/92 mean, how is this encoded?

Because 91/92 in ASCII mean \ and [

Thanks for any help

share|improve this question

4 Answers 4

up vote 9 down vote accepted

The content on your source web page was overzealously reformatted. The text was undoubtedly supposed to use (straight) single quotes (ASCII 39/0x27, U+0027) instead of curly single quotes (U+2018 and U+2019, which are 0x91 and 0x92 in CP1252 (also known as MS-ANSI and WINDOWS-1252; a common 8-bit encoding on Windows)).

Vim is showing you the hex codes because they are not valid in whatever encoding Vim is using (probably UTF-8). If you are editing text that has already been saved in a file, then you can reload the file as CP1252 with :e ++enc=cp1252; this should make the curly quotes visible. But there is no real reason to reload it as CP1252, just delete the 0x91 and 0x92 characters and replace them with single quotes.

share|improve this answer
    
You often get the curly quotes/apostrophe from content copied from MS Word which auto inserts the curly quotes/apostrophe as part of the "Smart Quotes" feature. If your font does not support those characters, you will just get an empty space instead of the character. –  lambacck Dec 21 '10 at 15:31
    
+1 for :e ++enc=cp1252 –  wfaulk Nov 30 '12 at 2:27

91 and 92 are the hex codes for open and close curly apostrophe (single quote) in the MS Windows default version of the latin1/ISO-8859-1 encoding, which is more specifically called cp1252/Windows-1252 (where cp stands for code page).

These characters are most often inserted by people copying content from Word documents / Outlook emails as part of the "Smart Quotes" feature. Other problem characters in this code page are hex 93/94 which are open and close double quotes, bullet point (•) and OE ligature (œ and Œ). You can see a full list of the "problem characters", the ones that don't map directly into ISO-8859-1 or UTF-8 with the same code, on the Wikipeda page for cp1252 highlighted in green.

If all you want is to open the file in the correct encoding then use the ++enc=cp1252 option to the :e command:

:e ++enc=1252 filename.txt

You can replace a particular bad hex code in Vim with the substitute command (:s) and one of the code substitutions:

    \d123   decimal number of character
    \o40    octal number of character up to 0377
    \x20    hexadecimal number of character up to 0xff
    \u20AC  hex. number of multibyte character up to 0xffff
    \U1234  hex. number of multibyte character up to 0xffffffff

To change the hex 91/92 characters in you need to do:

:%s/[\x91\x92]/'/g
share|improve this answer
    
It would be great to have a bash command to replace those characters in all files in the directory. I came up with this from a quick google search, sed -i "s/[\x91\x92]/\'/g" *.txt but it didn't work. –  Buttle Butkus Mar 13 '13 at 7:39
    
I just found something that seemed to work for the command line. This does find/replace for all .txt files in the current folder. Reasearch perl before using this, though, because I have no idea what the switches do. perl -p -i -e "s/[\x91\x92]/'/g" *.txt –  Buttle Butkus Mar 13 '13 at 7:48

They actually stand for hex 91 and 92, which in the Windows codepage are curly opening and closing single quotes (‘ and ’ - Alt-0145 and Alt-0146).

Try the following search/replace:

:s%/\<9[12]\>/'/g
share|improve this answer
    
I can't downvote due to lack of points, but this substitution command is so wrong I don't know where to begin :( –  lambacck Dec 21 '10 at 15:48
    
This doesn't work for me: stackoverflow.com/questions/2798398/… gives a solution that does work. –  Confusion Mar 2 '11 at 7:32
    
@lambacck: I was assuming that the file contains the literal strings "91" and "92", and in that case this command is correct. If these are hex characters, then you're right, you'd need your substitution command or something similar. –  Alex Mar 2 '11 at 14:43

Use iconv to convert the text file from CP1252 to UTF-8 before opening.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.