1

I am copy pasting a big chunk of code from an article in PDF format. The issue is that the operation is replacing every * character (the multiply operator in Fortran) by some sort of slash character, which isn't the generic slach character in Vim (used for division in Fortran).

For example, consider the expressions:

s2 = exp(-w * t)
s3 = 1.0_wp / s2

When copy pasting, I get the following:

enter image description here

As you can see, the regular slash is highlighted in yellow while the asterisk character was changed to some other kind of slash. I could very well go over every character and replace them, but that's not very reliable and would take quite a while (few thousand lines of code...). Ideally, I'd like to change them all in the following manner:

%s/[wierd-slash]/\*/g

I've found how to search and replace unprintable characters. ga or :ascii prints the hexa/octa value of the character under the cursor (in my case hexa 2044). However, when running :%s/\%x2044/\*/g, I can the error Err: pattern not found: \%x2044.

Also, I've tried typing * when the character is under the cursor (then I could search and replace last searched character) but it searched for the next word instead. In the example above, it would search for t instead.

4

Excerpt from :help /\%x (emphasis mine):

\%x2a       Matches the character specified with up to two hexadecimal characters. \%u20AC  Matches the character specified with up to four hexadecimal characters.

So you need to use \%u2044, rather than \%x2044, which will search for <Space>44.

You can also copy-paste it to the commandline or type <C-v>u2044 in the commandline to get a literal ; you don't need to escape it with \%u to use it in the :s command (or most other commands).

Finally, I find unicode.vim a very useful plugin. Using :UnicodeName on the character gives:

'⁄' U+2044 Dec:8260 FRACTION SLASH (/f) &frasl; /\%u2044

Note how this includes the /\%u2044 ready for copy/pasting :-)

  • @ChristianBrabandt your plugin is wonderful. I cut and paste pdf abstracts all the time, which results every time in a lot of hateful unicodes, for left and right quotes. Problem evaporated! Wasn't obvious to a novice like me how to install the plugin, but this site was very helpful – Leo Simon Feb 26 '17 at 18:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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