'Vi Editor'에 해당되는 글 1건

  1. 2008.08.07 Chapter 6. Vi 편집기
2008. 8. 7. 21:37

Chapter 6. Vi 편집기

Chapter 6.  Vi Editor

________________________

 

screen-oriented(visual) display editor based on ex

 

(1). vi 편집기의 특징(Visual Editor Characteristic)

 

- 전체 화면 모드 편집기(Full Screen Editor, Visual Editor)

- ex 편집기의 기능 확장 편집기(vi editor based on ex.)

 

[참고] /root/docs/Fundamental/Ref_vi_example.txt

 

 

 

(2). vi  편집기 실행하기

 

# vi  (: w filename)

# vi filename

# vi -r  filename (recovery)   // 복구 모드

# vi L                       // 리스트 찾기 , 에러난 파일

# vi +38 filename             // 수정 작업을 38(특정)라인에서 바로 시작할 때!

 

     -L    Lists the name of all files saved as the result of  an

          editor or system crash.

 

     -r filename

          Edits  filename  after  an  editor  or  system  crash.

          (Recovers  the  version  of  filename  that was in the

          buffer when the crash occurred.)

 

[EX] vi -r filename 형식의 예

# mailx

..... (중략) .....

A copy of an editor buffer of your file "/etc/vfstab" was saved on solaris254

when the system went down.

This buffer can be retrieved using the "recover" command of the editor.

An easy way to do this is to give the command "vi -r /etc/vfstab".

This works for "edit" and "ex" also.

 

 

[EX] vi -L 형식의 예

# vi -L

/usr/preserve/root:

On   1 01 at 09:00, saved 0 lines of file ""

On   1 17 at 12:27, saved 61 lines of file "/.kshrc"

On   2 15 at 10:13, saved 21 lines of file "/etc/dfs/dfstab"

On   1 31 at 19:48, saved 11 lines of file "/tmp/crontabVwaWPh"

/var/tmp:

No files saved.

 

 

 

(3). vi  Mode 변경

 

- Command Mode (ESC Mode), Edit Mode

- Input/Insert Mode

- Last Line Mode(Ex Mode)

 

 

<Command Mode>  ----- (i, a, o, I, A, O) -----> <Input Mode>

   A   |        <---- (    ESC         ) ------

   |   |

   |   |

   |   +------------- (<Shift+:>, /, ? ) -----> <Last Line Mode>

  +----------------- (    Enter       ) ------

  

* insert, append, open line

 

              [그림] vi 편집기 모드 변환

 

 

 

(4). Command Mode

(4.1) Move

- h, j,  k, l                // 상하좌우 커서이동

- b, w                       // b : back word 이동 , w : word 이동

- 0(^),  $                   // $ : 라인끝 이동  0(^) : 현재행의 처음으로~

- Ctrl+F / Ctrl+B          // 페이지단위 이동

 

- G, 1G, 10G               // nG    : n행으로 이동

- :5, :10                  //  n  : n행으로 이동

 

 

 

(4.2) Delete

- x, dd(=D), 3dd(=3D)      // x : 현재커서의 한글자 삭제

- :1,3d                    // 1 ~ 3 라인 삭제

- dw                       // 한 단어 삭제

- d0, d$          // d0 : 현재커서에서 라인 처음까지 삭제 , d$ : 현재커서에서 라인 끝가지 삭제

- dG                       // dG : 현재커서에서 문서의 마지막까지 삭제

- 3dd                      // 현재에서 3라인 삭제

- d1G                      // 현재에서 1라인까지 삭제

 

(4.3) Copy(Yank) & Paste

- yy(=Y), 3yy(3Y), p or    P                 // yy : 1라인 복사

- :1,3 co 5                                 // 1라인부터 3라인 까지 복사 5라인아래에 paste

- :1,3 m 5                                  // 1~ 3 까지 5라인 밑으로 move

 

 

 

(4.4) Search

- /New,  n or N                     // 탐색 결과에서 n -> 정방향 탐색 N -> 역방향 탐색

- ?New,  n or N                     // /pattern -> 현재에서 정방향탐색

                                   // ?pattern -> 현재에서 역방향 탐색

 

 

 


(4.5) Search & Replace

- :%s/Old/New/g               // %s   : search    ,  /g   : gloval  문서전체의~

                       // old 를 찾아 new로 치환

- :5,10s/Old/New/g     // 5~ 10 라인 ~  "

 

EX) : %s/Hello/HELLO/g

     1,$ => 5,10s/Hello/HELLO/g

     search

     globally => %s/Hello/HELLO/ , %s/Hello/HELLO/g

 

EX) :5,10s/^/#/

    :5,10s/^#//

 

    :5,10s/^/    / (4 blank character)

 

 

 

(4.6) Undo

- u, U            //실행 취소

 

 

 

(4.7) Join Line

- J               // 아래 라인을 현재 라인으로 붙여 준다.

 

 

 

(4.8) Replace

- r, R            // r : 현재커서의 한문자를 치환 , R : 현재커서부터 치환상태로

 

 

 

(4.9) Save & Quit

- :w              // 저장

- :w filename     // filename으로 저장

- :w!             // 강제저장

- :q              // 종료

- :q!             // 강제 종료

- :wq             // 저장 후 종료

- :wq!(root Use)  // 강제 저장 종료

- :!CMD           // vi 편집기 에서 쉘 명령어 실행

 

[참고] Save & Quit

- :x

- :wq

- ZZ

 

 

 


(5). vi  편집기의 환경 설정

 

(5.1). vi 편집기 사용시 환경설정

# vi filename

.....

: set                              // 현재 setting 목록

: set all                          // 설정할수 있는 모든 목록

: set number  (or :set nu)        // 라인넘버 부여

: set nonumber (or :set nonu)      // 번호 없앰

 

[EX] vi 편집기의 기능(:set all)

+- 기능이름---+--- number    --> : set number

|            +--- nonumber -->  : set nonumber

+- 기능이름=               --> : set 기능이름=

 

 

 

(5.2). vi 편집기 환경파일

 

* ex editor  =>  vi editor  => vim editor (iMprove vi)

 ~/.exrc                      ~/.vimrc

 

# vi ~/.exrc

set nu showmode sm ai

 

or

 

# vi ~/.exrc

set number                 // 편집기의 라인번호

set showmode               // 편집기의 모드 표시

set showmatch              // 편집기 작업시 매칭되는 문자들을 표시한다.

set autoindent             // 자동 들여쓰기

 

 

[참고] set list, set ic

set list - Display invisible charaters, such as ^I for a Tab and as $ for end-of-line

set ic   - Instructs searches to ignore case


출처 : http://cafe.daum.net/bscsolaris