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:
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:
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!
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?