Select Page

Introduction

If youā€™ve used Vim for some time now, you must already know how deeper and deeper you can get in Vim, when itā€™s about text manipulation. Actually, Vim by itself is pretty much about the manipulation thing, because if it werenā€™t prominent enough in this, you probably have no reason to choose Vim over a modern text editor anyway (unless weā€™re talking about lightweightness and accessibility).

In this article, weā€™ll try to cover pretty much everything you can expect to do with the letter ā€œeā€ inside of Vim. Sounds pretty weird doesnā€™t it? A whole article just for a single letter use-case in a text editor? Absolutely! This is why Vim has been a mighty editor all along, and will persist to be.


:edit Modified Files in Vim

Sometimes when working with large project files, we may wish to use different programs and commands at the same time on the same file. Letā€™s say, youā€™re compiling some heavy code in C++, inside of Vim, and now youā€™re using a separate terminal to run make on that file. In this scenario, the contents and the code in that file may be changed. If you now look at Vim, you may see that the contents have not been yet updated inside Vim. This is because Vim does not sync the changes in the file in real-time, to maintain its speed and efficiency.

But worry not. Vim has a command just for everything you may need from a text editor. I donā€™t current have any complex situation to demonstrate this feature, but a simple example will do just fine!

In the gif below, I have Vim and Mousepad Editor open up at the same time with the same file. Now, if you notice properly, you can see that When I edit the contents of the file inside of Mousepad, and save the file with Ctrl + s in it, we donā€™t see any changes in Vim. It stays the same. Now, in order to refresh the current file in Vim, we you probably wouldā€™ve first quit Vim and then return again to get the new contents. But you donā€™t need to. In Vim, you can type ā€œ:editā€ in Vim normal mode to refresh the current file, given that you have saved the file in the other editor:

Pretty simple and straightforward, isnā€™t it?

Notice that Iā€™ve written the full form of this command, which is :edit. You can simply use :e to make the same thing happen, but this would save you a few keystrokes.

However, thatā€™s not the only use of :e. Thereā€™s another very important one you need to know!


:edit other files in Vim

This one is a pretty common use for :edit, which you may not already know about. That is, to open up other files in Vim in a separate buffer than the current one.

To do this, you need to specify the file name, and also itā€™s absolute directory if it is not in the current one, like this:

:edit <filename>

In the above example, you should be able to see that I first used the given syntax for opening a new file in a separate buffer, which in my case was the file dwm.c (apologies for that weird text that popped up, it was just that I didnā€™t properly save it last time so a swap file as saved. You wonā€™t need to worry about it if you donā€™t understand what itā€™s doing there šŸ™‚ You wonā€™t notice any visible difference about different buffers having different files, as Vim usually doesnā€™t show it in the default interface (youā€™ll need a plugin to show buffers in the form of tabs at the top if you want that). But after that, if you look at the at the commandline in Vim, I typed this:

:bn

It is a command to navigate between open buffers in Vim. This is just a short for ā€œbuffer nextā€. Thereā€™s also one that does the opposite of this one, which is to switch to the previous buffer, by typing ā€œ:bpā€ (buffer previous). This is helpful in case you have a lot of buffers fired up, and switching through files in the forward direction only may slow you down.

Using :e in vim to fix folds

ā€œFoldsā€ in vim are where a block of code can be expanded or collapsed. This helps with navigating large files with lots of functions.

Sometimes, vim can mess up the folds if youā€™ve been editing a file for a long time.

The easiest way to fix the folds is to just :e so that vim can reload the folds from start. This is much easier than quitting and editing the file again.

Using :e to reload .vimrc

Using :e may also help you in one other important scenario. Letā€™s say, youā€™re adding up some settings in your .vimrc, and you want to see if the settings are fine by applying on a file. To do this, you may have done this the traditional way, which is to first quit Vim, and then reenter the file to check out the changes. But hopefully, Vim could help you save some time if you use ā€œ:eā€ inside of .vimrc to avoid needing to reload it every time.

You should now have a clear understanding of how to use :edit or :e for different use cases. But the letter e wonā€™t stop there. It has more uses weā€™re left to cover.


Jumping words with ā€œeā€

If you know a little about Vim navigation, and have went through a few tutorials and cheatsheet, you should be no stranger to the different ways you can navigate in Vim. Here in our website, we have a dedicated cheatsheet article that covers only the Navigation commands in Vim, but still being large enough to water your eyes!

If you press w in normal mode, your cursor will jump to the first letter of the next word in front of it. And if you press b, your cursor will jump to the first letter of the previous word. This is pretty useful and yet time saving when youā€™re navigating through the same column in Vim, and saves you a bunch of time as compared to using h and l or the left and right arrow keys to navigate. However, sometimes this may not be enough to fulfill your Vim navigation shenanigans!

If you press e in Vim normal mode, you can navigate to the end of the next word in front of your cursor:

If there are any punctuations in front of the word youā€™ve jumped, youā€™ll need to press e twice to jump directly on the punctuation. But you probably donā€™t need to, because you can also use a capital E instead to jump directly to the next wordā€™s punctuation without needing to press e twice:

Still not happy enough? I know you arenā€™t.

You can also press ge together to navigate to the last letter of the previous word. If the previous word contains a punctuation, you can use gE to navigate to that instead. I wonā€™t show it to you this time. Why not try it yourself, lazy fella!


Conclusion

If this article has not yet given you an idea of how vast Vim is, nothing else will. Itā€™s just part of the whole package. If you research a little more, youā€™ll find your cheeks growing age-spots, having still not reached the peak of all Vim commands. This is because Vim commands donā€™t work the same everytime. It doesnā€™t mean youā€™ll be encountering bugs, but what I essentially mean is that if you pair different command letters together, you can invent new ways of using Vim others may not have found yet.

How cool is that?