vi入门

1. cursor operation

   1.1 arror keys

   1.2 hjkl keys

   1.3 0   move the cursor to the start of the line.

   1.4 e   move the cursor to the end of a word

 

2. exit

   2.1 :q!   trash all the changes

   2.2 :wq   save the changes

 

3. delete

   3.1 x    delete 1 character at the cursor

   3.2 dw   delete from the cursor up to the next word

   3.3 d$   delete from the cursor to the end of a line

   3.4 dd   delete a whole line

 

4. insert

   4.1 i    insert before the cursor

 

   4.2 a    insert text AFTER the cursor

   4.2 A    insert text AFTER the end of the line.

  

   4.3 o    open a line BELOW the cursor and startinsert mode

   4.4 O    open a line ABOVE the cursor and startinsert mode

 

5. undo

   5.1 u    undo the previous actions

   5.2 U    undo all the changes on a line

   5.3 CTRL-R  undo the undo's

 

6. select/copy/paste

   6.1 v    Visually selected lines

   6.2 y    yanks(copies) text where selected by v

   6.3 p    pastes the text after the cursor

            6.3.1paste the text that has just been deleted(pls refer 3.delete)

            6.3.2 paste the text that has just beencopied(by y)

 

7. change

   7.1 ce   change from the cursor to the end of theword

   7.2 c$   change to the end of a line

 

8. replace

   8.1 r    replace the character under the cursor

 

9. line num

   9.1 CTRL-G    displays your location in the file

   9.2 G         moves to the end of the line

   9.3 gg        moves to the first line

   9.4 number G  moves to that line num

 

10. search

   10.1 /xxx     searches FORWARED for the "xxx"

   10.2 ?xxx     searches BACKWARD for the "xxx"

 

   10.3 n        find the next occurrence in the SAMEdirection

   10.4 N        find the next occurrence in theOPPOSITE direction

 

11.substitute

   11.1:s/old/new       substitute new for theFIRST old in a line

   11.2:s/old/new/g     substitute new for all 'old's on a line

   11.3:#,#s/old/new/g  substitute phrasesBETWEEN two line #'s

   11.4:%s/old/new/g    substitute ALLoccurrences in the file

   11.4:%s/old/new/gc   ask for confirmationeach time when substituting

 

12. match(,),[,],{, or }

  12.1 %   if the cursor is on a (,),[,],{, or }, thengoes to its match

 

13. retrieve

    13.1  :r FILENAME   retrieve disk file FILENAME and puts it below the cursor position

    13.2  :r!COMMAND    read the output of the COMMAND and puts it below the cursor position

                        eg: :r!ls

 

14. write

    14.1  :w FILENAME              writes the current Vim file todisk name FILENAME

    14.2  v motion :w FILENAME     saves the Visually selected lines in fileFILENAME

 

15. executes external command

    15.1  :!command     executes an external command

                        eg: :!ls

 

16. Set options

    16.1  :set xxx      set the option "xxx"   

          some optionsare:

          'ic'  'ignorecase' ignore upper/lower case when searching

          'is'  'incsearch'  show partial matches for a search phrase

          'hls''hlsearch'    highlight all matachingphrases

    16.2  :set noxxx    swith off an option "xxx", eg: :set noic

 

Option

Abbrev.

Default

Effect When Set

all

~

~

Lists all editor options on the screen.

autoindent

ai

noai

Begins each new line of text in the same column as the previous line (useful for programmers).

ignorecase

ic

noic

Causes vi to ignore uppercase and lowercase during searches.

number

nu

nonu

Numbers each line of text.

readonly

~

noreadonly

Enables write protection on the file you are editing. This ensures that you don't accidentally change or destroy the file's contents.

showmatch

sm

nosm

Shows the opening parenthesis, brace, or bracket when you type the corresponding closing parenthesis, brace, or bracket. This option is useful when you are typing mathematical expressions or writing programs in a language that uses parentheses, braces, or brackets.

showmode

~

noshowmode

Displays a message like "INPUT MODE" or "REPLACE MODE" at the bottom of the screen whenever you are in either of these modes.

wrapmargin

wm

wm=0 (zero)

Changes the right margin. n equals the number of spaces in the right margin. For example, if you're using an 80-column terminal, then :set wm=8 sets the right margin at column 72.

 

17 command format: operator [number] motion

   17.1 operator -iswhat to do. included as following:

        'd'   delete

        'c'   change

        'y'   yank(copy)

   17.2 [number] - isan optional count to repeat the motion

   17.3 motion   - moves over the text to operate on, suchas:

                  'w'(word),

                  '$'(to the end of line)

 

18 Making Your vi Environment Permanent

To avoid setting options or definingabbreviations or macros each time you enter vi, place all options and definitions you normally use into an.exrc file in your home directory. This file is read automaticallyeach time you enter vi and its contents make your customized vi environment permanent.

To create or change the .exrc file, follow these steps:

  1. Type cd at the HP-UX prompt to ensure that you're in your home directory; then use vi to create or edit the .exrc file:

  1.  

$ cd

  1.  

  1.  

  1.  

$ vi .exrc

  1.  

  1. Type the options, word abbreviations, and macros you want to make permanent (don't precede the commands with a colon ).
  2. Type :wq to save the text and exit vi.

After creating the .exrc file, you can access it whenever you want to change your vi environment. Any of the editor options discussed in theprevious section can be placed in this file.


 

行内快速跳转(命令模式下)
^ 将光标快速跳转到本行的首行字符
$ 将光标快速跳转到本行的行尾字符
nw 将光标快速跳转到当前光标所在位置的后n个单词的首字母
nb 将光标快速跳转到当前光标所在位置的前n个单词的首字母
nc 将光标快速跳转到当前光标所在位置的后n个单词的尾字母

 

你可能感兴趣的:(Linux/HPUX,behavior,delete,file,insert,character)