现在的位置: 首页 > 综合 > 正文

VI基础及常用技巧 .

2013年10月02日 ⁄ 综合 ⁄ 共 1523字 ⁄ 字号 评论关闭

 

1、 新建文件

    # vim filename

2、VI中的基本模式

   插入模式  i   a

   命令模式   ESC键

   尾行模式 在命令模式下输入:

       保存退出:wq

       不保存退出:q!

       保存:w

       另存:w filename

    在命令模式下:

        复制  nyy     n为数字,代表需要复制从光标所在行开始的行数

        粘贴 p

        删除 ndd   n为数字,代表需要删除从光标所在行开始的行数

        光标移动  上k 下j 左h 右l     可加n   100k:向上移动100行

        回到文本开头 gg

        移到最后一行 G

        移到某行  :num

  3、显示行号  :set nu

  4、查找: /xxx(?xxx)  整篇文档中搜索匹配xxx的字符串, / 表示向下查找, ? 表示向上查找.其中xxx可以是正规表达式

        替换:   : %s/aaaa/bbbb/g    将aaaa替换为bbbb

  5、取消高亮 : nohl

  6、格式化文件:gg=G  自动缩进

  7、撤销  u

  8、进入块选择模式   ctrl+v

  9、在vim中执行shell命令 :!  cmd

  10、打开多个窗口

           打开分割窗口 :sp   filename    或 vsp   filename

           切换窗口 Ctrl + w    按一次加上下键可以自己选择切换方向

                                              按两次则从上到下自动遍历窗口

            扩大窗口 Ctrl-w +

            缩小窗口 Ctrl-w -

            放大当前窗口,缩小其他窗口 :res

                                                                  后面可以设置行数, :res 20 则将当前窗口设置为20行

*******************************************

解析:

一:.vimrc 复制到家目录下   (putty下支持鼠标复制)

二:修改vim配置 /etc/vim/vimrc
set nocompatible       不使用vi默认键盘布局,如果不配置,在编辑模式下按方向键会输入字符。
set nu                显示行号

set showmatch          括号匹配模式
set ruler              显示状态行    
set tabstop=4          tab键为4个空格
set shiftwidth=4
set softtabstop=4
syntax on        语法高亮

set cindent            C语言格式对齐
set autoindent         自动对齐
set smartindent        智能对齐

**********************************************

添加部分:

set nocompatible
set nu
set autoindent
set showmatch
set ruler
set tabstop=4
set shiftwidth=4
set softtabstop=4
set cindent
syntax on

********************************

putty复制实现

set nu
set nocp
syntax on
if has('mouse')
 set mouse-=a
endif

set ru
set fileencodings=utf-8,gbk,ucs-bom,cp936

 

抱歉!评论已关闭.