Friday, December 12, 2008

Value Under Cursor #2

Expanding on a previous tip. Here are some methods for figuring out the value of a given character.

1) Using gf - place the character under a character and hit ga in normal mode to obtain it's ascii value.

2) Using g8 - same as above but applies to UTF-8 characters.

3) :set list - toggles displaying unprintable characters.

4) pipe into the shell command od -c

5) type the :ascii ex command to display a characters ascii value

6) use cat -vET filename

6 comments:

Anonymous said...

In my statusline, I show (among other things) the character under the cursor + utf-8 sequence of the character under the cursor when it is a non-ASCII characters:

In my .vimrc:

set laststatus=2
set ruler

function! SyntaxItem()
return synIDattr(synID(line("."),col("."),1),"name")
endfunction

function! ShowUtf8Sequence()
let p = getpos('.')
redir => utfseq
sil normal! g8
redir End
call setpos('.', p)
return substitute(matchstr(utfseq, '\x\+ .*\x'), '\<\x', '0x&', 'g')
endfunction


if has('statusline')
if version >= 700
" Mojosa statlinio
set statusline =
set statusline+=%#User1#
set statusline+=%-2.2n\ "
set statusline+=%#User2#
set statusline+=%f\ "
set statusline+=%#User1#
set statusline+=%h%m%r%w\ "
set statusline+=%{strlen(&ft)?&ft:'none'},
set statusline+=%{(&fenc==\"\"?&enc:&fenc)},
set statusline+=%{((exists(\"+bomb\")\ &&\ &bomb)?\"B,\":\"\")}
set statusline+=%{&fileformat},
set statusline+=%{&spelllang},
set statusline+=%{SyntaxItem()}
set statusline+=%=
set statusline+=%#User2#
set statusline+=%{ShowUtf8Sequence()}\ "
set statusline+=%#User1#
set statusline+=0x%B\ "
set statusline+=%-6.(%l,%c%V%)\ %<%P
endif
endif

hi User1 guifg=#00ff00 guibg=#00aa00 gui=bold term=standout cterm=bold ctermfg=lightgreen ctermbg=lightgreen
hi User2 guifg=#ffff00 guibg=#00aa00 gui=bold term=none cterm=bold ctermfg=yellow ctermbg=lightgreen

Anonymous said...

In my experience, :set list enables the display of unprintable characters (does not toggle it), and :set nolist disables it.

tbartels said...

don't forget

gd Goto Local Declaration, basically this is a backwards search for the keyword under cursor that ignores comments

use gD for global declarations.

pyrho said...

Another cool feature is C-R C-W, this sequence pulls the word under the cursor to the line below the statusbar.
For example, you want to substitute a word and your cursor is on it, just do :s^R^W/lol/

That changed my life :D

ps: the "^R^W" is to be understood as CONTROL+R and CONTROL+W, blogger won't let me put '<'C-R'>' :)

Unknown said...

:set list! will also disable it.

Anonymous said...

Here's an issue that I would appreciate a tip on: When I have two or more files open, and I use :wn and :wp, or :bn and :bp to switch between the files, it always moves the line the cursor was previously on to the middle of the screen when I switch back to the file. I'd like it to leave the lines just where I left them and not move the current line to the middle when I switch back. (I'm using Vim on Windows; forgot whether it does the same on Linux).

Thanks.

Casey