Categories: Web and IT News

Inspect Character Under Cursor in Vim

From time to time, you may come across the need to inspect the character under the cursor in Vim. For example, VimTricks reader Scott wrote in asking for help changing smart quotes in a file to regular quotes. Smart quotes or “curly quotes” are the special characters used by modern prose editors in place of regular double and single quotation marks. They are stylized differently for the beginning and end of the quote:

“these quotes are smart” and ‘so are these’ but 'these' and "these" are not

Scott’s case was one that many of us encounter: needing to replace these quotes with the traditional versions in some code or text file. Clearly, this is a case for Vim’s s substitution command. Something like this would work:

:s/[“”]/"/g

But how would we insert these characters into the regex? What if we can’t just copy paste them? How can we investigate strange or unfamiliar characters that we come across in our Vim buffer? As usual, Vim has a way:

  • ga – Show details about the character under the cursor
  • :as – Command mode version of the same

If we position our cursor over top of one of the smart quotes and press ga, Vim will provide detailed information about the character under the cursor. Included is the hex code for the character, exactly what we’ll need to be able to enter it into our substitution command:

<“> 8220, Hex 201c, Oct 20034, Digr "6

We can see that the opening quote has a hex code of 201c. Repeating on the closing quote we get 201d and now we have what we need to create our regex. To do this, we’d enter :s/[ to start our replacement and then press to enter the hex code followed by u and the code, 201c. Then u201d to enter the closing quote. Lastly the rest of the substitution command: /"/g.

I’ve put this whole workflow together into a brief screencast below.

Extending Vim’s Character Inspect

For even more advanced functionality, check out Tim Pope’s incredibly useful plugin called Characterize. It adds more functionality that’s helpful for today’s modern text environment. In addition to the hex code and Vim digraphs, ga will now show the Unicode character names, the emoji short names and the HTML entity names. For example:

  • Press ga on top of ™ and Vim will tell you the HTML entity name is ™
  • Press ga on top of ▙ and you will see the Unicode name is QUADRANT UPPER LEFT AND LOWER LEFT AND LOWER RIGHT (but who doesn’t know that already)
  • Press ga on top of 🪳 and you’ll learn that you can enter this Emoji in Slack with :cockroach:

The emoji capabilities alone make this yet another tpope plugin worthy of a line in your .vimrc.

The post Inspect Character Under Cursor in Vim appeared first on VimTricks.

Inspect Character Under Cursor in Vim first appeared on Web and IT News.

awnewsor

Recent Posts

FDP Mold Remediation of Newark Explains When a Small Mold Problem May Not Require Professional Cleanup

FDP Mold Remediation of Newark A small patch of mold doesn’t always require professional remediation.…

3 hours ago

AI-generated answers are now the top starting point for product research among AI-active shoppers

According to Impact.com‘s latest research report, The new front door: How AI is rewriting the buyer’s journey,…

3 hours ago

Wellness Index Report Names Three “Builders of Healthspan” in October 2026 Issue: “Built to Last: The Engineering of Healthspan”

table, td, td p, span, font {font-family: Arial, Helvetica, sans-serif ; font-size:11pt ;} View this…

3 hours ago

Sinch Announces Joining the Inaugural SpaceX Super Intelligence Network as Marketplace Partner

Sinch AB (publ) has announced that it has been named a Marketplace Partner in the SpaceX…

3 hours ago

QSIC Appoints Former Woolworths and Cartology Leader Mark Mansour as Managing Director APAC

Cartology founding team member and former Woolworths MarketPlus managing director brings the retailer’s perspective to…

3 hours ago

AMD Forecasts a $17 Billion Quarter After Data Center Sales Nearly Double

AMD expects to bring in about $17 billion in the fourth quarter, plus or minus…

3 hours ago

This website uses cookies.