Vim for file directory operations summary _linux

Source: Internet
Author: User

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 :

: W%%.bak

Open in the same directory main.h :

: e%:p: h/main.h

Insert Current file name:

"%p

Copy the current file name to the Clipboard, and of course you can make it a shortcut key:

: Let @*=expand ("%:t")

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.