iT邦幫忙

2019 iT 邦幫忙鐵人賽

DAY 5
1
自我挑戰組

vim不m系列 第 5

Day05 - replacement

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.

我們有以上的一段文字,我們想要將 Ipsum 這個字改為 Ttn 我們可以用以下的方式

:s/Ipsum/Ttn

這麼做只會改第一個如果有一次改全部的話那需要在後面多加一個 flag g

:s/Ipsum/Ttn/g

但如果有其中一個不想換的時候,這個方式就會有問題

可以多加一個 flag c

他會在每次要取代時先詢問 replace with Ttn (y/n/a/q/l/^E/^Y)?
y: 要 ( yes )
n: 不要 ( no )
a: 全部都要 ( all )
q: 現在退出 ( quit )
l: 改完這個後退出 ( last )

* 可以往後找出檔案中所有相同的字

cw 改變一個字

除了用取代之外還有另一種思考,將游標移在 Ipsum 這個字上按 *

cwTtn<Esc>

n.

如此一來就可以一個一個往後直到整個檔案的字都輪過一次

這時 . 所代表的是一整個把字換掉的修改, n 則是移動
所以如果這個輪到的字不做修改的話就再按一次 n 往下即可

如果是想要往前的話則是按 #

# 可以往前找出檔案中所有相同的字

在使用這個功能的時候可以開起一個設定

:set hls

可以將找出的結果改變顏色標示出來幫助你辨別

反向要關掉則是用

:noh


上一篇
Day04 - redo, undo
下一篇
Day06 - . 模式
系列文
vim不m30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 則留言

0
JasonYang
iT邦新手 5 級 ‧ 2018-10-23 10:49:25

好神奇!

ttn iT邦新手 5 級 ‧ 2018-10-24 10:38:39 檢舉

MAGIC!!

我要留言

立即登入留言