Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are some use cases of :e in Vim?

Tags:

vim

vi

I was reading :help :edit but I really don't understand the following sentence:

This is useful to re-edit the current file, when it has been changed outside of Vim

And what does start all over mean in :help :edit!?

This is useful if you want to start all over again

Could anyone please provide some use cases of them?

like image 451
Herbert Avatar asked Oct 04 '16 17:10

Herbert


1 Answers

"Changed outside of Vim" means that the file that you're editing has been written to by another program. :e will load the latest version, and :e! will do that even if you have unsaved changes.

Loading the current file from the file system is useful if you're following a log, or viewing a generated file that gets updated when you run :make and other situations.

One use for this is to throw away the changes you've made since the last save with :w and go back to the most recent saved version. Which is to say, it's not necessary for the file to have changed behind Vim's back for this to be useful. Although Vim has enough undo depth that you can usually undo your way to back to the unmodified state, it's cumbersome. You can easily "overshoot" and then have to redo. The status line shows you whether the file is [Modified] or not, but as you undo, it gets overwritten with information about each undo, so you have to use Ctrl-G to re-display the file status.

I had no idea :e by itself with no argument did this re-loading, by the way; I have been using :e% for years!

like image 51
Kaz Avatar answered Oct 03 '22 13:10

Kaz