Vim logo vim online Vim Book Ad

 Tip #258: how long is the current word?

 tip karma   Rating 4/4, Viewed by 686 

created:   June 10, 2002 9:05      complexity:   intermediate
author:   colin dearing      as of Vim:   6.0

ever wondered how long the current word is?  this can be quite useful when editing data files.
simply add the following to your .vimrc

nmap <C-_> :echo 'word' expand("<cword>") '  wordlen =' strlen(expand("<cword>"))<CR>

and it will tell you the word under the cursor, and how long it is.

and for things that arent words, this addition to your .vimrc works on sections of a line that have been hightligted in visual mode

vmap <C-_> "-y:echo 'word' @- '  wordlen =' strlen(@-)<CR>

again you see the "word", and its length
this may also work on vim 5.x, but i havent checked to make sure.

 rate this tip  Life Changing Helpful Unfulfilling 

<<fast page up/down. | removing the toolbar (icons) from gvim >>

Additional Notes

[email protected], June 11, 2002 1:51
If showcmd is set, viw also shows the length of the current word.

v - start visual mode per character
iw - select inner word

Kind regards

Sven
Anonymous, June 11, 2002 4:17
well i didnt know that.  live and learn :)

colin
Anonymous, June 11, 2002 4:23
trying this, i have just remembered why i never discovered this.  running vim 6 in a terminal emulator, showcmd slows down screen redraws considerably.  so normally i have ruler, status bar, etc all turned off, to increase scrolling and redraw speed.

Colin
If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to [email protected] after searching the archive. Help Bram help Uganda.
SourceForge Logo