raquant
V2EX  ›  Vim

vim 干货

  •  
  •   raquant · Mar 19, 2017 · 7866 views
    This topic created in 3341 days ago, the information mentioned may be changed or developed.

    基础篇

    • :e filename Open filename for edition
    • :w Save file
    • :q Exit Vim
    • :q! Quit without saving
    • :x Write file (if changes has been made) and exit
    • :sav filename Saves file as filename
    • . Repeats the last change made in normal mode
    • 5. Repeats 5 times the last change made in normal mode
        提醒你一下,
    
        :e filename 可以打开多个文件,切换方法为 ctrl+shift+^
    
        再提醒你一下,
    
        :e .   可以看看当前目录有哪些东西
    

    在文件中移动

    • k or Up Arrow move the cursor up one line
    • j or Down Arrow move the cursor down one line
    • e move the cursor to the end of the word
    • b move the cursor to the begining of the word
    • 0 move the cursor to the begining of the line
    • G move the cursor to the end of the line
    • gg move the cursor to the begining of the file
    • L move the cursor to the end of the file
    • :59 move cursor to line 59. Replace 59 by the desired line number.
    • 20| move cursor to column 20.
    • % Move cursor to matching parenthesis
    • [[ Jump to function start
    • [{ Jump to block start
        提醒你一下,
    
        ctrl+b,ctrl+e,ctrl+f 都可以试一试哦
    

    剪切、复制和粘贴

    • y Copy the selected text to clipboard
    • p Paste clipboard contents
    • dd Cut current line
    • yy Copy current line
    • y$ Copy to end of line
    • D Cut to end of line
        提醒你一下,
    
        还可以 3yy,复制 3 行
    
        再提醒一下,使用标记可以复制一个范围的,比如挪到某行 ma  另外一行 mb
    
        然后:'a,'by  可复制 a 到 b 直接的内容
    

    搜索

    • /word Search word from top to bottom
    • ?word Search word from bottom to top
      • Search the word under cursor
    • /\cstring Search STRING or string, case insensitive
    • /jo[ha]n Search john or joan
    • /< the Search the, theatre or then
    • /the> Search the or breathe
    • /< the> Search the
    • /< ¦.> Search all words of 4 letters
    • // Search fred but not alfred or frederick
    • /fred|joe Search fred or joe
    • /<\d\d\d\d> Search exactly 4 digits
    • /^\n{3} Find 3 empty lines
    • :bufdo /searchstr/ Search in all open files
    • bufdo %s/something/somethingelse/g Search something in all the open buffers and replace it with somethingelse
        没看明白?
        /\<the\> 只选 the 这个单词
    

    替换

    • :%s/old/new/g Replace all occurences of old by new in file
    • :%s/onward/forward/gi Replace onward by forward, case unsensitive
    • :%s/old/new/gc Replace all occurences with confirmation
    • :2,35s/old/new/g Replace all occurences between lines 2 and 35
    • :5,$s/old/new/g Replace all occurences from line 5 to EOF
    • :%s/^/hello/g Replace the begining of each line by hello
    • :%s/$/Harry/g Replace the end of each line by HarryI
    • :%s/onward/forward/gi Replace onward by forward, case unsensitive
    • :%s/ *$//g Delete all white spaces
    • :g/string/d Delete all lines containing string
    • :v/string/d Delete all lines containing which didn ’ t contain string
    • :s/Bill/Steve/ Replace the first occurence of Bill by Steve in current line
    • :s/Bill/Steve/g Replace Bill by Steve in current line
    • :%s/Bill/Steve/g Replace Bill by Steve in all the file
    • :%s/^M//g Delete DOS carriage returns (^M)
    • :%s/\r/\r/g Transform DOS carriage returns in returns
        可能有的人找这种删除命令很久了
        :g/string/d
    
    43 replies    2017-03-20 20:05:40 +08:00
    wangxn
        1
    wangxn  
       Mar 19, 2017 via Android
    都是最基本的啊
    sagaxu
        2
    sagaxu  
       Mar 19, 2017
    干货在哪里?
    raquant
        3
    raquant  
    OP
       Mar 19, 2017
    @wangxn 哈哈,先上基础的
    raquant
        4
    raquant  
    OP
       Mar 19, 2017
    @sagaxu 干货随后来,不是每个人都像你这么厉害的
    zhangchioulin
        5
    zhangchioulin  
       Mar 19, 2017
    收藏观望
    LittleKey
        6
    LittleKey  
       Mar 19, 2017 via Android
    好像有错的。。
    Remember
        7
    Remember  
       Mar 19, 2017
    这是给你自己自学用的吧,不用发论坛了
    vcfvct
        8
    vcfvct  
       Mar 19, 2017 via Android
    @Remember 发出来也不错,大家醒查一下自己有什么没有掌握的,查漏补缺嘛
    zerofiny
        9
    zerofiny  
       Mar 19, 2017
    多 tab 及切换
    :tabnew
    :e filename 正常模式下 gt 进行切换

    多行删除前几个字符或者追加几个字符
    正常模式下 ctrl + v 选中多行开头几个字符 delete 删除

    多行最前面追加相同的字符
    正常模式下 ctrl + v 选中多行最开头 Shift +i 写入字符 ESC 完成选择位置追加字符

    执行系统命令
    :!ls 命令前面加!
    aristotll
        10
    aristotll  
       Mar 19, 2017
    比较干...
    U7Q5tLAex2FI0o0g
        11
    U7Q5tLAex2FI0o0g  
       Mar 19, 2017
    会 vim 的人这些基本都会了吧。。。
    greyterry
        12
    greyterry  
       Mar 19, 2017
    。。。。。这种贴应该支持还是
    freshmanc
        13
    freshmanc  
       Mar 19, 2017 via Android
    感觉做完 tutorial 这些也…
    rashawn
        14
    rashawn  
       Mar 19, 2017 via iPhone
    有的功能基本不会用到 被效率更高的插件代替了
    colorwin
        15
    colorwin  
       Mar 19, 2017
    刚入门 vim 的表示还是有帮助的
    shidenggui
        16
    shidenggui  
       Mar 19, 2017
    学到了 D 和 search 的几个用法, 挺有用的
    myself659
        17
    myself659  
       Mar 19, 2017
    还不余我上传一张图
    mingyun
        19
    mingyun  
       Mar 19, 2017
    网上有个 vim 小抄 挺全的
    raquant
        20
    raquant  
    OP
       Mar 19, 2017
    @myself659 贵在整理啊
    mintist
        21
    mintist  
       Mar 19, 2017
    不错,学习了,谢谢楼主整理,又过了一遍,,,
    mintist
        22
    mintist  
       Mar 19, 2017
    其实,不太明白一些缩写的含义,如 y 为什么是 Copy the selected text to clipboard

    p 是 paste 还好理解点
    binux
        23
    binux  
       Mar 19, 2017
    LZ ,在菜市买的干货虽然也叫干货,但是和我们平时说的干货还是不一样的。
    raquant
        24
    raquant  
    OP
       Mar 20, 2017
    @binux 谢谢,真好,让我了解到 vim 版的强大,逼迫自己提高要求了
    raquant
        25
    raquant  
    OP
       Mar 20, 2017
    @mintist y 可能是 yank 的缩写啊
    will0404
        26
    will0404  
       Mar 20, 2017
    纠正一下。
    G 是移动到文件最底部。
    L 是移动到屏幕最底部。
    ldbC5uTBj11yaeh5
        27
    ldbC5uTBj11yaeh5  
       Mar 20, 2017
    大兄弟,给你看一个 14 年的文章, https://dougblack.io/words/a-good-vimrc.html 也比你的干货要干啊。
    xiaket
        28
    xiaket  
       Mar 20, 2017
    v2 不欢迎全文转载的.
    defunct9
        29
    defunct9  
       Mar 20, 2017 via iPhone
    湿答答的
    allotory
        30
    allotory  
       Mar 20, 2017 via Android
    其实还好吧,大家不要这样打击人。。。
    97dog
        31
    97dog  
       Mar 20, 2017
    很基本呀
    gejigeji
        32
    gejigeji  
       Mar 20, 2017
    骗点击的感觉
    irenicus
        33
    irenicus  
       Mar 20, 2017
    用于替代记事本,写字板, gedit , kwrite 的话,这些够用了
    半导体行业,我大部分同事也就止步于这里的 80%
    我下功夫学 perl 和 vim ,属于另类。。。
    BFDZ
        34
    BFDZ  
       Mar 20, 2017
    这货不干,整理的也不好,看起来没条理。这篇才是真正的干货 http://coolshell.cn/articles/5426.html
    Antidictator
        35
    Antidictator  
       Mar 20, 2017
    @BFDZ 额, 10 分钟前我看过,现在又看到你发了。。
    BFDZ
        36
    BFDZ  
       Mar 20, 2017
    @Antidictator #35 我的 vim 技能基本上是看这篇教程入门和进阶的,所以碰到说 vim 我就会推这篇教程
    chinese_zmm
        37
    chinese_zmm  
       Mar 20, 2017 via Android
    vim cheatsheet 应该很多
    lococo
        38
    lococo  
       Mar 20, 2017
    潮到出水
    psklf
        39
    psklf  
       Mar 20, 2017
    哈哈 菜市场的干货
    andysheng
        40
    andysheng  
       Mar 20, 2017
    不如 vimtutor
    Antidictator
        41
    Antidictator  
       Mar 20, 2017
    @BFDZ 哈哈哈,所以我说经典
    ROG
        42
    ROG  
       Mar 20, 2017
    mark 看干货
    liuenyan
        43
    liuenyan  
       Mar 20, 2017
    还是推荐看《 vim 使用技巧》这本书吧。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1047 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 135ms · UTC 18:31 · PVG 02:31 · LAX 11:31 · JFK 14:31
    ♥ Do have faith in what you're doing.