Ha, now you have learned a way to open files in Vim, although this way is not the most common, but it is the most direct, especially when your code includes a certain file, the following introduces two other commonly used open methods.
:e <filename>
open the file which named<filename>
, if the file is not exists, it will create a new one:Ex
open the directory tree in Vim, press-
to enter the parent directory and press Enter to open the corresponding file
*
find the word under the cursor and jump to the next#
find the word under the cursor and jump to the previous/<search>
find the specified string backward?<search>
find the specified string forwardn
continue to find the nextN
continue to find the previous
Note: n
and N
are directional. If you previously searched with *
, n
will continue to search toward the end of the document, and N
toward the
beginning of the document; conversely, if you search with #
, n
points to the
beginning and N
points to the end of the document.
f<X>
FindsX
on a line toward the end of the line and positions the cursor over the characterX
.`t<X>
FindsX
on a line toward the end of the line and positions the cursor over the character beforeX
.F<X>
FindsX
on a line toward the beginning of the line and positions the cursor over the characterX
.T<X>
FindsX
on a line toward the beginning of the line and positions the cursor over the character afterX
.;
Find the next character in the current direction,
Find the previous character in the current direction
There are several "Vim" words in the current document, you can try to use
*
and#
to find and feel the directionality ofn
andN
.And there are several "n" characters in the "Note" above, you can try to find them in the line and feel the directionality of
;
and,
.
In Vim, you can use %
to match (
and )
, [
and ]
, {
and }
. When the
cursor is on one of the symbols, press %
, the cursor will jump to the other
symbol that matches it.
Press
%
on the()[]{}
characters in the following text to see the effect, and then pressn
to continue searching.
const func = (win, doc) => {
const SEVEN = ((1 + 2) * (3 + 4) * (5 - 6)) / 7;
const YU = [1, 2, [[3, 4], 5, 6], 7];
if (true) {
return SEVEN;
} else {
return YU;
}
};
Next Chapter will introduce the modification of the document. Before that, let's briefly introduce the buffer of Vim. Simply understand that the buffer is the file history of the current Vim session.
Now you should have two files in your buffer, you can use
:buffers
or:ls
command to view, see the buffer list, probably like this:
:ls
1 #h "chapter01.md" line 47
2 %a "chapter02.md" line 1
Press ENTER or type command to continue
Then, you can use the following commands to switch between buffers:
:bn
open the next file in the buffer:bp
open the previous file in the buffer:b<N>
open the Nth file in the bufferAlso you can use
:bdelete<N>
to delete the buffer you want to close, the abbreviation is:bd<N>
.Of course, you can also use the
:Ex
command, selectchapter03.md
and open it, enter Chapter 3.