Vim: Going to the nth character in a file

By Druss , 14 August, 2010

I ran into an error message today that only specified the character number in a configuration file without making any reference to the line number. Rather odd. In any case, since Vim (and my usual preference, GVim) is an excellent editor, I expected this to be a cinch. Unfortunately, a few minutes of head-scratching later, I was still quite clueless as to how to accomplish this seemingly routine task.

I do know that typing:
:1000
will move the cursor to the 1000th line in the file.

There is also a line and character position display in the bottom right hand side of the UI. However, I was at a loss with respect to moving to a character position. Google was not helping. So I had to message a friend who replied with the following syntax. Typing
g, o, 1000 [minus the commas, of course ...]

will move the cursor to the 1000th character in the file. Rather neatly too.

Hope this helps.
JH
P.S. as a bonus, typing 200x will delete 200 characters from the current position :)

All times are UTC. All content licensed under the Creative Commons Attribution-Noncommercial-Share Alike 3.0 License.