The Bang Command
!
- 將外部命令的STDOUT讀入當前緩沖區(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ū)的內容作為STDIN寫入外部命令粟耻。
:w !cmd
當使用:w命令時查近,Vim使用當前緩沖區(qū)中的所有文本眉踱,類似于全局命令。也可以在前面指定范圍
- 從Vim內部執(zhí)行外部命令
:!cmd
Filtering Texts
:.!tr '[:lower:]' '[:upper:]'
使用tr (translate)命令大寫當前行霜威。
- .!
在當前行上執(zhí)行篩選命令谈喳。 - !tr '[:lower:]' '[:upper:]'
調用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
根據價格對它們進行排序戈泼,并且只顯示具有均勻間距的菜單
- awk 'NR > 1'
只顯示從第2行開始的文本婿禽。 - sort -nk 3
使用列3 (k 3)中的值進行數字排序(n)赏僧。 - column -t
以均勻的間距組織文本。