vim编辑器的配置和常用操作指令

安装vim
[root@localhost ~]# yum install -y vim
 
 
 
配置vim
[root@localhost ~]# vim ~/.vimrc
""""" 常规设置-开始 """""
set nu              " 显示行号
set paste           " 开启paste模式(粘贴代码时会原样粘贴不会再自动缩进)
set bg=dark         " 背景色设置,可改变深蓝色注释文字在黑色背景下看不清的问题
syntax on           " 语法高亮
colorscheme desert  " 配色方案,可选值:desert、evening、darkblue
""""" 常规设置-结束 """""
 
 
""""" 搜索设置-开始 """""
set hlsearch        " 高亮搜索结果,所有结果都高亮显示,而不是只显示一个匹配,关闭可设置为[nohlsearch]
set incsearch       " 逐步搜索模式,关键字搜索时对当前键入字符进行即时搜索而不是等待所有键入完成才搜索
set ignorecase      " 搜索时大小写不敏感,若要大小写敏感可设置为[noignorecase]
""""" 搜索设置-结束 """""
 
 
""""" 缩进设置-开始 """"" 
set noautoindent " 自动缩进,需要自动缩进可设为[autoindent]
set sw=4         " 自动缩进的时候,缩进尺寸为4个空格
set ts=4         " Tab宽度为4个字符
set et           " 编辑时将所有Tab替换为空格
""""" 缩进设置-结束 """"" 
 
 
""""" 当前行高亮设置-开始 """""
set cursorline
hi CursorLine cterm=NONE ctermbg=darkred ctermfg=white
hi CursorColumn cterm=NONE ctermbg=darkred ctermfg=white
""""" 当前行高亮设置-结束 """""
 
 
""""" 自动备份-开始 """""
if has("vms")
    set nobackup
else
    set backup
endif
""""" 自动备份-结束 """""
[root@localhost ~]#


 
---------- 常用操作指令 ----------
不保存退出:ESC → :q!
保存并退出:ESC → :wq
关键字查找:ESC → /关键字
删除14~19行:ESC → :14,19d
清空文件内容:ESC → :1,.d
撤销上一步操作:ESC → u(可连续按u键实现连续撤销)
转到文件结尾:ESC → G
转到第9行:ESC → 9G

Copyright © 2024 码农人生. All Rights Reserved