VIM
From Vaddina.com
Contents |
Basic Commands
Save and exit
Save the current file as a new file with the name, file-name
Quit
Forced quit. All changes are lost
save
Move the cursor to home
Move the cursor to the end of the line
Page-up
Page-down
Moves the cursor back to one word back
Moves the cursor forward by one word
Start inserting text at the beginning of the current line
Start inserting text at the end of the current line
Move to the next/previous tab window in the editor
Copy/Yank
Yank the current line. The 8, indicates the number of lines to be yanked.
Yank a the current character
Yank a word from the current cursor position
Yank from the current cursor position to the end of the line
Yank from the current cursor position to the end of the sentence
Copies the specified number of lines starting from the current line to the clipboard. Ex: "*23yy --> Will copy, 23 lines
Paste
When p, pastes the text, before the current position of the cursor. Similarly, P, pastes the text after the current cursor.
Paste the contents of the clipboard. When 'p' is used, the text is copied before the cursor and when 'P' is used, after the cursor
Cut/Delete
Internal Cut
Cuts the current line. The 8, indicates the number of lines to be cut.
Search/Replace
All occurances of the <search-word> are highlighted.
- 'n' --> Moves to the next occurrance of the search word
- 'N' --> Moves to the previous occurrance of the search word
Replace all occurrances of the search-word, old with the word, new, and ask for confirmation Examples
- [range]-->The range in the file through which the subsitute command works.
- '%' --> Use the entire file
- '$' --> Use the last line of the file
- 1,100 --> Use the command from line 1 to line 100
- 37 --> Apply the command on line 37 only
- 'g'-->Substitute all occurrances in the line. Without this only the first occurrance of the line will be replaced
- 'c'-->Prompt for confirmation
- 'i'-->Ignore case of the search string
- 'I'-->Do not ignore case
Use the above command to insert text at the beginning of every line in the file.
Use the above command to insert text at the end of every line in the file.
Use the above command to insert text at the beginning of every line of a selection.
In all the below cases, to delete lines that does not match the corresponding patters, use either v or g!
Delete all lines that begins with #. Note that the ^ is used to indicate the beginning of the line. Ignoring it will search the whole line for the character # and deletes the line
Delete all lines that are empty
Search the whole file for lines which begin with, search_text, and then insert the text, add_text at the beginning. Please note that by default the range of the above command is % (the whole file), contrary to the command, substitute, which works only on a single line.
Insert text at the beginning of all lines, that are non-empty
Search the file for lines having atleast one character, beginning with either of a-z or A-Z and then insert the text, add_text at the beginning of the line
Search the file for lines having more than one character, beginning with either of a-z or A-Z and then insert the text, add_text at the beginning of the line
Search the file for lines beginning with echo and then insert the text, add_text at the end of the line
Some advanced VIM Search and Replace commands at this link:
http://www.brezeale.com/technical_notes/vim_notes.shtml#search
Diff
Starting the diff view
Shows the diff between the two files
Commands to use in diff
Show the next difference
Show the previous difference
To replace a diff in the current viewport with that from the other viewport
To replace a diff in the other viewport with that from the current viewport
Bookmarks
Shall assign a bookmark to the current line with the character, <letter>
Move to the bookmark marked with the character, <letter>
vimrc hacks
Insert the following lines in the vimrc file to insert spaces instead of tab characters, and to choose the number of spaces to insert for a tab
set shiftwidth=2
set expandtab
Character case's
Convert the selected text to Uppercase/Lowercase respectively.
Will apply the Uppercase command to the whole file. Every character will be in Uppercase. Similarly, guGG can be used to convert all characters to lowercase.
Will look for word monitor (case insensitive) in the current buffer and converts it to MONITOR
Will look for word monitor (case insensitive) in the current buffer and converts it to monitor
Will look for word monitor (case insensitive) in the current buffer and converts it to the title format Monitor
Spaces/Tabs
2. <<
3. <
Command to move to the left, the current line in Insert mode, the current line in command mode and the current selection in visual mode, respectively.
2. >>
3. >
Command to move to the right, the current line in Insert mode, the current line in command mode and the current selection in visual mode, respectively.
Miscelleneous
Toggle the cases of all the characters of the selection
Enters visual mode
Selects the entire line
Find the matching braces, brackets, etc ...
Will create a new tab. Only with VIM versions greater than 7.0
Displays all the bookmarks
Sets line numbers in the file
Turn on/off syntax highlighting with the default colors
Vertical split of the text editor
When the editor screen is split into two vertical halfs, the above key combination can be used to navigate between the two split screens