第六天 :Vim 编辑器和使用技巧

小Q:做任何事,不要想当然的去期望,否则只能得到无尽的失望;

            昨天对某件事期望太大了,耽误了多半天,却换来了更深的失望,呵呵。

               收回那期待的心,步入正轨吧,毕竟这才是正事。

 

Vim 全屏幕编辑器:

             三种模式:命令模式      编辑模式       插入模式

             命令大全:vim / vi                            进入编辑

                    插入:    a                                 在光标字符后插入

                                  A                                 在光标行尾插入

                                  i                                   在光标字符前插入          *

                                  I                                  在光标行首插入

                                  o                                  在光标下插入新行           *

                                  O                                  在光表上插入新行

                    命令:   :set  nu                        设置行号                        *

                                 :setnonu                       取消行号

            (不用           gg                                   跳到第一行                     *

               写冒号)     G                                    跳到最后一行                  *     

                                 nG                                   跳到第n行

                                 :n                                  跳到第n行                      *

                                 $                                     跳到行尾

                                 0                                      跳到行首

                     删除:  x                                      删除光标所在字符

                                 nx                                    删除光标后n个字符        *

   (有时输入后会      dd                                    删除光标所在行

    自动转插入模式)  ndd                                  删除所在之后n行           *

                                 dG                                    删除所在行至文件尾

                                 D                                      删除所在行至行尾

                                 :n1,n2d                              删除指定范围行           *

                复制剪切: yy                                     复制当前行                 *

                                  nyy                                   复制当前n行

                                  dd / ndd                           剪切当前行/n行          *

                                  p                                       粘贴到光标行下          *

                                  大P                                    粘贴到光标行上

                替换取消:  r                                       替换光标处单个字符

                                   R                                      从光标处开始替换,esc结束*

                                  u                                      取消上一步操作             *

                      搜索:  /string                             搜索string字符串          *

                                   n                                      转像搜索的下一个字符  *

                                  :%s/old/new/g                  全文new替换old            *

                                  :n1,n2s/old/new/g             指定范围替换                *

                 保存退出: :w                                   仅保存                         *

                                   :w   文件名                      另存为指定文件           *

                                   :wq                                  保存并退出                 *

                                   ZZ                                     保存并退出

                                   :q!                                 不保存退出

                                   :wq!                               强制保存退出             *

 

vim使用技巧:

              技巧:  r    文件名                    将文件名中内容导入

                      : ! which  命令               查找命令所在位置

                                  : r  ! 命令                       把命令执行结果导入

                                  : map  ctrl+v+b  0x           删除注释

                定义快捷: : map  ctrl+v+p  命令组合    按ctrl+v+p直接实现

                                  : n1,n2s/^/#/g                   连续行注释

                                  : n1,n2s/#/ /g                    去掉注释

                                  : n1,n2s/^字符/  /g              删除行首字符

                                  : n1,n2s//\/\/  /g               用//注释

                       替换: ab  替换者   被替换者           输入替换者回车即可

 

好:

http://www.cnblogs.com/softwaretesting/archive/2011/07/12/2104435.html 


   有时可以直接修改配置文件,只要进入文件编辑,就可以执行。

 

   文件位置:  root用户    /root/vim.rc

                      普通用户     /home/用户名/vim.rc       

 

 

你可能感兴趣的:(linux)