Wednesday, January 28, 2009

Vim Tips: Copy and paste text

Copy:
'Y' or 'yy': copies (yanks) one or more lines.
10Y: copies 10 lines.
yG: copies all lines to the end of the file.
yw: yank text from the current cursor position to the end of the word.
y$: yank text from the current cursor position to the end of the line.

Paste:
P(uppercase): to paste the text contained in the buffer above the current cursor position.
p(lowcase): to paste the text contained in the buffer below the current cursor position.

Insert:
I(uppercase) : insert to the start of the current line.
A(uppercase): append to the end of the current line.
r(lowcase) : overwrite one character. After overwriting the simple character, go back to command mode.
R(lowcase): enter insert mode but replace characters after than inserting.

Entering visual mode:
v(lowcase) : start hightlighting characters.
V(uppercase) : start hightlighting lines.

Moving:
0(zero) : to the beginnning of a line.
$ : to the end of a line.

Editing blocks of text:
(The Vim commands marked with (V) work in visual mode, when you've selected some text).
~ : change the case of characters.
>(V) : shift right.
<(V) : shift left.
y(V) : yank the highlighted text.
d(V) : delete the highlighted text.

Tuesday, January 27, 2009

Perl Programming Topics

Perl Command-Line Options:
Perl Command-Line Options from perl.com

Overloading
Overloading from perl.com

Special Variables
Perl's Special Variables from perl.com

http://www.devdaily.com/perl/edu/articles/pl010010/

Development Practices
Ten Essential Development Practices

Vim tips: The basics of search and replace

Search:
1. /searchstring search forward through the file and ?searchstring search backwards through the file.
2. After running a search once, we can repeat it by using n in command mode, or N to reverse direction.
Replace:
syntax : [range] s/search/replace
1. The range is optional; if we just run :s/search/replace, it will search only the current line and match only the first occurrence of a term. We can add a range like:
:8, 10 s/search/replace/g
Without adding g, the search will match only the first instance of a string in any given line.
2. If you want to search an entire file, you can use % to indicate that as the range. If you wish to be asked for confirmation before Vim makes a substitution, add the confirm (c) option to the end of the search and replace command. (i) option will ignore case for the search pattern. (g) option will replace all occurrences in the line. Without this, Vim replaces only the first occurrences in each file.
:%s/search/replace/gc
Where you land:
1. To land on the last character in the matched string, add /e to your search: /string/e
2. To specify a cursor offset by line: /string/+2 or /string/-2
3. To specify a cursor offset by the beginning of the string or the end of the string: /string/s+2 or /string/e-3