VIM工具

5.1、vim介绍

  • vim和vi功能相同,vim是vi的升级版本
  • vim带有颜色显示
  • 安装vim-enhanced
  • 三种模式:一般模式、编辑模式、命令模式;

	1. [root@centos7-01 ~]# yum install -y vim-enhanced
	2. 已加载插件:fastestmirror
	3. base                                                                                                                                                                    | 3.6 kB  00:00:00     
	4. extras                                                                                                                                                                  | 3.4 kB  00:00:00     
	5. updates                                                                                                                                                                 | 3.4 kB  00:00:00     
	6. (1/2): extras/7/x86_64/primary_db                                                                                                                                       | 129 kB  00:00:00     
	7. (2/2): updates/7/x86_64/primary_db                                                                                                                                      | 3.6 MB  00:00:04     
	8. Loading mirror speeds from cached hostfile
	9. * base: ftp.sjtu.edu.cn
	10. * extras: mirrors.163.com
	11. * updates: ftp.sjtu.edu.cn=


  • 有颜色显示

输入图片说明

  • vim三种模式
  • 一般模式:dd命令删除一行
  • 编辑模式:按i,编辑文档
  • 命令模式:按:set nu显示行数

	1. 1 root:x:0:0:root:/root:/bin/bash
	2.   2 bin:x:1:1:bin:/bin:/sbin/nologin
	3.   3 daemon:x:2:2:daemon:/sbin:/sbin/nologin
	4.   4 adm:x:3:4:adm:/var/adm:/sbin/nologin
	5.   5 lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
	6.   6 sync:x:5:0:sync:/sbin:/bin/sync
	7.   7 shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
	8.   8 halt:x:7:0:halt:/sbin:/sbin/halt
	9.   9 mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
	10. 10 operator:x:11:0:operator:/root:/sbin/nologin
	11. 11 games:x:12:100:games:/usr/games:/sbin/nologin
	12. 12 ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
	13. 13 nobody:x:99:99:Nobody:/:/sbin/nologin
	14. 14 systemd-bus-proxy:x:999:997:systemd Bus Proxy:/:/sbin/nologin
	15. 15 systemd-network:x:192:192:systemd Network Management:/:/sbin/nologin
	16. 16 dbus:x:81:81:System message bus:/:/sbin/nologin
	17. 17 polkitd:x:998:996:User for polkitd:/:/sbin/nologin
	18. 18 tss:x:59:59:Account used by the trousers package to sandbox the tcsd daemon:/dev/null:/sbin/nologin
	19. 19 postfix:x:89:89::/var/spool/postfix:/sbin/nologin
	20. 20 sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
	21. 21 chrony:x:997:995::/var/lib/chrony:/sbin/nologin
	22. 22 liyang:x:1000:1000::/home/liyang:/bin/bash
	23. 23 user1:x:1001:1001::/home/user1:/bin/bash
	24. 24 user2:x:1002:1002::/home/user2:/bin/bash
	25. ~                                                                                                                                                                                              
	26. ~                                                                                                                                                                                              
	27. ~                                                                                                                                                                                              
	28. ~                                                                                                                                                                                              
	29. ~                                                                                                                                                                                              
	30. ~                                                                                                                                                                                              
	31. ~                                                                                                                                                                                              
	32. ~                                                                                                                                                                                              
	33. ~                                                                                                                                                                                              
	34. ~                                                                                                                                                                                              
	35. ~                                                                                                                                                                                              
	36. ~                                                                                                                                                                                              
	37. :set nu



5.2、vim颜色显示和移动光标

  • 指定的文档放在指定的位置,会有颜色显示;
  • vim显示条件有很多,vim编辑文件时会显示颜色(和文件的具体内容有关系.ss&.py)
  • vim的配置文件在/etc/vimrc,也可在用户自己的家目录下编辑:vim /root/.vimrc

	1. [root@centos7-01 ~]# vim /etc/vimrc
	2. if v:lang =~ "utf8$" || v:lang =~ "UTF-8$"
	3.    set fileencodings=ucs-bom,utf-8,latin1
	4. endif
	5. set nocompatible        " Use Vim defaults (much better!)
	6. set bs=indent,eol,start         " allow backspacing over everything in insert mode
	7. "set ai                 " always set autoindenting on
	8. "set backup             " keep a backup file
	9. set viminfo='20,\"50    " read/write a .viminfo file, don't store more
	10.                         " than 50 lines of registers
	11. set history=50          " keep 50 lines of command line history
	12. set ruler               " show the cursor position all the time
	13. " Only do this part when compiled with support for autocommands
	14. if has("autocmd")
	15.   augroup redhat
	16.   autocmd!
	17.   " In text files, always limit the width of text to 78 characters
	18.   " autocmd BufRead *.txt set tw=78
	19.   " When editing a file, always jump to the last cursor position
	20.   autocmd BufReadPost *
	21.   \ if line("'\"") > 0 && line ("'\"") <= line("$") |
	22.   \   exe "normal! g'\"" |
	23.   \ endif
	24.   " don't write swapfile on most commonly used directories for NFS mounts or USB sticks
	25.   autocmd BufNewFile,BufReadPre /media/*,/run/media/*,/mnt/* set directory=~/tmp,/var/tmp,/tmp
	26.   " start with spec file template
	27.   autocmd BufNewFile *.spec 0r /usr/share/vim/vimfiles/template.spec
	28.   augroup END
	29. endif
	30. if has("cscope") && filereadable("/usr/bin/cscope")
	31.    set csprg=/usr/bin/cscope
	32.    set csto=0
	33.    set cst
	34.    set nocsverb



5.3、vim一般模式下移动光标

  • h或者向左的方向键 光标向左移动一个字符;
  • l(小写字母l)或者向右的方向键 光标向右移动一个字符;
  • k或者向上的方向键 光标向上移动一个字符;
  • j或者向下的方向键 光标向下移动一个字符;
  • CTRL+f或者pageup键 屏幕向前移动一页;
  • CTRL+b或者pagedown键 屏幕向后移动一页;
  • 数字0或者shift+6 移动到本行的行首;
  • shift+4 移动到本行行尾;
  • gg 移动到行首;
  • G 移动到行尾;
  • nG(n是任意数字) 移动到第n行;

5.4、一般模式下复制剪切粘贴

  • x,X x表示向后删除一个字符,X表示向前删除一个字符;
  • nx 向后删除n个字符
  • dd 删除/剪切光标所在的那一行
  • ndd 删除/剪切光标所在行之后的n行
  • yy 复制光标所在行
  • p 从光标所在行开始,向下粘贴已经复制或者粘贴的内容
  • 大p 重光标所在行开始,向上粘贴已经复制或者粘贴的内容
  • nyy 从光标所在行开始,向下复制n行
  • u 还原上一步操作(最大50次) CTRL+r回复u上一步操作;
  • v 按v后移动光标会选中指定字符,然后可以实现复制、粘贴等操作

转载于:https://my.oschina.net/u/3706694/blog/1564093

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值