文本编辑器vim
vim是vi的升级版本,直观上最大的区别就是增加了显示文字颜色功能。首先我们要安装vim,使用命令:
[root@localhost ~]# yum install -y vim-enhanced
vim分3种模式,他们之间的关系是
默认vim +文件,我们进入的是一般模式(图中的命令模式):
[root@localhost etc]# vim yum.conf
[main]
cachedir=/var/cache/yum/$basearch/$releasever
keepcache=0
debuglevel=2
logfile=/var/log/yum.log
exactarch=1
obsoletes=1
gpgcheck=1
plugins=1
installonly_limit=5
bugtracker_url=http://bugs.centos.org/set_project.php?project_id=23&ref=http://bugs.centos.org/bug_report_page.php?category=yum
distroverpkg=centos-release
# This is the default, if you make this bigger yum won't see if the metadata
# is newer on the remote and so you'll "gain" the bandwidth of not having to
# download the new metadata and "pay" for it by yum not having correct
# information.
# It is esp. important, to have correct metadata, for distributions like
# Fedora which don't keep old packages around. If you don't like this checking
# interupting your command line usage, it's much better to have something
# manually check the metadata once an hour (yum-updatesd will do this).
# metadata_expire=90m
# PUT YOUR REPOS HERE OR IN separate files named file.repo
# in /etc/yum.repos.d
~
~
~
~
~
~
~
"yum.conf" 26L, 970C 1,1 全部
一般常用操作
- ctrl+b 向上翻屏
- ctrl+f 向下翻屏
- v 选择一堆连续的数据
- yy 复制所在行
- nyy 从光标开始向下复制n行
- p 向下粘贴
- 大P 向上粘贴
- ^ 移动到行首 (符合正则 开头的意思)
- $ 移动到行尾 (符合正则 结尾的意思)
- gg 移动到首行
- G 移动到尾行
- nG 移动到第n行
- dd 剪切一行
- ctrl+r u多按了,使用这个再回来
- x 剪切一个或者向后删除
- 大X 向前删除 就是删除的键位
- :x 没做任何操作,wq会修改mtime x不会!
- > /etc/passwd 清空该文件
编辑模式常见操作
- 大I 在行首输入
- 大A 在行末输入
- 大O 在当前行的上一行输入
命令模式常见操作
==替换格式 s代表替换 g代表全部 替换的时候如果关键字也有/ 则可以换成# @==
- /搜索关键字 按n 选到下一个 N选到上一个
- :1,100s/xx/oo/g 1-100行全局替换xx为oo
- :1,$s/xx/oo/g 全文替换
- :加上↑ 调出上次输入命令
- :set nu 显示行号
- :set nonu 不显示行号
- :nohl 不高亮
笔记
- vim一个文件时会产生一个临时文件xx.swap 如果文件编辑完毕保存退出,则该临时文件消失。如果意外退出则下次打开会提示恢复该文件使用 :recover
- :e! 把文件恢复到打开时的状态
- :set noai nosi 无格式选择性粘贴 或者 :set paste
- :X 加密 :set key= 取消密码 :wq