Take Notes from Book-Learning the vi Editor

                        Take Notes from Book-Learning the vi Editor

vi is short for visual editor and is pronounced "vee-eye."
vi's initial or "default" mode is command mode
Basic commands:
i insert before the cursor
a insert after the cursor
cw change word
ZZ quit and save edits
:w save file
:wq save and quit
w! overwrite the existing file
w newfile save the edited version in a new file
q!
e!
go to the first line. :1
go to the end of file G
search the next, n
backward search ? enter then n
forward search / enter then n
A colon (:) begins all ex commands.
Moving the Cursor
h left, one space
j down, one line
k up, one line
l right, one space
Movement commands can take numeric arguments
4l moves the cursor four spaces to the right
Movement within a Line
0 Move to beginning of line.
$ Move to end of line.
Movement by Text Blocks
w moves the cursor forward one word at a time, counting symbols and punctuation as equivalent to words
W not counting symbols and punctuation as equivalent to words
b move backward by word
B move backward by word, not counting punctuation
2w moves forward two words; 5B moves back five words, not counting punctuation.
i for insert (which you've already seen); a for append;
press ESC to end the insert and return to command mode.
Changing Text
c change text
In order to tell c how much text to change, you combine c with a movement command.
vi marks the end of the text that will be changed with a $
cw to the end of a word.
cc changes an entire line
C same as c$.
c2b back two words
c$ to the end of line
c0 to the beginning of line.
r replaces a single character with another single character, and do not have to press ESC to return to command mode
R replace character by character
s substitute command, replaces a single character
S deletes the entire line
~ (5~) change a lowercase letter to uppercase, or an uppercase letter to lowercase.
Deleting Text
d delete command requires a text object
dw delete a word beginning where the cursor is positioned
de delete only to the end of a word, not including the space following the word
dd delete the entire line
D delete from the cursor position to the end of the line, shortcut for d$
2dd, d0, d$, db, d2w
x deletes only the character the cursor is on
X(capital) deletes the character before the cursor
Moving Text
You move text by deleting it and then placing that deleted text elsewhere in the file, like a "cut and paste." Each time you delete a text block, that deletion is temporarily saved in a special buffer. Move to another position in your file and use the put command (p) to place that text in the new position.
p(put) place that text in the new position.
P(capital) puts the text in the buffer before the cursor
If you delete one or more lines, p puts the deleted text on a new line(s) below the cursor. If you delete less than an entire line, p puts the deleted text on the current line, after the cursor.
xp transpose two letters(that is to reverse the order of two letter, such as su to us )
Copying Text
y(for yank) and p (for put)
yy operates on an entire line
Y same as yy
yw, y$, 4yy, then move to where you want to put the yanked text, then p/P
Numeric Arguments for Insert Commands
50i*ESC inserts 50 asterisks
With a numeric prefix, r replaces many characters with a repeated instance of a single character
50r*
ea append new text to the end of a word
Movement Commands
+ To first character of next line
- To first character of previous line
e or E To end of word
w or W Forward by word
b or B Backward by word
$ To end of line
0 To beginning of line
P or p Place text from buffer
i Insert text at current position
I Insert text at beginning of line
a Append text at current position
A(shortcut for $a) Append text to end of current line.
o Open new line below cursor for new text
O Open new line above cursor for new text
s(shortcut for c Space) Delete character at cursor and substitute text.
S(same as cc) Delete line and substitute text
R Overstrike existing characters with new text
J Join current and next line
~ Toggle case
. Repeat last action
u Undo last change
U Restore line to original state
Command Pattern: (command)(number)(text object)
Or the equivalent form: (number)(command)(text object)
Movement by screens
ctrl+b Scroll backward one screen.
ctrl+f Scroll forward one screen.
ctrl+d Scroll forward half screen (down).
ctrl+u Scroll backward half screen (up).
ctrl+e screen up one line
ctrl+y screen down one line

zRETURN Move current line to top of screen and scroll.
z. Move current line to center of screen and scroll.
z- Move current line to bottom of screen and scroll.
200z RETURN moves line 200 to the top of the screen
Movement within a Screen
H Move to home—top line on screen.
M Move to middle line on screen.
L Move to last line on screen.
nH Move to n lines below top line.
nL Move to n lines above last line.
Movement by Line
RETURN Move to first character of next line.
+ Move to first character of next line.
- Move to first character of previous line.
+100 Move down 100 lines
-100 Move up 100 lines
Movement on the current line
h and l move the cursor to the left and right
0 Move to the first character of current line.
^ Move to first non-blank character of current line.
$ Move to the last character of current line.
n|, hl move the cursor to the left or right n positions.
Movement by Text Blocks
e Move to end of word.
E Move to end of word (ignore punctuation).
( Move to beginning of current sentence.
) Move to beginning of next sentence.
{ Move to beginning of current paragraph.
} Move to beginning of next paragraph.
[[ Move to beginning of current section.
]] Move to beginning of next section.
d) deletes to the end of the current sentence
2y} copies (yanks) two paragraphs ahead.
3) moves ahead three sentences
Movement by Searches
/pattern search command
?pattern search backward
Repeating Searches
n Repeat search in same direction.
N Repeat search in opposite direction.
/ RETURN Repeat search forward.
?RETURN Repeat search backward.
?you
Changing through searching
You can combine the / and ? search operators with the commands that change text, such as c and d.
d?move Delete from before the cursor up to and through the word move.
d/move
Current Line Searches
There are also miniature versions of the search commands that operate within the current line. The command fx moves the cursor to the next instance of the character x (where x stands for any character). The command tx moves the cursor to the character before the next instance of x. Semicolons can then be used repeatedly to "find" your way along.
Fx Find (move cursor to) previous occurrence of x in the line.
Tx Find (move cursor to) character before next occurrence of x in the line.
Tx Find (move cursor to) character after previous occurrence of x in the line.
; Repeat previous find command in same direction.
, Repeat previous find command in opposite direction.
dfx deletes up to and including the named character x.
ct. change text up to the end of a sentence, leaving the period.
With any of these commands, a numeric prefix n will locate the nth occurrence.
dfx deletes up to and including the named character x.
The command ct. could be used to change text up to the end of a sentence, leaving the period.
Movement by Line Number
ctrl+g display filename, current line number, total number of lines in the file, etc
44G move the cursor to the beginning of line 44
G move the cursor to the last line of the file
Two backquotes (` `) returns you to your original position
Two apostrophes (' ') works like two backquotes, except it returns the cursor to beginning of line
Typing two backquotes (` `) returns you to your original position (the position where you issued the last G command), unless you have done some edits in the meantime. If you have made an edit, and then moved the cursor using some command other than G, ` ` will return the cursor to the site of your last edit. If you have issued a search command (/ or ?), ` ` will return the cursor to its position when you started the search. A pair of apostrophes (' ') works much like two backquotes, except that it returns the cursor to the beginning of the line instead of the exact position on that line where your cursor had been.
Movement Command
Scroll forward one screen. ^F
Scroll backward one screen. ^B
Scroll forward half screen. ^D
Scroll backward half screen. ^U
Scroll forward one line. ^E
Scroll backward one line. ^Y
Move current line to top of screen and scroll. z RETURN
Move current line to center of screen and scroll. z.
Move current line to bottom of screen and scroll. z-
Redraw the screen. ^L
Move to home—top line of screen. H
Move to middle line of screen. M
Move to bottom line of screen. L
Move to first character of next line. RETURN
Move to first character of next line. +
Move to first character of previous line. -
Move to first non-blank character of current line. ^
Move to column n of current line. n|
Move to end of word. e
Move to end of word (ignore punctuation). E
Move to beginning of current sentence. (
Move to beginning of next sentence. )
Move to beginning of current paragraph. {
Move to beginning of next paragraph. }
Move to beginning of current section. [[
Move to beginning of next section. ]]
Search forward for pattern. /pattern
Search backward for pattern. ?pattern
Repeat last search. n
Repeat last search in opposite direction. N
Repeat last search forward. /Enter
Repeat last search backward. ?Enter
Move to next occurrence of x in current line. fx
Move to previous occurrence of x in current line. Fx
Move to just before next occurrence of x in current line. tx
Move to just after previous occurrence of x in current line. Tx
Repeat previous find command in same direction. ;
Repeat previous find command in opposite direction. ,
Go to given line n. nG
Go to end of file. G
Return to previous mark or context. ` `
Return to beginning of line containing previous mark. ' '
Show current line (not a movement command). ^G
More Editing Commands
Change Delete Copy from Cursor to ...
cH dH yH top of screen
cL dL yL bottom of screen
c+ d+ y+ next line
c5| d5| y5| column 5 of current line
2c) 2d) 2y) second sentence following
c{ d{ y{ previous paragraph
c/pattern d/pattern y/pattern pattern
cn dn yn next pattern
cG dG yG end of file
c13G d13G y13G line number 13
All of the above sequences follow the general pattern:
(number)(command)(text object)
number is the optional numeric argument. command in this case is one of c, d, or y. text object is a ovement command.
Options When Starting vi
According to the POSIX standard, vi should use -c command instead of +command as shown here. Typically, for backwards compatibility, both versions are accepted.
vi +n file Opens file at line number n.
vi +/pattern file Opens file at the first occurrence of pattern.
vi -R file(or view file) Read-only Mode
vi -c command file Run command after opening file; usually a line number or search
vi +/"you mark" file
Using +/pattern is helpful if you have to leave an editing session in the middle. You can mark your place by inserting a pattern such as ZZZ or HERE. Then when you return to the file, all you have to remember is /ZZZ or /HERE.
Recovering a Buffer
There is an option, -r, which lets you recover the edited buffer at the time of a system crash.
If you type the command: ex -r (or vi -r ),you will get a list of any files that the system has saved.
vi -r practice
You can force the system to preserve your buffer even when there is not a crash by using the command :pre(means preserve). You may find it useful if you have made edits to a file, then discover that you can't save your edits because you don't have write permission. (You could also just write out a copy of the file under another name or into a directory where you do have write permission.)
Making Use of Buffers
While you are editing, your last deletion (d or x) or yank (y) is saved in a buffer (a place in stored memory). You can access the contents of that buffer and put the saved text back in your file with the put command (p or P).
The last nine deletions are stored by vi in numbered buffers. You can access any of these numbered buffers to restore any (or all) of the last nine deletions. (Small deletions, of only parts of lines, are not saved in numbered buffers, however. These deletions can only be recovered by using the p or P command immediately after you've made the deletion.)
vi also allows you to place yanks (copied text) in buffers identified by letters. You can fill up to 26 (a-z) buffers with yanked text and restore that text with a put command at any time in your editing session.
Recovering Deletions
To recover a deletion, type " (double quote), identify the buffered text by number, then give the put command. To recover your second-to-last deletion from buffer 2:
"2p
The deletion in buffer 2 is placed after the cursor.
If you use the repeat command (.) with p after u, it automatically increments the buffer number. As a result, you can search through the numbered buffers as follows:
"1pu.u.u
to put the contents of each succeeding buffer in the file one after the other. Each time you type u, the restored text is removed; when you type a dot (.), the contents of the next buffer is restored to your file. Keep typing u and . until you've recovered the text you're looking for.
Yanking to Named Buffers
You can also use y and d with a set of 26 named buffers (a-z) which are specifically available for copying and moving text. If you name a buffer to store the yanked text, you can retrieve the contents of the named buffer at any time during your editing session.
To yank into a named buffer, precede the yank command with a double quote (") and the character for the name of the buffer you want to load.
"a7yy Yank next seven lines into buffer a.
After loading the named buffers and moving to the new position, use p or P to put the text back:
"ap Put the contents of buffer a after cursor.
you can use named buffers to selectively transfer text between files.
"a5dd
If you specify a buffer name with a capital letter, your yanked or deleted text will be appended to the current contents of that buffer. This allows you to be selective in what you move or copy.
"zd) Delete from cursor to end of current sentence and save in buffer z.
2) Move two sentences further on.
"Zy) Add the next sentence to buffer z.
Marking Your Place
During a vi session, you can mark your place in the file with an invisible "bookmark," perform edits elsewhere, then return to your marked place. In command mode:
m x
Marks the current position with x (x can be any letter).
' x
(apostrophe) Moves the cursor to the first character of the
line marked by x.
` x
(backquote) Moves the cursor to the character marked by x.
``
(backquotes) Returns to the exact position of the previous mark or context after a move.
''
(apostrophes) Returns to the beginning of the line of the previous mark or context.
Review of vi Buffer and Marking Commands
Command-Line Options
+n file Open file at line number n.
+file Open file at last line.
+/pattern file Open file at first occurrence of pattern.
-c command file
-R Operate in read-only mode (same as using view instead of vi).
-r Recover files after a crash.
Buffer Names
1-9 The last nine deletions, from most to least recent.
a-z Named buffers for you to use as needed. Uppercase letters append to the buffer.
Buffer and Marking Commands
"bcommand Do command with buffer b.
mx Mark current position with x.
'x Move cursor to first character of line marked by x.
`x Move cursor to character marked by x.
`` Return to exact position of previous mark or context.
'' Return to beginning of the line of previous mark or context.
Introducing the ex Editor
ex Commands
ex file, :1p, :1,3
A command without a line number is assumed to affect the current line.
:s/screen/line/
:1s/screen/line/
Invoke an ex command from vi
:6 move to line 6
ex command in vi
delete d Delete lines.
move m Move lines.
copy co Copy lines.
t Copy lines (a synonym for co).
Line Addresses
:3,18d Delete lines 3 through 18.
:160,224m23 Move lines 160 through 224 to follow line 23. (delete and put in vi.)
:23,29co100 Copy lines 23 through 29 and put after line 100. (yank and put in vi.)
:1,10# To temporarily display the line numbers for a set of lines
:= Print the total number of lines.
:.= Print the line number of the current line.
:/ pattern/= Print the line number of the first line that matches pattern.
Line Addressing Symbols
A dot (.) stands for the current line;
$ stands for the last line of the file.
% stands for every line in the file, same as the combination 1,$.
:.,$d Delete from current line to end of file.
:20,.m$ Move from line 20 through the current line to the end of the file.
:%d Delete all the lines in a file.
:%t$ Copy all lines and place them at the end of the file
+ and - specify an address relative to the current line
:.,+20d Delete from current line through the next 20 lines.
:226,$m.-2 Move lines 226 through the end of the file to two lines above the current line.
:.,+20# Display line numbers from the current line to 20 lines further on in the file.
:-,+t0 Copy line above the cursor through the line below the cursor, put them at the top of the file.
Search Patterns
:/pattern/d Delete the next line containing pattern.
: /pattern/+d Delete the line below the next line containing pattern.
: /pattern1/, / pattern2/d Delete from the first line containing pattern1 through the first line containing pattern2.
:.,/ pattern/m23 Take the text from the current line (.) through the first line containing pattern and put it after line 23.
Difference between vi command and ex command
d/while delete from cursor up to the word while, but leave the remainder of both lines.
:.,/while/d delete the entire range of addressed lines. All lines are deleted in their entirety.
Redefining the Current Line Position
Use a semicolon instead of a comma, the first line address is recalculated as the current line
:100;+5 p The +5 is now calculated relative to line 100
:/pattern/;+10 p print the next line containing pattern, plus the 10 lines that follow it
Global Searches
:g search for a pattern and display all lines containing the pattern
:g! (or its synonym :v) search for all lines that do not contain pattern.
:g/ pattern Finds (moves to) the last occurrence of pattern in the file.
:g/ pattern/p Finds and displays all lines in the file containing pattern.
:g!/ pattern/nu Finds and displays all lines in the file that don't contain pattern, also displays the line number for each line found.
:60,124g/ pattern/p
Combining ex Commands
| combine multiple commands from the same ex prompt, when use the |, ex would keep track of the line addresses. If one command affects the order of lines in the file, the next command does its work using the new line positions.
:1,3d | s/thier/their/
:1,5 m 10 | g/pattern/nu
Saving and Exiting Files
ZZ quit and save your file
:w, :q , :wq, :w!, :q!
:x write and quit
:w practice.new
e! When you want to wipe out all of the edits you have made in a session and then return to the original file.
Saving Part of a File
:230,$w newfile
:.,600w newfile
Appending to an Existing File
:340,$w >>newfile
Copying a File into Another File
:read(or r) filename
:185r /home/tim/data
:$r /home/tim/data
:/ pattern/r /home/tim/data
Editing Multiple Files
vi file1 file2
:n Call in the next file
:args display the argument list, with brackets around the current filename.
:rewind (:rew) reset the current file to be the first file named on the command line
:last move to the last file on the command line.
Calling in New Files
:e filename edit another file within vi
% (current filename) and # (alternate filename)
:e # return to the alternate file
:r # read the alternate file into the current file
:e! discard your edits and returns to the last saved version
:w %.new % stands for the current filename
ctrl+^ switch back to the previous
Edit Between Files
vi commands:
"f4yy Yank four lines into buffer f.
"fp Place yanked text from named buffer f below the cursor.
Ex commands:
:160,224ya a yank (copy) lines 160 through 224 into buffer a
:e anotherfile
:pu a
Global Replacement
Global replacement uses two ex commands, :g (global) and :s (substitute).
:s/old/new/ change the first occurrence of the pattern old to new on the current line.
:s/old/new/g change every occurrence of old to new on the current line
:50,100s/old/new/g
:1,$s/old/new/g
:%s/old/new/g % is same as 1,$
Confirming Substitutions - c
:1,30s/his/the/gc c means confirmation.
n (repeat last search) and dot (.) (repeat last command) is an useful way to page through a file and make repetitive changes.
/which
cwthat ESC
n
.
:%s/editer/editor/g
:g/pattern/s/old/new/g
:g/string/s//new/g pattern being used to find line is the same as the one we want to change
:g/editer/s//editor/g is same as :%s/editer/editor/g
Combine the :g command with :d, :mo, :co and other ex commands besides :s to make global
deletions, moves, and copies.
Pattern-Matching Rules
.,*,^,$,\,[ ],
\( \)
Saves the pattern enclosed between \( and \) into a special holding space or "hold buffer." Up to nine patterns can be saved in this way on a single line.
\(That\) or \(this\) saves That in buffer 1 and saves this in buffer 2.
:%s/\(That\) or \(this\)/\2 or \1/
:s/\(abcd\)\1/alphabet-soup/ changes abcdabcd into alphabet-soup
\< \> Matches characters at the beginning (\<) or at the end (\>) of a word.
\<ac will match only words that begin with ac, such as action.
The expression ac\> will match only words that end with ac, such as maniac.

~ Matches whatever regular expression was used in the last search.
POSIX Bracket Expressions
Character classes keywords bracketed by [: and :]
Collating symbols characters bracketed by [. and .]
Equivalence classes It consists of a named element from the locale, bracketed by [= and =].
All three of these constructs must appear inside the square brackets of a bracket expression.
[[:alpha:]!] matche any single alphabetic character or the exclamation point.
[[.ch.]] matche collating element ch, but does not match just c or h.
In a French locale, [[=e=]] might match any of e, è, or é.
[:graph:], [:lower:], [:print:], [:punct:], [:space:], [:upper:], [:xdigit:]
Metacharacters Used in Replacement Strings
The regular expressions carry special meaning only within the search portion, and in replacement Strings, it is treated literally.
Metacharacters that have special meaning in a replacement string
\ n Is replaced with text matched by the nth pattern previously saved by \( and \)
\
& Is replaced with the entire text matched by the search pattern
When used in a replacement string.
:%s/Yazstremski/&, Carl/
:1,10s/.*/(&)/
~ the string found is replaced with the replacement text specified in the last substitute command.
\u, \l Cause the next character in the replacement string to be changed to uppercase or lowercase, respectively.
:s/\(That\) or \(this\)/\u\2 or \l\1/
\U or \L and \e or \E
\U and \L are similar to \u or \l, but all following characters are converted to uppercase or lowercase until the end of the replacement string or until \e or \E is reached. If there is no
\e or \E, all characters of the replacement text are affected by the \U or \L.
:%s/Fortran/\U&/
:s is the same as :s//~/., and would repeat the last substitution.
:%&g repeat the last substitution everywhere
The & key can be used as a vi command to perform the :& command, i.e., to repeat the last substitution.
:%s:/home/tim:/home/linda:g Use different character as the pattern delimiter
:%s/\<child\>/children/g
:g/mg\([ira]\)box/s//mg\1square/g
Block Move by Patterns
Block definition by patterns
g /SYNTAX/.,/DESCRIPTION/-1 move /PARAMETERS/-1
:g/DESCRIPTION/,/PARAMETERS/-1d
:%s/ */ /g Replace one or more spaces with a single space
.* will match any number of any character.
:%s/: \([^,]*\), \([^;]*\);/: \2 \1;/
:g/^Name/s/: \([^,]*\), \([^;]*\);/: \2 \1;/
:g/^$/d
Using :g to Repeat a Command
:1,10g/^/ 12,17t$ place ten copies of lines 12 through 17 to the end of file
Collecting Lines
:g /^Chapter/ .+2w >> begin
++ means +2.
:/^Part 2/,/^Part 3/g /^Chapter/ .+2w >> begin
:/^Part 2/,/^Part 3/g /^Chapter/ .+2w >> begin | +t$
Customizing vi
The .exrc File
.exrc files can include operating instructions for vi, and can be placed in your home directory, or in current directory. This allows setting options that are appropriate to a particular project.
Enter into this file the set, ab, and map commands
set number autoindent sw=4 terse ignorecase nowrapscan
set tags=/usr/lib/tags
set exrc set the exrc option in your home directory's .exrc file, before vi will read the .exrc file in the current directory.
Define alternate vi environments by saving option settings in a file other than .exrc and reading in that file with the :so command. (so is short for source.)
:so .progoptions
The :set Command
Toggle options:
:set ic specify that pattern searches should ignore case
:set noic return to being case-sensitive in searches
:set all display the complete list of options vi is using
:set show options you have changed, in .exrc file or during current session
set option? find out the current value of any individual option by name
:set wrapmargin=10 specify the size of the right margin that will be used to autowrap text
toggle options:
noignorecase, wrapscan, and magic default settings
ignorecase, nowrapscan, and nomagic
autoindent, showmatch, tabstop, shiftwidth, number, and list
autowrite
Executing UNIX Commands
:!command
:sh create a shell in vi, and exit the shell using exit or pressing CTRL-D.
:r !date
:10r !date
:r !sort phone
Filtering Text Through a Command
:96,99!sort pass lines 96 through 99 through the sort filter and replace those lines with the output of sort.
Filtering text with vi
!)command pass the next sentence through command.
Saving Commands
Word Abbreviation
:ab abbr phrase
:ab imrc International Materials Research Center
:unab abbr
:ab list currently defined abbreviations
Using the map Command
:map x sequence Define character x as a sequence of editing commands.
:unmap x Disable the sequence defined for x.
:map List the characters that are currently mapped.
:map v dwelp reverse the order of two words,delete word,
dw; move to the end of next word, e; move one space to the right, l; put the deleted word there, p.
:map e ea
:map v dwwP
Do case-insensitive search
:set ignorecase(noignorecase)
CASE IN ONE PATTERN
If you want to ignore case for one specific pattern, you can do this by prepending the "\c" string. Using "\C" will make the pattern to match case.
This overrules the 'ignorecase' and 'smartcase' options, when "\c" or "\C" is used their value doesn't matter: \cword

Do Regular Expression Search
/ERROR\|exception\|THROWABLE
%s/old/new/g
This will search every line for 'old' and replace all occurrences in the line with 'new'.
%s translates to all lines, g(for global) affects all occurrences in the lines defined by '%s'.
Limiting the Replace
declare the search and replace for only the current line by removing the percent sign: s/old/new/g

40,42 s/old/new/g
Use Any Delimiter
Alternatively, change your delimiter. It can be anything!
%s!http://!https://!g

Get Confirmation Before Changing
You can get confirmation for each replace by adding a 'c' to the end of your command: %s/old/new/gc
:range g[lobal][!]/pattern/cmd
Execute the Ex command cmd (default ":p") on the lines within [range] where pattern matches. If pattern is preceded with a ! - only where match does not occur.

The global commands work by first scanning through the [range] of of the lines and marking each line where a match occurs. In a second scan the [cmd] is executed for each marked line with its line number prepended. If a line is changed or deleted its mark disappears. The default for the [range] is the whole file.

Ex commands are all commands you are entering on the Vim command line like :s[ubstitute], :co[py] , :d[elete], :w[rite] etc. Non-Ex commands (normal mode commands) can be also executed via
:norm[al]non-ex command
Examples
Delete all empty lines in a file:    :g/^$/ d
Reduce multiple blank lines to a single blank:    :g/^$/,/./-j

Copy all Error line to the end of the file:        :g/^Error:/ copy $

You can give multiple commands after :global using "|" as a separator. If you want to use "|' in an argument, precede it with "\'.
g/^Error:/ copy $ | s /Error/copy of the error/
First modify the string then copy to the end:    g/^Error:/ s /Error/copy of the error/ | copy $
y(for yank) and p (for put)
yw, y$, 4yy, then move to where you want to put the yanked text, then p/P
ex commands in vi
:3,18d Delete lines 3 through 18.
:160,224m23 Move lines 160 through 224 to follow line 23. (delete and put in vi.)
:23,29co100 Copy lines 23 through 29 and put after line 100. (yank and put in vi.)
10x   - delete current 10 characters
dw  - delete current word
dd  - delete current line
5dd - delete five lines

d$  - delete to end of line
d0  - delete to beginning of line

:1,.d   delete to beginning of file
:.,$d   delete to end of file
Resources:
Post a Comment

Labels

Java (159) Lucene-Solr (110) All (60) Interview (59) J2SE (53) Algorithm (37) Eclipse (35) Soft Skills (35) Code Example (31) Linux (26) JavaScript (23) Spring (22) Windows (22) Web Development (20) Tools (19) Nutch2 (18) Bugs (17) Debug (15) Defects (14) Text Mining (14) J2EE (13) Network (13) PowerShell (11) Chrome (9) Continuous Integration (9) How to (9) Learning code (9) Performance (9) UIMA (9) html (9) Design (8) Dynamic Languages (8) Http Client (8) Maven (8) Security (8) Trouble Shooting (8) bat (8) blogger (8) Big Data (7) Google (7) Guava (7) JSON (7) Problem Solving (7) ANT (6) Coding Skills (6) Database (6) Scala (6) Shell (6) css (6) Algorithm Series (5) Cache (5) IDE (5) Lesson Learned (5) Miscs (5) Programmer Skills (5) System Design (5) Tips (5) adsense (5) xml (5) AIX (4) Code Quality (4) GAE (4) Git (4) Good Programming Practices (4) Jackson (4) Memory Usage (4) OpenNLP (4) Project Managment (4) Python (4) Spark (4) Testing (4) ads (4) regular-expression (4) Android (3) Apache Spark (3) Become a Better You (3) Concurrency (3) Eclipse RCP (3) English (3) Firefox (3) Happy Hacking (3) IBM (3) J2SE Knowledge Series (3) JAX-RS (3) Jetty (3) Restful Web Service (3) Script (3) regex (3) seo (3) .Net (2) Android Studio (2) Apache (2) Apache Procrun (2) Architecture (2) Batch (2) Build (2) Building Scalable Web Sites (2) C# (2) C/C++ (2) CSV (2) Career (2) Cassandra (2) Distributed (2) Fiddler (2) Google Drive (2) Gson (2) Html Parser (2) Http (2) Image Tools (2) JQuery (2) Jersey (2) LDAP (2) Life (2) Logging (2) Software Issues (2) Storage (2) Text Search (2) xml parser (2) AOP (1) Application Design (1) AspectJ (1) Bit Operation (1) Chrome DevTools (1) Cloud (1) Codility (1) Data Mining (1) Data Structure (1) ExceptionUtils (1) Exif (1) Feature Request (1) FindBugs (1) Greasemonkey (1) HTML5 (1) Httpd (1) I18N (1) IBM Java Thread Dump Analyzer (1) JDK Source Code (1) JDK8 (1) JMX (1) Lazy Developer (1) Mac (1) Machine Learning (1) Mobile (1) My Plan for 2010 (1) Netbeans (1) Notes (1) Operating System (1) Perl (1) Problems (1) Product Architecture (1) Programming Life (1) Quality (1) Redhat (1) Redis (1) Review (1) RxJava (1) Solutions logs (1) Team Management (1) Thread Dump Analyzer (1) Troubleshooting (1) Visualization (1) boilerpipe (1) htm (1) ongoing (1) procrun (1) rss (1)

Popular Posts