Computer Science/유닉스프로그래밍

[유닉스 이론과 실습] ch04. vi 사용법 익히기

계속지나가기 2020. 10. 18. 11:08
반응형

(본 강의 노트는 한빛 미디어의 <유닉스 이론과 실습> 책을 기반으로 하고 있습니다)

ch04. vi 사용법 익히기

학습목표

  • 유닉스에서 사용하는 편집기의 종류를 알아본다
  • 대표적인 화면 편집기인 vi의 사용 방법을 익힌다
  • vi의 환경 설정방법을 익힌다

목차

  1. 유닉스 편집기
  2. vi의 사용법

01. 유닉스의 편집기

화면 편집기

  1. vi
  • vi editor는 리눅스 패밀리에서 가장 유명하고 classical한 텍스트 edit tool
  • 대부분의 리눅스에서 사용 가능함
  • 사용자 친화적인 환경이라서 적응되면 사용하기 편함
  1. emacs
  • 막강한 기능 제공, 설치해서 사용해야 함

모드형과 비모드형

  1. 모드형
  • 명령모드에서 입력한 키는 명령으로, 입력모드에서 입력한 키는 데이터로 간주
  • 모드를 바꾸기 위한 특수 키가 있음
  1. 비모드형
  • 입력한 모든 키는 데이터로 간주

Modes of vi

  1. command mode
  • 입력한 내용을 명령어로 해석
  • vi 시작시 맨 처음 모드
  • vi 종료 : shift + zz
  • 커서 이동, 페이지 이동, 글자 삭제, 줄 삭제 등
  1. insert mode
  • key stroke이 파일의 내용으로 반영
  • command -> insert : i,a
  • inset -> command : Esc
  1. last line mode
  • 파일 전체에 영향을 미치는 명령
  • 검색, 저장 바꾸기 줄 이동 등
  • command -> last line mode : :,/,?
  • last line -> vi 종료 : q, q!

02. vi의 사용방법

VI Example

  1. launch the VI Editor
  • vi 첫 입장 시 : command mode 로 열림
  1. go to insert mode with 'i'
  • command mode에서 'i' 입력시 insert mode로 전환
  • 다시 command mode 돌아가고 싶으면 Esc 누르기
  1. Exiting vi with save
  • last line mode with: and 'wq'
  • terminal 에서 cat : 편집 없이 터미널 내에서 볼 수 있음

Moving within a file command

  1. ^ : the beginning of the line
  2. $ : end of the line

command to/from insert mode

  1. i : insert at cursor
  2. a: write after cursor
  3. A : write at the end of line
  4. o : open a new line
  5. u : undo last change
  6. U : undo all changes to the entire line

saving and closing the file

  1. shift+zz : save the file and quit
  2. q/q! : quit without saving

editing command

  1. dd - delete line
  2. x - delete character at the cursor
  3. r - replace character
  4. yy - copy | p - paste( 여러줄 하고 싶으면 2yy -> p하면 됨)

Misc

  1. (/string) : 커서가 있는 기준 다음으로 string이라는 단어를 찾음
  2. (?string) : 커서가 있는 기준 접으로 string 이라는 단어를 찾음
  3. n : 지금 기준으로 다음으로 검색 진행
  4. N : 지금 기준으로 이전으로 검색 진행
  5. :s/string1/string2 - string1 단어를 한 줄 내에서 모두 찾아 string2로 바꿔줌
  6. :1,$s/string1/string2/g - string1 단어를 모든 줄 내에서 모두 찾아 string2 로 바꿔줌
  7. :set number - line 보여줌 | :set nonu - line지워줌
  8. :n - n번째 라인으로 감
반응형