본문 바로가기
구 블로그 보관처

Linux - VI 명령어 사용법 정리

by 만수킴 2020. 5. 17.

 

 calshp> vi filename 

 a : append after the cursor 

 i : insert before the cursor 

 o : start a new line below the cursor 

 O : start a new line above the cursor 

 

 

 

The "esc" key must be used to end any of the above commands or to begin any of the following commands 

(depending on which way you look at it). You must also hit the "esc" key prior to any cursor movement. 

When in doubt, hit the "esc" key and proceed. 

 

 

3. How to delete information from a file:  

 x : deletes the character the cursor is under 

 dd : deletes the line the cursor is on 

 

4. How to make corrections:  

 r : followed by a single character, replaces the character the cursor is on  

 R : followed by many characters until an "esc" key is typed, writes over all the previous characters 

 

5. More edit commands  

 CTRL-f : scroll down ndd delete n lines 

 CTRL-b : scroll up nG go to line n 

 ^ : go to beginning of line nY copy n lines 

 $ : go to end of line p put copied lines below cursor 

 ndd : delete n lines

 nG : go to line n 

 nY : copy n lines

 p : put copied lines below cursor

 

 

6. How to exit from vi:  

 Depress the escape key; then type a colon ":" and you are ready to use one of the line commands.  

 ZZ : saves the current changes and exits vi 

 :wq : saves the current changes and exits vi 

 :w! : saves the current changes but does not exit vi 

 :q! : exits vi without saving any change 

 

7. More line commands: 

 :1 : goes to the top line of your file 

 :5 : goes to the fifth line of your file 

 :$ : goes to the bottom line of your file 

 :set nu  : will number all your lines 

 :set nonu : will turn off the line numbering 

 :1,$s/oldstr/newstr/g : how to make global substitution 

 :vi : returns to the full screen editor 

 

 

 

댓글