HOME BLOG

Archive for the ‘Vim’ Category

How to search and replace unprintable character with Vim

Posted on: October 14th, 2021 by Olu No Comments

Hi folks,

In this post I talk about how to search and replace unprintable character with Vim. I once found myself in a situation where some code wouldn’t run in my file due to an unknown character. It turned out the character wasn’t visible, so I had to find a way to remove it. If you find yourself in a similar situation here’s what to do:

First try to set encoding type and see if that works.

:set encoding=utf-8

If that doesn’t work, you can place the cursor on the unprintable character and press keys ga. This will show the decimal/hexadecimal/octadecimal code for the character. You can then replace it with command:

:%s/\%xYY/yournewchar/g

Or for multibyte character use:

:%s/\%uYYYY/yournewchar/g

See the following for details

:help character-class

 

Reference

How to search and replace an unprintable character. Stackoverflow. https://stackoverflow.com/questions/2798398/how-to-search-and-replace-an-unprintable-character/2801132

How to fix issue of “’” showing on page instead of “ ‘ ” in gVim in Windows

Posted on: September 26th, 2020 by Olu No Comments

Hi folks,

Recently I experienced an issue where when I opened a file using my favourite editor gVim in Windows and found to my utter bewilderment that the “’” character was showing instead of “ ‘ ”. I’ll quickly talk about how to fix such problem.

First, what’s the cause? The cause is that the editor isn’t using UTF-8 encoding. It might be using ISO-8859-1/Windows-1252. So, to fix it, update gVim to use UTF-8. Here’s how to do that.

Open your _vimrc file and add the following lines

 

set encoding=utf-8
set fileencoding=utf-8

Save and close the file. That’s it. Your apostrophe characters should now display correctly. Happy editing.

Sources:

“’” showing on page instead of “ ‘ ”. stackoverflow. https://stackoverflow.com/questions/2477452/%C3%A2%E2%82%AC-showing-on-page-instead-of

Set encoding and fileencoding to utf-8 in Vim. stackoverflow. https://stackoverflow.com/questions/16507777/set-encoding-and-fileencoding-to-utf-8-in-vim