Linux/Linux

Vim 단축키 / Vim shortcuts

옥뀨 2020. 7. 9. 18:03

필자는 현재 칼리 리눅스 터미널에서 centos를 사용중이다.

I am currently using centos in a Kali Linux terminal.

 

필자의 프로그래밍 환경을 확인해야 한다면 

https://information-security-vlog.tistory.com/10 을 참고하면 되겠다.

If you need to check my programming environment,

you can refer to information-security-vlog.tistory.com/10.

 

프로그래밍을 하기전 Vim 설치와 환경 설정 및 단축키를 먼저 확인하고 가자.

Before programming, let's check the Vim installation, preferences, and shortcuts first.

 

Vim은 Vi 호환 텍스트 편집기이며 Vi 보다 다양한 기능이 제공되는 편집기이다.

Vim is a Vi-compatible text editor and an editor with more features than Vi.

 

Vim 의 강점은 자유롭게 편집 환경을 변경하거나, 확장된 정규 표현식 문법, 강력한 문법 강조 기능,

다중 되돌리기, 유니코드를 비롯한 다국어 지원, 문법 검사 등을 쓸 수 있다는 점이다.

Vim's strengths are that you can freely change the editing environment,

use extended regular expression grammars, powerful grammar highlighting, multi-revert,

multi-language support, including Unicode, grammar checking, and more.

 

gedit 은 그래픽 유저 인터페이스 환경용 프로그램이므로 사용하지 않겠다.

I will not use gedit as it is a program for a graphical user interface environment.

 

이상 간단한 설명을 마치고 본 포스팅에선 Vim 의 단축키를 먼저 알아보고

다음 포스팅에선 설치 및 설정을 진행해보자.

After completing the above brief description, let's first look at the shortcuts of Vim in this post,

and then install and configure in the next post.

 

Vim 에는 많은 단축키를 지원해준다.

Vim supports many shortcuts.

 

이 그림은 간략한 단축키에 대한 그림이고 밑에 구체적으로 설명을 적어주도록 하겠다.

This is a picture of a brief shortcuts and I will write a detailed explanation below.

 

Vi, Vim 에디터 단축키 / Vi, Vim editor shortcuts
Vim 명령 모드 / Vim command mode

 

바로 단축키 설명을 해보도록 하겠다.

I'll explain the shortcuts right away.

 

삽입/편집 작업을 진행하다가 명령 모드로 변경해야 할 경우  "ESC" 키를 누르면 전환된다.

If you need to change to command mode while inserting/editing, press the "ESC" key to switch.

 

 파일 작업 시 명령어
 Command when working with files

 Vim 명령어
 Vim command

 결과
 result

 :e 파일명
 :e filename

 새로운 파일을 편집.

 커맨드 프롬프트처럼 Tab 키를 통해 파일이름의 자동 완성 기능을 사용 가능.
 Editing new files.
 You can use the autocomplete function of the file name
 through the Tab key as in the command prompt.

 :w 파일명
 :w filename

 파일을 저장. 파일 이름을 지정하지 않는다면 원래 파일 이름으로 저장이 되고
 파일 이름을 지정해 준다면 새로운 파일 이름으로 저장.
 Save the file. If you do not specify a file name, it is saved as the original
 file name. If you specify a file name, it is saved as a new file name.

 :q

 현재 편집 중인 Vim 종료. 파일을 저장하지 않으면 종료되지 않음.
 Exit Vim currently being edited. Does not exit if file is not saved.

 :q!

 파일의 저장에 상관없이 종료.
 Exit regardless of saving the file.

 :wq

 파일을 저장한 후 종료.
 Save the file and exit.

 :x

 위의 :wq 와 거의 같지만 여기서 파일이 저장된 이후 기록된 사항이 있으면
 저장하지 않고 파일이 저장된 이후 기록된 사항이 있으면 저장 후 종료.
 It is almost the same as :wq above, but if there is a record after the file is
 saved, it is not saved. If there is a record after the file is saved,
 save and exit.

 

실행 취소 및 다시 실행 명령어이다.

These are the undo and redo commands.

 

"ESC" 키를 눌러 편집 모드에서 빠져 나온 뒤 명령 모드에서 사용한다.

Press "ESC" key to exit edit mode and use it in command mode.

 

 실행 취소 및 다시 실행
 Undo and redo

 Vim 명령어
 Vim command

 결과
 result

 u

 실행 취소.
 Undo.

 U

 커서가 가리키고 있던 라인에서 했던 모든 실행들을 취소.
 Undo all executions done on the line the cursor is pointing to.

 Ctrl + r

 다시 실행.
 Redo.

 

다음은 검색 명령어이다.

The following is a search command.

 

"ESC" 키를 눌러 편집 모드에서 빠져 나온 뒤 명령 모드에서 사용한다.

Press "ESC" key to exit edit mode and use it in command mode.

 

 검색
 Search

 Vim 명령어
 Vim command

 결과
 result

 /pattern

 "pattern" 단어를 검색.
 Search for the word "pattern".

 n

 다음 문자열을 아래방향으로 검색.
 Search for the next string downwards.

 N

 다음 문자열을 윗방향으로 검색.
 Search for the next string upwards.

 

치환 명령어이다.

It is a substitution command.

 

문자나 문자열을 바꾸는 명령어라고 생각하면 된다.

Think of it as a command to change characters or strings.

 

마찬가지로 "ESC" 키를 눌러 삽입/편집 모드에서 빠져 나온 뒤 명령 모드에서 사용한다.

Likewise, press "ESC" key to exit insert/edit mode and use it in command mode.

 

 치환 (바꾸기)
 Substitution (replace)

 Vim 명령어
 Vim command

 결과
 result

 :r s/foo /bar /a 명령어
 :r s/foo /bar /a
 command

 foo 를 bar 로 치환. r 은 치환하는 범위를 지정하고 f 는 인자를 지정.
 아래에 r 과 a 의 종류에 대해 설명되어 있다.
 Replace foo with bar. r specifies the range to replace, and f specifies
 the argument. The types of r and a are described below.

 범위 (r, range) 의 종류
 Type of range (r, range)

 아무것도 쓰지 않을 때
 When nothing is written

 범위를 주지 않을 경우 현재 라인에서 치환.
 If no range is given, replace in the current line.

 숫자를 쓸 때
 When writing numbers

 치환할 라인의 숫자를 입력.
 Enter the number of lines to replace.

 %

 전체 파일의 모든 라인에 대해 치환.
 Replace all lines in the entire file.

 인자 (a, argument )의 종류
 Types of arguments (a, argument)

 g

 한 라인의 모든 경우를 치환. 이 인자를 주지 않을 경우 처음 발견되는 것만을 치환.
 Replace all cases in one line. If this argument is not given,
 only the first one found is replaced.

 i

 검색된 문자들의 대소문자를 무시하고 치환.
 Ignore the case of the searched characters and replace them.

 I

 대소문자를 무시하지 않고 치환
 Substitution without ignoring case

 c

 모든 치환에 대해 확인. 만약 치환할 것이라면 y 를, 치환하지 않을 것이라면 n 을,
 이하 모든 부분을 치환할 것이라면 a 를, 치환을 종료하겠다면 q 를 입력.
 Confirm for all substitutions. Enter y if you want to replace, n if you
 don't want to replace, a if you want to replace all of the following,
 or q to quit.

 예를 들자면
 for example

 :452s/foo /bar /

 452 번째 라인의 첫 번째 foo 를 bar 로 치환.
 Replace foo with the first foo on line 452.

 :s/foo /bar /g

 현재 라인에 나타나는 모든 foo 를 bar 로 치환.
 Replace all foos appearing on the current line with bar.

 :%s/foo /bar /g

 전체 파일의 모든 foo 를 bar 로 치환.
 Replace all foos in the entire file with bar.

 :%s/foo /bar /gi

 위와 같지만 Foo, FOO, FOo, foO 와 같은 것들도 모두 치환.
 Same as above but Foo, FOO, FOo, foO are all substituted.

 :%s/foo /bar /gc

 위위와 같지만 각 치환에 대해 모두 검사를 수행.
 Tests are performed for each substitution.

 :%s/foo /bar /c

 파일의 모든 라인에 대해 각 라인의 첫 번째 foo 만 bar 로 치환하며 각 치환에 대해
 검사.
 For every line in the file, only the first foo on each line is replaced by bar,
 and checked for each substitution.

 

다음은 파일 편집 시 사용하는 단축키이다.

The following are shortcuts used when editing files.

 

 파일 편집 중 이동
 Moving during file editing

 아래의 Vim 명령어는 Visual 모드, 터미널 모드 모두에서 사용 가능.
 The following Vim commands can be used in both Visual and Terminal modes.

 Vim 명령어
 Vim command

 결과
 result

 j or 방향키 ↑
 j or arrow keys ↑

 커서를 한 칸 위로 이동.
 Move the cursor up one space.

 k or 방향키↓
 j or arrow keys

 커서를 한 칸 아래로 이동.
 Move the cursor down one space.

 l or 방향키 →
 j or arrow keys

 커서를 한 칸 오른쪽으로 이동.
 Move the cursor one space to the right.

 h or 방향키 ←
 j or arrow keys

 커서를 한 칸 왼쪽으로 이동.
 Move the cursor one space to the left.

 e

 단어의 끝으로 이동.
 Go to the end of the word.

 E

 단어의 끝으로 이동.
 Go to the end of the word.

 b

 단어의 첫 부분으로 이동.
 Go to the first part of the word.

 B

 단어의 첫 부분으로 이동.
 Go to the first part of the word.

 0

 문장의 첫 부분으로 이동.
 Move to the beginning of the sentence.

 ^

 공백문자가 아닌 문장의 첫 부분으로 이동.
 Move to the beginning of a sentence that is not a space character.

 $

 문장의 끝으로 이동.
 Move to the end of the sentence.

 H

 화면의 첫 번째 라인으로 이동.
 Go to the first line of the screen.

 M

 화면의 중간 라인으로 이동.
 Move to the middle line of the screen.

 L

 화면의 마지막 라인으로 이동.
 Go to the last line on the screen.

 :n

 n 번째 라인으로 이동. 예를 들어 :10 이면 10 번째 줄로 이동.
 Go to the nth line. For example: 10 moves to the 10th line.

 텍스트의 삽입 몇 편집
 Insert and edit text

 Vim 명령어
 Vim command

 결과
 result

 i

 커서 앞에 입력.
 Enter before the cursor.

 I

 커서가 가리키는 라인의 앞에 입력.
 Enter in front of the line pointed to by the cursor.

 a

 커서 뒤에 추가.
 Add after cursor.

 A

 커서가 가리키는 라인의 맨 뒤에 추가.
 Append to the end of the line pointed to by the cursor.

 o

 커서가 가리키는 라인 아래에 새 라인을 추가.
 Add a new line below the line the cursor points to.

 O

 커서가 가리키는 라인 위에 새 라인을 추가.
 Add a new line above the line the cursor points to.

 r

 한 글자를 바꿔 쓴 후 다시 명령모드로 변경.
 After changing one letter, change to command mode again.

 R

 삽입모드에 들어가지만 글자를 덧쓰면서 이미 쓰여진 글자를 삭제.
 Enters the insert mode,
 but deletes the already written text while overwriting the text.

 ESC

 삽입/수정 모드에서 명령 모드로 변경.
 Change from insert/modify mode to command mode.

 텍스트 지우기
 Clear text

 Vim 명령어
 Vim command

 결과
 result

 x

 커서가 가리키는 글자를 삭제.
 Delete the character pointed to by the cursor.

 X

 커서 앞의 글자를 삭제.
 Delete the character in front of the cursor.

 dd or :d

 현재 커서가 가리키는 라인의 글자를 삭제.
 Delete the character of the line to which the current cursor is pointing.

 

마지막으로 비주얼 모드이다.

Finally, it is a visual mode.

 

비주얼 모드는 블록을 지정하여 사용하는 모드이다.

Visual mode is a mode used by designating a block.

 

 비주얼 모드 들어가기
 Enter visual mode

 Vim 명령어
 Vim command

 결과
 result

 v

 단어를 블록 지정. 텍스트를 블록 지정하기 위해서 이동키를 사용.
 Word block designation. Use move keys to designate blocks of text.

 V

 현재 커서가 가리키는 라인을 블록 지정.
 Specifies the block of lines currently pointed to by the cursor.

 ESC

 비주얼 모드에서 빠져나와 명령 모드로 변경.
 Exit visual mode and change to command mode.

 블록 테스트 편집하기
 Editing block tests

 아래의 명령어는 비주얼 모드에서 텍스트를 블록 설정한 후 명령 모드로 들어와 사용 가능.
 물론 명령모드에서도 사용 가능.
 The following command can be used after designating a block of text in visual mode.
 Of course, it can also be used in command mode.

 Vim 명령어
 Vim command

 결과
 result

 ~

 글자의 대소문자를 변경. 예를 들면 mOvL 은 MoVl 로 변경된다. 비주얼 모드와
 명령모드 둘 다 사용할 수 있으며 비주얼 모드에서 블록 처리한 뒤 명령 모드로
 들어와~ 를 누르면 그 블록 설정된 부분의 대소 관계가 변경됨.
 Change the case of letters. For example, mOvL is changed to MoVl.
 It can be used in visual mode and command mode.
 After processing in visual mode,
 enter the command mode and press ~ to change the case of letters

 > (V)

 한 칸 오른쪽으로 이동.
 Move one space to the right.

 < (V)

 한 칸 왼쪽으로 이동.
 Move left one space.

 c (V)

 블록 지정된 텍스트를 변경.
 Change the block specified text.

 y (V)

 블록 지정된 텍스트를 복사.
 Copy the specified block text.

 d (V)

 블록 지정된 텍스트를 잘라내기.
 Cut block specified text.

 yy or :y or Y

 커서가 가리키는 라인을 복사. 블록 지정할 필요는 없다.
 Copy the line pointed to by the cursor.
 There is no need to specify a block.

 dd or :d

 커서가 가리키는 라인을 삭제. 블록 지정할 필요는 없다.
 Delete the line pointed to by the cursor.
 There is no need to specify a block.

 p

 복사나 잘라내기 했던 텍스트를 붙여넣기.
 Paste text that has been copied or cut.

 P

 커서 앞에 복사나 잘라내기 했던 텍스트를 붙여 넣기.
 Paste text that has been copied or cut in front of the cursor.

 

'Linux > Linux' 카테고리의 다른 글

Vim 설정 / Vim Settings  (0) 2020.07.13