raquant
V2EX  ›  Vim

vim 干货

  •  
  •   raquant · Mar 19, 2017 · 8526 views
    This topic created in 3524 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
    wangxn
    Mar 19, 2017 via Android
    1
    都是最基本的啊
    sagaxu
    sagaxu
    Mar 19, 2017
    2
    干货在哪里?
    raquant
    raquant
    OP
    Mar 19, 2017
    3
    @wangxn 哈哈,先上基础的
    raquant
    raquant
    OP
    Mar 19, 2017
    4
    @sagaxu 干货随后来,不是每个人都像你这么厉害的
    zhangchioulin
    zhangchioulin
    Mar 19, 2017
    5
    收藏观望
    LittleKey
    LittleKey
    Mar 19, 2017 via Android
    6
    好像有错的。。
    Remember
    Remember
    Mar 19, 2017
    7
    这是给你自己自学用的吧,不用发论坛了
    vcfvct
    vcfvct
    Mar 19, 2017 via Android
    8
    @Remember 发出来也不错,大家醒查一下自己有什么没有掌握的,查漏补缺嘛
    zerofiny
    zerofiny
    Mar 19, 2017
    9
    多 tab 及切换
    :tabnew
    :e filename 正常模式下 gt 进行切换

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

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

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

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