Tuesday, May 29, 2007

VIM Crash Course. Study #2.

OK. Recently, we have replaced a word in file. Now let's replace particular line in file.

Example presumes you have open file you need to replace a line in.

Line number is known and is 1234. (Or you can use '/' search operator from previous post to find the line.)

1. :1234<Return>
2. C
3. <new text for given line>
4. <Esc>
5. :wq


1. Colon ':' allows us not only to input commands, but also to jump to particular line given by its number. Press colon, type line number and hit Enter. Cursor will be put on the first character in line number 1234. (Or last line, if number is too big.)

2. 'C' would 'C'lear (delete all characters) starting from current one and put vim into insert mode. If cursor stands on first character in line - as it should after step 1 - it would clear whole line.

3. Now type whatever you need to type in the line. After step 2 we are in insert mode - to insert text. Any text you would type would appear verbatim.

4. <Esc> will put vim back into normal mode.

5. ':wq' will write file and end editing session.


No comments: