• Vim编辑器-Text Blocks and Multiple Files


    4 Text Blocks and Multiple Files

    • Simple cut-and-paste operations (in Vim terms, delete and put)
    • Marking locations within the text
    • Copying text into a register using the yank commands
    • Filtering text
    • Editing multiple files

    • Cut, Paste, and Copy
      When you delete something with the d, x, or another command, the text is saved.You can paste it back by using the p command. (The technical name for this is a put).

    • Character Twiddling
      Frequently when you are typing, your fingers get ahead of your brain.The result is a
      typo such as teh for the.The Vim editor makes it easy to correct such problems. Just put the cursor on the e of teh and execute the command xp.

    • More on “Putting”
      You can execute the p command multiple times. Each time, it inserts another copy of the text into the file.
      The p command places the text after the cursor.The P command places the text before the cursor. A count can be used with both commands and, if specified, the text
      will be inserted count times.

    • Marks
      The Vim editor enables you to place marks in your text.The command ma marks the place under the cursor as mark a.You can place 26 marks (a through z) in your text. (You can use a number of other marks as well.)

    To go to a mark, use the command `mark, where mark is the mark letter.
    The command ‘mark (single quotation mark, or apostrophe) moves you to the beginning of the line containing the mark.This differs from the `mark command, which moves you to the marked line and column.
    

    The ‘mark command can be very useful when deleting a long series of lines.To delete a long series of lines, follow these steps:

    1. Move the cursor to the beginning of the text you want to delete.
    2. Mark it using the command ma. (This marks it with mark a.)
    3. Go to the end of the text to be removed. Delete to mark a using the command d’a.
      There is nothing special about doing the beginning first followed by the end.You could just as easily have marked the end, moved the cursor to the beginning, and deleted to the mark.
      One nice thing about marks is that they stay with the text even if the text moves (because you inserted or deleted text above the mark. Of course, if you delete the text containing the mark, the mark disappears.
    • Where Are the Marks?
      To list all the marks, use the following command: :marks

    • Yanking
      The shorthand yy yanks the current line into the buffer.
      (Note: Most other editors call this a “copy” operation.)
      Take a look at how you can use this command to duplicate a block of text. First go to the top of the text to be copied and mark it with ma.Then go to the bottom and
      do a y’a (yank to mark a).
      Now go to where the copied text is to be inserted and put it there using the p command.

    • Yanking Lines
      The Y command yanks a single line. If preceded by a count, it yanks that number of lines into the register.You might have expected Y to yank until the end of the line, like D and C, but it really yanks the whole line.

    • Filtering
      The !motion command takes a block of text and filters it through another program. In other words, it runs the system command represented by command, giving it the block of text represented by motion as input.The output of this command then replaces the selected block.
      You want to sort lines 1 through 10 of a file.You start by putting the cursor on line 1. Next you execute the following command:
      !10Gsort<Enter>
      The !! command runs the current line through a filter. (I have found this a good way to get the output of system commands into a file.)
      !!ls !!date

    Using !! like this is technically not filtering because commands like ls and date don’t read standard input.

    • Editing Another File
      Suppose that you have finished editing one file and want to edit another file.The sim-
      ple way to switch to the other file is to exit Vim and start it up again on the other file. Another way to do so is to execute the following command:
      :vi file
      :write
      :vi! file.txt

    • The :view Command
      The following command works just like the :vi command, except the new file is opened in read-only mode:
      :view file

    • Dealing with Multiple Files
      $ gvim one.c two.c three.c
      To edit the next file:next
      :wnext write and next
      :next! you will lose those changes
      Finally, there is the ‘autowrite’ option. If this option is set, Vim will not issue any No write... messages. Instead, it just writes the file for you and goes on.To turn this option on, use the following command:
      :set autowrite
      To turn it off, use this command: :set noautowrite

    • Which File Am I On?
      :args

    • Going Back a File
      :previous or :Next
      If you want to write the current file and go to the previous one, use either of the following commands:
      :wprevious :wNext

    • Editing the First or Last File
      :rewind or :first edit the first file
      :last edit the last file

    • Editing Two Files
      By pressing CTRL-^, you can switch editing from the current file to the alternate file.

    When you first start editing (file one.c) and press CTRL-^, you will get an error message: No alternate file. Remember the alternate file is the last file you just edited before this one (in this
    editing session). Because one.c is the only file edited, there is no previous file and therefore the error message.

    Super
  • 相关阅读:
    SharePoint 中AJAX请求报错
    SharePoint Online 站点启用内容编辑器部件
    SharePoint 表单开发常用脚本[不断更新ing]
    SharePoint Online 工作流添加历史记录
    BBC评出的100本最具影响力经典书籍
    描写人物的成语汇总,请为孩子收藏!
    失传已久,1917年的满分作文,惊现于世!
    MySQL用户及权限
    数据库SQL优化大总结之 百万级数据库优化方案(转载)
    3分钟弄懂中国金融体系
  • 原文地址:https://www.cnblogs.com/chao8888/p/15374734.html
Copyright © 2020-2023  润新知