First, the current file name
We know that Vim has 48 registers, where the current file path is kept in the% read-only registers. For example /home/harttle/
, at the bottom open src/main.cpp
, we print the% value:
: Echo @% file path src/main.cpp
The keywords expand to get the absolute path, the directory, and other information:
: Echo expand ('%:t ') "filename main.cpp
: Echo expand ('%:p ') " absolute path/home/harttle/src/main.cpp
: echo expand ('%:p: h ') "Directory/HOME/HARTTLE/SRC
: Echo expand ('%:p: H:t ')" The directory name src
:p understood as Path: H is understood as head: T is understood as tail. Reference: Help expand.
Second, use% for file operation
Back up the current file main.cpp
to main.cpp.bak
:
Open in the same directory main.h
:
Insert Current file name:
Copy the current file name to the Clipboard, and of course you can make it a shortcut key:
Three, open the directory directly
Harttle found that vim can open not only files, but also directories. Open it directly vim /home/harttle
, or you can open the directory in VIM:
: E./harttle edit this directory
: Explore. "Browse this directory
: Sexplore. " Browse the directory in the horizontal split window
: Vexplore. " Browse the table of contents in a vertical split window
Open the table of contents and enter into the next level-return to the previous layer, r rename, d delete.
The horizontal split here refers to the top and bottom two windows, split vertically into the left and right two windows. Seemingly tmux and vim on the level and vertical definition of the contrary, Harttle is also drunk.
Four, the Universal method
If you can't find the appropriate VIM command, you can always execute the bash command directly in vim. You only need to add a leading! character in ex mode, for example:
# list Files
:!ls
# Delete file
:!rm foo.txt
In addition, the Nerdtree plug-in can display the file directory tree in vim. Of course, you also integrate file and directory operations, and you need to familiarize yourself with their shortcut keys.
Summarize
The above is the entire content of this article, I hope the content of this article for everyone's study or work can help, if there is doubt you can message exchange.