The Bang Command
!
- 將外部命令的STDOUT讀入當(dāng)前緩沖區(qū)。
:r !cmd
:r is Vim's read command
:r !curl -s 'https://jsonplaceholder.typicode.com/todos/1'
read the data from the curl command
:10r !cat file1.txt
accepts an address
- 將緩沖區(qū)的內(nèi)容作為STDIN寫入外部命令。
:w !cmd
當(dāng)使用:w命令時,Vim使用當(dāng)前緩沖區(qū)中的所有文本,類似于全局命令。也可以在前面指定范圍
- 從Vim內(nèi)部執(zhí)行外部命令
:!cmd
Filtering Texts
:.!tr '[:lower:]' '[:upper:]'
使用tr (translate)命令大寫當(dāng)前行。
- .!
在當(dāng)前行上執(zhí)行篩選命令。 - !tr '[:lower:]' '[:upper:]'
調(diào)用tr命令將所有小寫字符替換為大寫字符
傳遞一個范圍作為過濾器來運行外部命令是必要的。所以要用“.”
:%!awk "{print $1}"
刪除第二列
- :%!
在所有行執(zhí)行filter命令 - awk "{print $1}"
prints only the first column of the match
:%!awk 'NR > 1' | sort -nk 3 | column -t
根據(jù)價格對它們進行排序,并且只顯示具有均勻間距的菜單
- awk 'NR > 1'
只顯示從第2行開始的文本。 - sort -nk 3
使用列3 (k 3)中的值進行數(shù)字排序(n)。 - column -t
以均勻的間距組織文本。