You are here

Vim: Going to the nth character in a file

Submitted by Druss on Sun, 2010-08-15 00:05

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:
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.
P.S. as a bonus, typing 200x will delete 200 characters from the current position :)


However, I couldn't get
g o N
to work (MacVim 7.3). It went to line N instead. However,
N go
works, as does
:go N


When you learn a new command in Vim, always read the help files for more info!
`:h go`

A lot has changed since you wrote this post 8 years ago!

Vim 8.0 shows two different commands from what you put in your article:

You entered `go1000<CR>`. Today, if we break that down, `go` without the initial count moves to the first line and is therefore the same as `gg`. Then the next command `1000<CR>` moves the cursor down 1000 lines, not characters.

To move to the 1000th character as of Vim 8.0, you need this: