# 網際網路與 Linux 應用 Week 7
## vim 使用
---
# 故事時間
----
## vi
(1976)
[wiki](https://zh.wikipedia.org/wiki/Vi)
----
## 編輯器的大戰
vi VS Emacs
[wiki](https://zh.wikipedia.org/wiki/%E7%BC%96%E8%BE%91%E5%99%A8%E4%B9%8B%E6%88%98)
---
# 模式
----
## NORMAL mode
一般模式(命令模式)
進入方法:狂按 esc
用途:輸入命令(螢幕最下面那行),操作檔案(複製,貼上,選取.....)
----
## INSERT mode
進入方法:
i: 在這個字開始輸入
a: 在下一個字開始輸入
o: 向下新增一行開始輸入
I: 在行首開始輸入
A: 在行尾開數輸入
O: 向上新增一行開數輸入
用途:編輯
---
# 命令
(要進入一般模式)
----
## save file
```
:w filename(optional)
```
----
## quit
```
:q
```
----
## save and quit
```
:wq
```
----
## open file
```
:e filename
```
----
## open a new file
```
:enew
```
----
## search
```
/barbar
```
----
## replace
```
:s/bar/foo/
:%s/bar/foo/
:s/bar/foo/i
:s/bar/foo/g
:%s/bar/foo/gi
```
[regex wiki](https://zh.wikipedia.org/wiki/%E6%AD%A3%E5%88%99%E8%A1%A8%E8%BE%BE%E5%BC%8F)
----
## move to line
```
:[line number][enter]
[line number][g][g]
[line number][G]
```
CF:
```
[line number][enter]
```
---
# 快捷鍵
----
## copy a line
```
[y][y]
```
----
## cut(delete) a line
```
[d][d]
```
----
## paste text in clipboard
```
[p]
```
----
## select
```
[V]
[v]
[C-v]
```
----
### [V]

----
### [v]

----
### [C-v]

----
## move to the top/bottom of the file
```
[g][g]
[G][G]
```
----
## move to the start/end of a line
```
[^]
[%]
```
{"metaMigratedAt":"2023-06-15T07:30:05.106Z","metaMigratedFrom":"YAML","title":"網際網路與 Linux 應用 Week 7","breaks":true,"contributors":"[{\"id\":\"e9395e03-a75e-451d-8392-22ff7e9c3ef5\",\"add\":1532,\"del\":77}]"}