码迷,mamicode.com
首页 > 系统相关 > 详细

1.5Vim工具使用详解

时间:2015-12-07 00:43:58      阅读:161      评论:0      收藏:0      [点我收藏+]

标签:vim工具使用详解

        Vim编辑器是Vi的升级版,在选择最小化安装Linux系统,默认没有安装Vim工具。

一、安装Vim

1、查询安装包

[root@www ~]# yum search vim
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.btte.net
 * extras: mirror.bit.edu.cn
 * updates: mirror.bit.edu.cn
========================================= N/S Matched: vim =========================================
vim-X11.x86_64 : The VIM version of the vi editor for the X Window System
vim-common.x86_64 : The common files needed by any version of the VIM editor
vim-enhanced.x86_64 : A version of the VIM editor which includes recent enhancements
vim-filesystem.x86_64 : VIM filesystem layout
vim-minimal.x86_64 : A minimal version of the VIM editor

  Name and summary matches only, use "search all" for everything.

2、安装Vim

[root@www ~]# yum -y install vim-common vim-enhanced


二、vim的使用

1、vim的一般模式

j   向下

k  向上

n+j    向下跳到第n行

n+k   向上跳到第n行

gg  顶部

G    底部

ctrl + f        向下翻一页

ctrl + b       向上翻一页

shift + $     光标移动到行尾

shift + ^     或者 0   光标移动到行首

数字n + G   移动到指定的第n行


dd   剪切光标所在行     

p     粘贴到下一行

P     粘贴到上一行


D      剪切光标所在行后面的内容

P      粘贴在光标

P      粘贴在光标后


u            恢复上一步操作

ctrl + r   撤销上一步操作

X        向前删除一个字符

x        向后删除一个字符

数字+x   向后删除多个字符

数字+X   向前删除多个字符


yy      复制当前行

p       向下粘贴yy复制的行

P       向上粘贴(大写P)

2+yy    向下复制两行


v   进入可视化模式


2、vim的编辑模式

a    光标移动到当前后一个字符进入编辑模式

A    光标移动到行尾进入编辑模式


i    进入编辑模式

I    光标移动到行首进入编辑模式


o    在当前行下另起一行

O   在当前行上另起一行


3、vim的命令模式

在一般模式下使用”:“或”/“显示该模式在左下角


/word    搜索字符,n移动到下一个,N移动到上一个

:%,$s/word/new word/g      搜索第一行到最后一行的word并替换为new word,加g表示全部替换

:%,$s/word/new word/gc     加c表示逐个询问替换


:1,$s/\/etc\//111111/g    


:noh         取消高亮


:set nu      设置行号

:set nonu  取消行号


:sh   跳出vim回到shell,exit返回vim


vim +8 /etc/passwd  打开并定位到第8行

:e!     撤销回到初始状态

:X        使用vim工具设置密码,设置空密码取消密码

Warning: Using a weak encryption method; see :help ‘cm‘
Enter encryption key: ***
Enter same key again: ***

:!ls /      在vim下使用shell命令
bin   dev    disk6  home  lib64       media  opt   root  selinux  sys  usr
boot  disk1  etc    lib   lost+found  mnt    proc  sbin  srv      tmp  var



1.5Vim工具使用详解

标签:vim工具使用详解

原文地址:http://7424593.blog.51cto.com/7414593/1720133

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!