程序员都应该知道的130个vim命令

  次阅读 作者:智能小宝 来源:互联网 2016-01-19 12:44 我要评论(0)

从1970年开始,vi和vim 就成为了程序员最喜爱的文本编辑器之一。5年前,我写了一个问自己名为 每个程序员都应该知道的100个vim 命令这次算是之前那篇文章的改进版,希望你会喜欢。

基础

:e filename Openfilenamefor 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 asfilename . Repeats the last change made in normal mode 5. Repeats 5 times the last change made in normal mode

在文件中移动

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 line59. Replace59by the desired line number. 20| move cursor to column20. % Move cursor to matching parenthesis [[ Jump to function start [{ Jump to block start

剪切、复制和粘贴

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

搜索

/word Searchwordfrom top to bottom ?word Searchwordfrom bottom to top * Search the word under cursor /cstring SearchSTRINGorstring, case insensitive /jo[ha]n Searchjohnorjoan /< the Search the, theatre orthen /the> Searchtheorbreathe /< the> Searchthe /<.> Search all words of 4 letters // Searchfredbut notalfredorfrederick /fred|joe Searchfredorjoe /<dddd> Search exactly 4 digits /^{3} Find 3 empty lines :bufdo /searchstr/ Search in all open files bufdo %s/something/somethingelse/g Searchsomethingin all the open buffers and replace it withsomethingelse

替换

:%s/old/new/g Replace all occurences ofoldbynewin 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 byhello :%s/$/Harry/g Replace the end of each line byHarry :%s/onward/forward/gi Replaceonwardbyforward, case unsensitive :%s/ *$//g Delete all white spaces :g/string/d Delete all lines containingstring :v/string/d Delete all lines containing which didn t containstring :s/Bill/Steve/ Replace the first occurence ofBillbyStevein current line :s/Bill/Steve/g ReplaceBillbyStevein current line :%s/Bill/Steve/g ReplaceBillbyStevein all the file :%s/^M//g Delete DOS carriage returns (^M) :%s///g Transform DOS carriage returns in returns :%s#<[^>]+>##g Delete HTML tags but keeps text :%s/^(.*)1$/1/ Delete lines which appears twice Ctrl+a Increment number under the cursor Ctrl+x Decrement number under cursor ggVGg? Change text to Rot13

大小写

Vu Lowercase line VU Uppercase line g~~ Invert case vEU Switch word to uppercase vE~ Modify word case ggguG Set all text to lowercase gggUG Set all text to uppercase :set ignorecase Ignore case in searches :set smartcase Ignore case in searches excepted if an uppercase letter is used :%s/<./u&/g Sets first letter of each word to uppercase :%s/<./l&/g Sets first letter of each word to lowercase :%s/.*/u& Sets first letter of each line to uppercase :%s/.*/l& Sets first letter of each line to lowercase

读写文件

:1,10 w outfile Saves lines 1 to 10 inoutfile :1,10 w >> outfile Appends lines 1 to 10 tooutfile :r infile Insert the content ofinfile :23r infile Insert the content ofinfileunder line 23

文件浏览器

:e . Open integrated file explorer :Sex Split window and open integrated file explorer :Sex! Same as:Sexbut split window vertically :browse e Graphical file explorer :ls List buffers :cd .. Move to parent directory :args List files :args *.php Open file list :grep expression *.php Returns a list of .php files conteningexpression gf Open file name under cursor

和 Unix 系统交互

:!pwd Execute thepwdunix command, then returns to Vi !!pwd Execute thepwdunix command and insert output in file :sh Temporary returns to Unix $exit Retourns to Vi

本站文章信息来源于网络以及网友投稿,本站只负责对文章进行整理、排版、编辑,是出于传递更多信息之目的,并不意味着赞同其观点或证实其内容的真实性。如果您有什么意见或建议,请联系QQ28-1688-302!

人工智能实验室
相关文章相关文章
  • 未来两年人工智能要怎么走?看这篇就够了

    未来两年人工智能要怎么走?看这篇就够了

  • 英国研发“杀生”机器人 通过生命体获取能量

    英国研发“杀生”机器人 通过生命体获取能量

  • 无人驾驶汽车如何改变城市生活?听听他们怎么说

    无人驾驶汽车如何改变城市生活?听听他们怎么说

  • 韩春雨称已能重复实验结果 近期将有消息公布

    韩春雨称已能重复实验结果 近期将有消息公布

网友点评网友点评
阅读推荐阅读推荐

据国外媒体报道,在过去两年内,聊天机器人(chatbot)、人工智能以及机器学习的研发和采用取得了巨大进展。许多初创公司正利用人工智能和...

霍金 视觉中国 图 英国著名物理学家霍金(Stephen Hawking)再次就人工智能(AI)发声,他认为:对于人类来说,强大AI的出现可能是最美妙的...

文|郑娟娟 今年,人工智能(AI) 60岁了。在AI60岁的时候,笔者想要介绍一下AI100,一个刚刚2岁的研究项目,但它的预设寿命是100年,甚至更长...

AlphaGo与李世石的人机大战,为大众迅速普及了人工智能的概念。 但对谷歌而言,除了下围棋,现在的人工智能进展到哪一步了?未来,人工智能...