Use vim to edit and create new files under Linux

888u

Last update at :2024-03-05,Edit by888u

When using a VPS on a Linux system, you will inevitably encounter the situation of editing configuration files or modifying files. As a text editor built into Linux, the vi/vim editor can very conveniently create new files and edit text. Editing of files. This article introduces the use of vim to edit and create new files under Linux.

Introduction to vim editor

The vim editor was developed from vi. It is also a text editor commonly used on Linux. It is generally built-in in Linux and can be used directly without installation. It is very convenient.

Basically, vi/vim is divided into three modes, namely Command mode, Insert mode and Last line mode. To edit a file with vi/vim, first enter the command mode, enter i to enter the input mode, after the modification is completed, enter ESC to enter the bottom line command mode, and finally: wq to save.

The difference between vim and vi is that vim is an upgraded version of vi. Vim is compatible with all instructions of vi, and also has some new features (see the article for details). In our daily use, both vim and vi can be implemented , for example, if I want to modify the file /etc/conf.json, both vi /etc/conf.json and vim /etc/conf.json can be implemented, and the operations of adding, deleting, modifying and checking are basically the same.

Vim editor usage tutorial

Edit files

The following takes modifying /etc/ssh/sshd_config as an example.

Enter vi /etc/ssh/sshd_config (or vim /etc/ssh/sshd_config), use the up and down arrows, or ctrl+f, ctrl+b to page up and down to find the part you want to modify, enter i to enter editing (INSERT )model.

At this time, pay attention to the mode in the lower left corner (INSERT mode). At this time, the green cursor is where we enter letters. Just like Windows Notepad, delete and enter text:

After completing the modification, press ESC to enter the bottom line command mode, then enter: wq (the colon is an English colon, w means write, q means quit), and then press Enter to save the changes and exit:

New file

If you want to use the vim editor to create a new file, for example, if I want to create a new test.txt in the /root directory, directly enter vi /root/test.txt, enter the content in the same way as editing the file and save it, vim The corresponding file will be automatically created.

Attachment

1.The difference between vim and vi

Compared with vi, several new features of vim are summarized as follows:

  • Multi-level undo: In vi, pressing u can only undo the last command, but in vim, you can undo without restrictions.
  • Ease of use: vi can only run on unix, while vim can run on multiple operating platforms such as unix, windows, mac, etc.
  • Syntax highlighting: vim can use different colors to highlight your code.
  • Visual operation: vim can not only run in the terminal, but also in x windowsdow, mac os, windowsdows.
  • Completely compatible with vi: In some cases, you can use vim as vi.
  • 2.vim keyboard diagram

    Recommended site searches: foreign virtual space, domain name space purchase, foreign server rental price, all-purpose virtual host, Taiwan host, Zhejiang server, icp registration query, expired domain name query, Chinese domain name, Korean server rental,

    Use vim to edit and create new files under Linux

    All copyrights belong to 888u unless special state
    取消
    微信二维码
    微信二维码
    支付宝二维码