در حال بارگذاری ...

Opening and Creating Files0:00

File management in Vim and NeoVim is a little different to most editors. Let's learn about buffers and a few other Vim concepts for managing our open files. Let's come back to the terminal. We can open the test.txt file we created in the previous lesson by passing it as an argument on the command line. Alternatively, if we quit back out of Vim and then open it on its own, we can use :e, so that's : for command mode and then e for edit, and then the file name we want to open. And we can use tab completion here. If we want to create a new file, we can type enew, and this will open a new unnamed buffer. We can come into insert mode, we can type some words, escape to normal mode, and then :w, and because it's an unnamed buffer at this point, we need to give it a name.

Saving and Listing Buffers0:42

We can come into insert mode, we can type some words, escape the normal mode, and then :w, and because it's an unnamed buffer at this point, we need to give it a name. So let's say test2.txt. Once we've given it a name, we can just use :w to write the file. If we already know the name of the file we want to create, we can just type :e followed by the file name, even if it doesn't exist, and this will open a new buffer with that name. This file doesn't exist on disk yet, so let's go into insert mode and type some more words, and then we'll save this. Now because we've already given this a name, we can just use :w. So now we have three files open, but how do we switch between them? By default, you can say :ls to list all open buffers,

Tabs, Splits, and Quitting4:06

So let's open up a horizontal split using our split command and then we can switch to the previous tab using tab p for tab previous. So each tab has a different layout or a different number of splits. I don't tend to use this feature at all, and so later we'll install a plugin that places our buffers across the top instead of these tabs. One last note. If we've got multiple files open, we can use :wqa, which will write and quit all. We can use :wa to write all, or we can use qa to quit all. And if we have some unsaved changes, we can always put the exclamation at the end. So let's quit out of Vim, closing all of the open buffers, not saving any changes.

Open FilesSave and QuitBuffersSplits

دوست دارید گاهی خبرهای Laracasts را ایمیل کنیم؟