zoukankan      html  css  js  c++  java
  • 学习使用Vim(一)

       今天下定决心要逐渐脱离IDE的“comfortable zone”,学习使用Vim。以前偶尔使用Vim的经历都是很痛苦的,觉得各种不方便和命令复杂难懂。但既然那么多书都推荐使用Vim来浏览纯文本,我想一定是有道理的。我想记录下自己从对Vim一窍不通开始学习的历程,也是对自己的一种鞭策吧。


        在baidu上搜索“Vim 入门”,各种资料很多,但很多让人忘而生畏。Vim的各种命令,如果硬记或者其然不知其所以然,实在是事倍功半。我想找一个像游戏入门那样有趣,基础然后又覆盖面足够的教程。最后发现远在天边近在眼前:

        vimtutor。

       

        2015-01-29

       vimtutor教程中有两句话,我觉得特别有用:

        “特别提示:在您浏览本教程时,不要强行记忆。记住一点:在使用中学习。

        ”特别提示:切记您要在使用中学习,而不是在记忆中学习。“

        我觉得这正是以前尝试学习Vim总是半途而废的原因一看各种命令和文档就头大,没怎么实际使用就觉得自己肯定学不好,或者断定这种古老复杂的工具没有学习意义。但本质上Vim只是一种工具,就像木匠的工具一样,把说明书背得熟练也是没有用的,必须实际使用。

        所以我的计划是,在初期,一方面是反复练习vimtutor中的基础知识,另一方面是尽量使用Vim来完成日常工作,首要的就是看android的log文件和写博客。


        2015-02-02          Vimtutor 学习笔记
    一  知识结构
        一共八讲:
        第一讲: 

                 移动光标  h、j、k、l;
                  VIM的进入和退出  :q!   :wq
                  删除单个字符  x
                  插入  i
        第二讲: 

                 删除类命令  dw删除单词,会删除单词后的空格
                  其他删除类命令  d$删除至行尾
                  命令和对象  [number] d object 或者 d [number] object  w、e、$
                  对象命令的特殊情况  dd   ndd
                  撤销类命令  u  U  CTRL-R
        第三讲: 

                 插入类命令  p将最后一次删除的内容插入光标之后
                  替换类命令  r和一个字符替换光标位置字符
                  更改类命令  cw更改一个单词
                  使用c的其他更改命令  [number] c object 或者  c [number] object   

       第四讲: 

                 定位及文件状态   CTRL-g、  SHIFT-G、   行号 SHIFT-G
                  搜索类命令   /、  ?、  n、  SHIFT-N
                  配对括号的查找  %
                  修正错误的方法之一   :s/old/new、:s/old/new/g、:#,#s/old/new/g
                  更多修正错误的方法   :%s/old/new/g、:%s/old/new/gc
        第五讲:  

                 在VIM内执行外部命令   :!
                  保存文件  :w FILENAME
                  保存部分内容  :#,# w FILENAME
                  提取和合并文件  :r FILENAME
        第六讲: 

                 打开类命令   o  SHILF-O
                  光标后插入类命令  a  SHIFT-A
                  另一个替换类命令  SHIFT-R
                  设置类命令的选项  :set ic   :set hls is
        第七讲: 

                 在线帮助命令  :help w
                                         :help c_<T
                                         :help insert-index
                                         :help user-manual
        第八讲:

                 创建一启动脚本 :edit ~/.vimrc
                                                :read $VIMRUNTIME/vimrc_exmaple.vim
                                                :write
        书籍推荐:VIM-Vi Improved


    二  基本命令的解释

        :q  :quit   Quit the current window. Quit Vim if this is the last window.
        :w  :write  Write the whole buffer to the current file. This is the normal way to save changes to a file.
        x   Delete characters under and after the cursor(into register x).
        i   Insert text before the cursor (count) times.


        d   Delete text that motion moves over into register x.
        w   words forward. exlusive motion.
        $ or <END>   To the end of the line.
        e   Forward to the end of the word incluseve.
        u   Undo changes.
        U   Undo all latest changes on one line.
        CTRL-R   Redo changes which were undone.

     
        p   Put the text after the cursor.
        r   Replace the character under the cursor.
        c   Delete text and start insert.
        

        CTRL-g   Prints the current file name, the cursor position, and the file status.
        SHIFT-G  Goto line, default last line.
        /   Search forward for the occurrence of pattern exclusive.
        ?   Search backward for the previous occurrence of pattern exclusive.
        n   Repeat the latest "/" or "?".
        N   Repeat the latest "/" or "?" in opposite direction.
        %   Find the next item in this line after or under the cursor and jump to its match.
        :s  For each line in range, replace a match of pattern with string.


        :!cmd   Execute cmd with the shell.
        :r :read   Insert the file(defult:current file)below the cursor.



        o   Begin a new line below the cursor and insert text.
        O   Begin a new line above the cursor and insert text.
        a   Append text after the cursor.
        A   Append text at the end of the line.
        R   Enter Replace mode:Each character you type replaces an existing character, starting with the character under the cursor.
        :set   Show all options that differ from their default value.
        ic/ignorecase   Ignore case in search patterns.
        hls/hlsearch   When there is a previous search pattern, highlight all its matches.


    三 练习vimtutor的感

       练习几遍vimtutor之后,对使用vim的畏惧感已经没有了。在实际使用中,已经初步感受到了vim的便利性。在阅读几万到十几万行的android日志文件的过程中,使用vim确实比用gedit要便捷得多,也更利于工作过程中精神的专注。

        在<<禅与摩托车维修艺术>>这本书中,作者说, 大部分复杂工具的说明书都不是写给人看的,技术的开发者对于技术本身即不专注,也无热情。而vim的手册,给我的感觉是一个很好的反例,不光人性化,而且是在将复杂的东西简约化,让我这样的初学者也能很好的使用,极大增强了我对于学好vim的信心。

        所以下一步,我决定依然依靠vim自身提供的user-manual,希望能了解vim更多的使用技巧和特性。          

  • 相关阅读:
    在搜索引擎中输入汉字就可以解析到对应的域名,请问如何用LoadRunner进行测试。
    面向对象
    三种循环结构语句
    JAVA复习题(一)基础知识
    JVM快速入门(上)
    count(*) 优化
    .jquery中$.get()提交和$.post()提交有区别吗?
    window.onload()函数和jQuery中的document.ready()有什么区别?
    假设有一个文本框要求输入10个字符的邮政编码,对于该文本框应该怎样划分等价类?
    软件测试项目从什么时候开始,?为什么?
  • 原文地址:https://www.cnblogs.com/yuanchongjie/p/4448386.html
Copyright © 2011-2022 走看看