user3222947
user3222947

Reputation: 197

How to scroll down to last line in Vim?

My Rails production.log has 2000000 lines. How can I scroll down to the last line with Vim?

I scroll down with Ctrl+F and Ctrl+D but it's not fast enough.

Upvotes: 5

Views: 13441

Answers (4)

Purefan
Purefan

Reputation: 1506

According to this article:

To move to end of file just type G (press ESC and type capital G):

You can also go to a specific line with the line number followed by G, for example to go to line 123 you would do

123G

Upvotes: 5

Ingo Karkat
Ingo Karkat

Reputation: 172500

Alternative motions

Note that you can prefix motions like j or Ctrl + F with a number (multiplier), called [count] in the (excellent) :help. That gets you around a large buffer fast.

Another beneficial, but less known command is N%, to jump to a percentage in the file, e.g. the middle with 50%.

Best solution

But your particular problem is indeed best addressed by G, or :$ followed by Enter.

Additional help

With such a large file, navigation in Vim may be sluggish. Have a look at the LargeFile - Edit large files quickly plugin, which changes some options to speed up Vim.

Tips

If you're new to Vim (and its navigation and editing commands), you should spend 30 minutes on the vimtutor that comes with it (see :help vimtutor inside Vim). Then, there are several good resources, cheatsheets, and vi / Vim tutorials out there on the net. http://vimcasts.org/ has several short entertaining episodes that go beyond the basics.

Learn how to look up commands and navigate the built-in :help; it is comprehensive and offers many tips. You won't learn Vim as fast as other editors, but if you commit to continuous learning, it'll prove a very powerful and efficient editor.

Upvotes: 13

sanmiguel
sanmiguel

Reputation: 4878

Further to the other answers, if the first thing you do when you open the logfile is jump to the end, have vim open the file straight at the end with:

vim /path/to/logfile +

Alternatively, as in my comment above, try opening it in a pager such as less if you're not actually editing the file. Again, you can jump straight to the end of the file from the command line:

less +G /path/to/logfile

More generally, both these forms (with the + argument) allow you to specify a command to run on startup.

vim defaults to jumping to the end of the file if no command is given, whereas less requires you to specify the G command. Both less and vim support searching for a specific string (e.g. a date) on opening the file with:

vim +/2014-02-28 /path/to/logfile
less +/2014-02-28 /path/to/logfile

Upvotes: 3

Kent
Kent

Reputation: 195029

G is the key. if you want to open the file with cursor positioning on the last line, you can:

vim +  foo.log

Upvotes: 4

Related Questions