Fun with Ubuntu (used by Vim in the Linux editor)
Author CodeAllen , please indicate the source
Getting started with vim
1. Installation
sudo apt install - y vim
Second, open the file
open a file
sudo vim demo.cpp
Directly locate to the line, for example, line 25
sudo vim +25 demo.cpp
Simultaneously open multiple files demo.cpp and test.cpp
Ctrl + W can switch the editing window
sudo vim -O demo.cpp test.cpp
Three, configure Vim
The default vim is just a simple editor, it is more convenient to configure some development functions.
Its configuration file location is
vi /etc/vim/vimrc
Add the following configuration (you can add it yourself)
: set nu #显示行号
:set ai #自动缩进
:syntax on #语法高亮
Fourth, edit the document
vim editor is mainly three modes
- Command mode-"In this mode, the input is considered to be a control command
- Edit mode--》 a / i / o any key can switch to edit mode
- EX mode-"When exiting, Esc key, q to exit, wq to save and exit, q! To exit without saving
5. Command execution
Linux can be executed in the edit command
to use Esc to switch to command mode, a colon Ex mode, can then enter the command
Example child:
:! g++ -o demo demo.cpp
Six, shortcut keys
sudo vim /etc/vim/vimrc
Define shortcut keys, after saving, click vim directly in vim command mode to run
noremap <F6> :set nu
noremap <F7> :set ai
noremap <F8> :syntax on
Seven, some efficient configuration
filetype on #启动文件类型侦测
set encoding=cp936 #指定当前字符编码为Windows简体中文
set tabstop=4 #设置tab键为4个空格
set mouse=a #在终端中使用鼠标
set ignorecase #查找时忽略大小写