ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

Vim编辑器-Editing a Little Faster

2021-10-04 11:36:46  阅读:225  来源: 互联网

标签:Little Faster character cursor command words line Editing deletes


2 Editing a Little Faster

  • Additional movement commands
  • Quick searches along a single line
  • Additional delete and change commands n The repeat command
  • Keyboard macros (how to record and play back commands)
  • Digraphs

  • Word Movement
    Let’s start with movement.To move the cursor forward one word, use the w command.
    The b command moves backward one word. Like most Vim commands, you can use a numeric prefix to move past multiple words. For example, 4b moves back four words.

  • Moving to the Start or End of a Line
    The $ command moves the cursor to the end of a line.
    1$ moves you to the end of the first line (the one you’re on), 2$ to the end of the next line, and so on.
    The ^ command moves to the first nonblank character of the line

  • Searching Along a Single Line
    The command fx (forward search) searches the line for the single character x.
    therefore, you can space forward five words by using the command 5f:. Note: this only moves five space characters, not five words. If there are multiple spaces between words, this will not move five words!
    The F command searches to the left.
    The tx (search ‘til) command works like the fx command, except it stops one char-
    acter before the indicated character.The backward version of this command is Tx.
    Sometimes you will start a search, only to realize that you have typed the wrong com- mand.You type f to search backward, for example, only to realize that you really meant F.To abort a search, press as the search key. So f is an aborted for- ward search. (Note: cancels most operations, not just searches.)

  • Moving to a Specific Line
    G command: 3G puts you on line 3,
    With no argument, it positions you at the end of the file.
    gg, it positions you at the begin of the file.

  • Telling Where You Are in a File
    :set number
    To turn it on, use this command:
    :set nonumber

  • Where Am I?
    The CTRL-G command displays a status line that indicates where you are in the file. For example:
    “c02.txt” [Modified] line 81 of 153 —52%— col 1
    This indicates that you are editing a file called c02.txt, and that it has been modified since the editing started.The cursor is positioned on line 81 out of a total of 153, or about 52% of the way through the file.The cursor is currently sitting in column 1.

  • Scrolling Up and Down
    The CTRL-U command scrolls up half a screen of text.
    The CTRL-D command scrolls you down half a screen.

  • Deleting Text
    The dw command deletes a word.
    The d3w com- mand deletes three words.
    In fact, the d command may be followed by any motion command, and it deletes from the current location to the place where the cursor winds up. (Therefore, we say the syntax of the d command is d motion.)
    The $ command moves to the end of a line.The d$ command deletes from the cursor to the end of the line, as seen in Figure 2.11. A shortcut for this is the D command.

  • Where to Put the Count (3dw or d3w)
    The commands 3dw and d3w delete three words. If you want to get really picky about things, the first command, 3dw, deletes one word three times; the command d3w deletes three words once.This is a difference without a distinction.
    You can actually put in two counts, however (for example, 3d2w).This command deletes two words, repeated three times, for a total of six words.

  • Changing Text
    The c command changes text. It acts just like the d command, except it leaves you in insert mode.
    For example, cw changes a word. Or more specifically, it deletes a word and then puts you in insert mode.
    the cw and dw commands.Whereas cw deletes the text up to the space following the word (and then enters insert mode), the dw command deletes the word and the space following it.

  • The . Command
    It repeats the last delete or change command. For instance, suppose you are editing an HTML file and want to delete all the <B> tags.You position the cursor on the first < and delete the <B> with the command df>.You then go to the < of the next </B> and kill it using the . command.

  • Joining Lines
    The J command joins the current line with the next one. A space is added to the end of the first line to separate the two pieces that are joined. 3J

  • Replacing Characters
    The rx command replaces the character under the cursor with x.
    The r command can be preceded with a count, indicating the number of charac- ters to be replaced.
    Be careful where you place the count.The 5rx command replaces five characters with
    the character x, whereas r5x replaces the character under the cursor with 5 (r5) and then deletes a character (x).

  • Changing Case
    The ~ command changes a character’s case. It changes uppercase to lowercase and vice versa. If a count is specified, the count characters are changed. Figure 2.17 contains examples.

  • Keyboard Macros
    The . command repeats the preceding change. But what if you want to do something more complex than a single change?
    The qcharacter command records keystrokes into the register named character. (The char-
    acter must be between a and z.)
    To finish recording, just type a q command.You can now execute the macro by
    typing the @character command. (This can be preceded by a count, which will cause the macro to be executed that number of times.)
    Take a look at how to use these commands in practice.You have a list of filenames that look like this:

stdio.h
fcntl.h 
unistd.h 
stdlib.h

And what you want is the following: #include “stdio.h”

#include “fcntl.h”
#include “unistd.h”
#include “stdlib.h”

qa ^ i#include “<Esc> $ a”<Esc> j q

  • Digraphs
    Some characters are not on the keyboard—for example, the copyright character (©). To type these letters in Vim, you use digraphs, where two characters represent one.To enter a ©, for example, you type CTRL-Kc0.

标签:Little,Faster,character,cursor,command,words,line,Editing,deletes
来源: https://www.cnblogs.com/chao8888/p/15366022.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有