Vim Tips Wiki
No edit summary
 
(General review, Consolidated most comments into tip. Changed Name)
Line 2: Line 2:
 
{{Tip
 
{{Tip
 
|id=67
 
|id=67
  +
|title=Showing ASCII value of the current character
|title=Ascii Value
 
 
|created=May 7, 2001 5:56
 
|created=May 7, 2001 5:56
 
|complexity=intermediate
 
|complexity=intermediate
Line 9: Line 9:
 
|rating=217/107
 
|rating=217/107
 
|text=
 
|text=
Sometimes we, the programmers, need the value of a character, don't we?
+
Sometimes we programmers need the value of a character, don't we?
   
You can learn the ascii value of a character by pressing g and a keys.(ga)!
+
You can learn the ASCII value of a character by pressing '''ga''' in command mode or ''':as''' / ''':ascii''' on the command line
   
It displays the value in dec, hex and octal...
+
This displays the value of the character under the cursor in dec, hex and octal...
 
}}
 
}}
  +
To get the same for a multibyte character use '''g8'''
   
 
You can also add options to the statusline option to show the
== Comments ==
 
 
ASCII value of the character under the cursor.
You can also add options to the statusline option to show what the
 
ascii value of the character under the cursor is.
 
   
set statusline=%<%f%h%m%r%=%b 0x%B %l,%c%V %P
+
:set statusline=%<%f%h%m%r%=%b\ 0x%B\ \ %l,%c%V\ %P
^^^^^^^^
 
   
  +
It's the '''%b\ 0x%B''' that does the trick. See ''':help statusline''' for detail. Note that you may need to :set laststatus=2 (or 1) so that the status line is visible. See vim's help on '''laststatus'''.
The underlined part is what does it.
 
  +
 
== Comments ==
   
dp--AT--orion.spectral-sys.com
 
, May 9, 2001 6:35
 
----
 
 
The mnemonic I use to remember ga is "get ascii" but I guess that is an obvious one...
 
The mnemonic I use to remember ga is "get ascii" but I guess that is an obvious one...
   
scrott--AT--users.sourceforge.net
+
scrott--AT--users.sourceforge.net, May 9, 2001 22:29
, May 9, 2001 22:29
 
----
 
doesn't work with multibyte editing :-(
 
 
stephane--AT--tuxfinder.org
 
, June 5, 2001 5:00
 
----
 
For multibyte use g8.
 
 
Alexey Marinichev
 
, June 7, 2001 14:57
 
----
 
all i want is a backwards 3, where the 3 is facing the other way.....
 
   
Tengauge12--AT--yahoo.com
 
, August 30, 2006 3:45
 
 
----
 
----
 
<!-- parsed by vimtips.py in 0.462430 seconds-->
 
<!-- parsed by vimtips.py in 0.462430 seconds-->

Revision as of 10:51, 9 June 2007

Previous TipNext Tip

Tip: #67 - Showing the ASCII value of the current character

Created: May 7, 2001 5:56 Complexity: intermediate Author: Erhan Version: 5.7 Karma: 217/107 Imported from: Tip#67

Sometimes we programmers need the value of a character, don't we?

You can learn the ASCII value of a character by pressing ga in command mode or :as / :ascii on the command line

This displays the value of the character under the cursor in dec, hex and octal... To get the same for a multibyte character use g8

You can also add options to the statusline option to show the ASCII value of the character under the cursor.

:set statusline=%<%f%h%m%r%=%b\ 0x%B\ \ %l,%c%V\ %P 

It's the %b\ 0x%B that does the trick. See :help statusline for detail. Note that you may need to :set laststatus=2 (or 1) so that the status line is visible. See vim's help on laststatus.

Comments

The mnemonic I use to remember ga is "get ascii" but I guess that is an obvious one...

scrott--AT--users.sourceforge.net, May 9, 2001 22:29