vi/vim editor for raspberry pi

Linux commonly used editing tools include nano, vi/vim (vim is an enhanced version of vi) and so on. Novices are recommended to use the nano editor, which is simple and easy to use. Personally, I prefer to use the vi/vim editor. If you want to use the vi editor, you must first reinstall the vi editor, because the editor that comes with the Raspberry Pi is quite pitiful, who knows who uses it.

First remove the default vi editor

sudo apt-get remove vim-common

then reinstall vim

sudo apt-get install vim

For convenience, you have to add the following three sentences after the /etc/vim/vimrc file

set nu #display line number
syntax on # syntax highlighting
set tabstop=4 #tab back four spaces
The effect is as follows

vi has 3 modes: insert mode, command mode, low-line mode .

    Insert Mode : In this mode, you can enter characters, press ESC to return to command mode.

    Command mode : You can move the cursor, delete characters, etc.

    Low-line mode : you can save files, exit vi, set vi, search and other functions (low-line mode can also be regarded as command mode)

Open file, save, close file (used in vi command mode)

vi filename //Open filename file

:w // save the file

:q //Quit the editor, if the file has been modified please use the following command

:q! //Quit the editor without saving

:wq //Exit the editor and save the file


Insert text or line (used in vi command mode, after executing the following command, it will enter insert mode, press ESC key to exit insert mode)

a //Add text to the right of the current cursor position

i //Add text to the left of the current cursor position

A //Add text at the end of the current line

I //Add text at the beginning of the current line (the beginning of the line with a non-empty character)

O     //在当前行的上面新建一行

o     //在当前行的下面新建一行

R     //替换(覆盖)当前光标位置及后面的若干文本

J     //合并光标所在行及下一行为一行(依然在命令模式)

删除、恢复字符或行(vi命令模式下使用)

x          //删除当前字符

nx        //删除从光标开始的n个字符

dd       //删除当前行

ndd     //向下删除当前行在内的n行

u         //撤销上一步操作

U         //撤销对当前行的所有操作

复制、粘贴(vi命令模式下使用)

yy      //将当前行复制到缓存区

        nyy    //将当前行向下n行复制到缓冲区

yw     //复制从光标开始到词尾的字符

nyw   //复制从光标开始的n个单词

y^     //复制从光标到行首的内容

y$     //复制从光标到行尾的内容

p      //粘贴剪切板里的内容在光标后

P      //粘贴剪切板里的内容在光标前

设置行号(vi命令模式下使用)

:set  nu       //显示行号

:set nonu    //取消显示行号

新手使用vi可能不习惯,慢慢的被虐多了就觉习惯了 。顺便提醒一句,linux系统是区分大小写的。另附vi/vim键盘图一张。


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324636458&siteId=291194637