Missing Semesters (2020) 3강 Vim
Vim modes
- Normal mode
- 목적: Navigation
- 다른 mode에서
esc를 눌러서 이동
- Insert mode
- Normal mode에서
i를 눌러서 이동 - 목적: Typing text into the text buffer
- Normal mode에서
- Replace mode
- Normal mode에서
r을 눌러서 이동
- Normal mode에서
- Visual mode
- Normal mode에서
v를 눌러서 이동 - Visual line
- Normal mode에서
shift + v를 눌러서 이동
- Normal mode에서
- Visual block
- Normal mode에서
ctrl + v를 눌러서 이동
- Normal mode에서
- Normal mode에서
- Command-line mode
- Normal mode에서
:을 눌러서 이동
- Normal mode에서
이것을 보면 esc를 많이 누르게 될 것을 알고 있다. esc키를 누르기 위해 왼손 새끼손가락을 쭉 올리는거보다, 종종 캡스락 키에 esc 키를 바인딩 하기도 한다.
Open file
vim을 눌러서 vim을 키고 끌 수 있다.vim file.md를 써서 파일을 열 수 있다.- vim에서 파일을 읽거나 저장하거나, vim을 종료하려고 할 때는 command-line mode를 사용한다.
- Normal mode에서
:를 눌러서 command-line mode로 와야한다. :quit을 누르면 끌 수 있다.:q는 짧은 버전이다.:w를 통해 write, 즉 저장할 수 있다.:help xyz를 눌러서 xyz에 대한 document를 볼 수 있다.
- Normal mode에서
Buffers, tabs, windows
- VSCode는 동시에 여러개의 파일을 열 수 있다.
- Vim 도 가능하다. 여러개의 buffer를 열 수 있다.
- 기존의 에디터 프로그램들에서 사용하는 개념들은 vim에서는 다음과 같이 맵핑된다.
- File -> buffer
- Tab -> Tab
- Window -> Window
- Vim도 여러개의 buffer (i.e.file)을 열 수 있고, 여러개의 탭을 열 수 있고, 여러개의 윈도우를 사용할 수 있다.
- Buffer는 윈도우 없이 여러개를 열 수 있다.
- Window를 열기 위해서는
:sp커맨드를 사용한다.:q또는:quit을 사용해서 윈도우를 닫는다.:qa(i.e. quit all)을 사용해서 모든 윈도우를 한번에 닫을 수 있다.
tabnew를 사용하여 새 tab을 열 수 있다.- 하나의 tab에는 여러 윈도우를 띄울 수 있다.
Buffer
- Navigate around buffer in normal modeS?
hjklbuttons to move cursors- Instead of
hhhhh, we can also do5h.
- Instead of
wandbto move cursor by wordseto move cursor to the end of the word
0to move by line$to move to the end of a line^to move to first non-empty character of the line
ctrl + Umoves up the page,ctrl + Dmoves down the page.Gmoves to the bottom of the page,ggmoves to the top of the pageLmoves your cursor to the bottom of the screen,Mto the middle of the screen,Hto the top of the screen
- Find words
foto find the first ‘o’.Foto find the first ‘o’ backwards.toto find the first ‘o’, but place the cursor right before it.Toto find the fisrt ‘o’, but place the cursor right before it./wordto search for a word
- Editing
oin normal mode will automatically activate insert mode after making a new lineOin normal mode will automatically activate insert mode after making a new line above the cursor.dwto delete a word- We can do
7dwto delete 7 words.
- We can do
deto delete to end of a wordddto delete a line. Repeating the command affects the entire line.ceto change to end of a word. It deletes the content to end of a word and automatically activate insert mode.ccto change a line. Repeating the command affects the entire line.xdeletes a characterrareplace a character by ‘a’uUndo actionRredo actionyto copy (yank), andpto paste.yyto copy a lineywto copy a word- To select a block of text, we need to enter the visual mode. Use
vto enter the visual mode. UseVto enter the visual line mode. Usectrl + Vto enter the visual block mode.- Use
hjklto navigate cursor and select the block of text - then, use
yto copy the block of text and return to normal mode.
- Use
~to change the case
- Modifer commands
- Use
ci(orci[to change the contents inside the brackets (i for inside) - Use
%to jump back and forth the parentheses. - Use
da(to delete the entire content + the parentheses. (a for around)
- Use
- Repeat command
.to repeat the previous command.