2016年6月1日 星期三

[Linux 文章收集] vi Find And Replace Text Command

Source From Here 
Question
How do I find and replace (substitute) test using vi or vim text editor under UNIX / Linux / BSD or Apple OS X operating systems?

How-To
Both vi and vim text editor comes with substitute command for finding and replacing text.

Syntax
The syntax is as follows:
:%s/WORD-To-Find-HERE/Replace-Word-Here/g

OR
:%s/FindMe/ReplaceME/g

Examples
The substitute command can be used as per your requirements.

Task: VI / Vim Basic Find and Replace
To find each occurrence of ‘UNIX’, and replace it with ‘Linux’, enter (press ESC, type : and following command):
:%s/UNIX/Linux/g

 

Task: Find and Replace with Confirmation
Find a word called ‘UNIX’ and replace with ‘Linux’, but ask for confirmation first, enter:
:%s/UNIX/Linux/gc

Task: Find and Replace Whole Word Only
Find whole words exactly matching ‘UNIX’ to ‘Linux’; and ask for confirmation too:
:%s/\/Linux/gc



Task: Case Insensitive Find and Replace
Find ‘UNIX’ (match UNIX, unix, UnIx, Unix and so on) and replace with ‘Linux’:
:%s/unix/Linux/gi

Same command with confirmation:
:%s/unix/Linux/gic

How Do I Replace In the Current Line Only?
Find ‘UNIX’ and replace with ‘Linux’ in the current line only (note % is removed from substitute command):
:s/UNIX/Linux/g

How Do I Replace All Lines Between line 100 and line 250?
:{START-n},{END-n}s/word1/word2/g

Find ‘UNIX’ and replace with ‘Linux’ all lines between line 100 and line 250, enter:
:100,200s/UNIX/Linux/g

OR
:100,200s/UNIX/Linux/gc


沒有留言:

張貼留言

[JS 文章收集] 用 Node.js 學 JavaScript 語言(1)簡介與安裝

Source From  Here   簡介   Node.js  是 Ryan Dahl 基於 Google 的 V8 引擎於 2009 年釋出的一個 JavaScript 開發平台,主要聚焦於 Web 程式的開發,通常用被來寫網站。但是,要開發網站就勢必要把「 HTML,...