14.06.2014 Views

vim 101 hacks

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Buyer: xiujuan lu (luxiujuan@gmail.com)<br />

Transaction ID: 85W16630AD8515549<br />

Vim <strong>101</strong> Hacks<br />

www.thegeekstuff.com<br />

Hack 22. Substitute Text<br />

The following explains various methods to substitute text in a file.<br />

Key<br />

s<br />

Description<br />

Substitute the current character with new<br />

character<br />

S<br />

Substitute the current line with new text<br />

4s<br />

Substitute 4 characters (from current position)<br />

with new text<br />

4S<br />

Substitute 4 lines (from current line) with new<br />

text<br />

Let us assume that we are editing the following file<br />

$ <strong>vim</strong> employee.txt<br />

100 John Doe DBA<br />

200 John Smith Sysadmin<br />

300 Raj Patel Developer<br />

• If your cursor is over D on “John Doe” and if you type 2s, you’ll be<br />

replacing ‘Do’ with any new text that you type.<br />

• If your cursor is anywhere on line 1 and if you type 2S, you’ll be<br />

replacing both the 1 st and the 2 nd line with any new text that you<br />

type.<br />

51

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!