Created
September 10, 2011 04:44
-
-
Save jondkinney/1207932 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Lesson 2 SUMMARY | |
1. To delete from the cursor up to the next word type: dw | |
2. To delete from the cursor to the end of a line type: d$ | |
3. To delete a whole line type: dd | |
4. To repeat a motion prepend it with a number: 2w | |
5. The format for a change command is: | |
operator [number] motion | |
where: | |
operator - is what to do, such as d for delete | |
[number] - is an optional count to repeat the motion | |
motion - moves over the text to operate on, such as w (word), | |
$ (to the end of line), etc. | |
6. To move to the start of the line use a zero: 0 | |
7. To undo previous actions, type: u (lowercase u) | |
To undo all the changes on a line, type: U (capital U) | |
To undo the undo's, type: CTRL-R | |
Lesson 3 SUMMARY | |
1. To put back text that has just been deleted, type p . This puts the | |
deleted text AFTER the cursor (if a line was deleted it will go on the | |
line below the cursor). | |
2. To replace the character under the cursor, type r and then the | |
character you want to have there. | |
3. The change operator allows you to change from the cursor to where the | |
motion takes you. eg. Type ce to change from the cursor to the end of | |
the word, c$ to change to the end of a line. | |
4. The format for change is: | |
c [number] motion | |
Lesson 4 SUMMARY | |
1. CTRL-G displays your location in the file and the file status. | |
G moves to the end of the file. | |
number G moves to that line number. | |
gg moves to the first line. | |
2. Typing / followed by a phrase searches FORWARD for the phrase. | |
Typing ? followed by a phrase searches BACKWARD for the phrase. | |
After a search type n to find the next occurrence in the same direction | |
or N to search in the opposite direction. | |
CTRL-O takes you back to older positions, CTRL-I to newer positions. | |
3. Typing % while the cursor is on a (,),[,],{, or } goes to its match. | |
4. To substitute new for the first old in a line type :s/old/new | |
To substitute new for all 'old's on a line type :s/old/new/g | |
To substitute phrases between two line #'s type :#,#s/old/new/g | |
To substitute all occurrences in the file type :%s/old/new/g | |
To ask for confirmation each time add 'c' :%s/old/new/gc | |
Lesson 5 SUMMARY | |
1. :!command executes an external command. | |
Some useful examples are: | |
(MS-DOS) (Unix) | |
:!dir :!ls - shows a directory listing. | |
:!del FILENAME :!rm FILENAME - removes file FILENAME. | |
2. :w FILENAME writes the current Vim file to disk with name FILENAME. | |
3. v motion :w FILENAME saves the Visually selected lines in file | |
FILENAME. | |
4. :r FILENAME retrieves disk file FILENAME and puts it below the | |
cursor position. | |
5. :r !dir reads the output of the dir command and puts it below the | |
cursor position. | |
Lesson 6 SUMMARY | |
1. Type o to open a line BELOW the cursor and start Insert mode. | |
Type O to open a line ABOVE the cursor. | |
2. Type a to insert text AFTER the cursor. | |
Type A to insert text after the end of the line. | |
3. The e command moves to the end of a word. | |
4. The y operator yanks (copies) text, p puts (pastes) it. | |
5. Typing a capital R enters Replace mode until <ESC> is pressed. | |
6. Typing ":set xxx" sets the option "xxx". Some options are: | |
'ic' 'ignorecase' ignore upper/lower case when searching | |
'is' 'incsearch' show partial matches for a search phrase | |
'hls' 'hlsearch' highlight all matching phrases | |
You can either use the long or the short option name. | |
7. Prepend "no" to switch an option off: :set noic | |
Lesson 7 SUMMARY | |
1. Type :help or press <F1> or <Help> to open a help window. | |
2. Type :help cmd to find help on cmd . | |
3. Type CTRL-W CTRL-W to jump to another window | |
4. Type :q to close the help window | |
5. Create a vimrc startup script to keep your preferred settings. | |
6. When typing a : command, press CTRL-D to see possible completions. | |
Press <TAB> to use one completion. | |
Code Folding - use markers which look like "{{{1" | |
Movement | |
-------- | |
w - skips to the beginning of the next word, including periods and most other chars | |
W - skips to the next word based on whitespace | |
b - skips to the beginning of the previous word | |
B - skips back based on whitespace | |
e - skips to the end of the next word | |
E - skips to the end based on whitespace | |
ge - skips to the end of the previous word | |
gE - skips to the end of the previous based on whitespace | |
$ - end of the line | |
0 - beginning of the line | |
f+char - takes you to the first "char" so.. "f/" would take you to the first slash. Then ";" repeats it though I can't get that to work | |
t+char - takes you until the char you specify so... "f/" would take you to just before the / in the direction you're going | |
ctrl+f - page down | |
ctrl+b - page up | |
ctrl+u - 1/2 page down | |
ctrl+d - 1/2 page down | |
M - middle line | |
H - head | |
L - Last line on the current page | |
* - highlights a word of the current word that you're on | |
# - matches the full word you're on starting backwards | |
g* - partial matches of a word going forward - can use n to go forward and N to go backwards | |
g# - partial match of a word going backwards | |
/ and ? are regex. / goes forward, ? goes backwards | |
More Jumping Around | |
------------------- | |
[ and ] let you jump to { braces. % lets you jump between braces and quotes, etc | |
ma - marking and jumping - you can mark a line or a char in a line then return later. | |
:marks - shows you what marks you have in vim | |
-> if you go to line 20 with "20G" then you can type single quote single quote '' to get back to where you were | |
-> you can also use the backtick ` to go to the exact spot on the line you were | |
Editing | |
------- | |
i - normal drop into insert mode | |
I - start editing at the beginning of the line | |
a - starts inserting after the current cursor position | |
A - starts inserting at the end of the line | |
o - drops you down a line and puts you in insert mode | |
O - drops you above the current line in insert mode | |
d - deletes things | |
dw - deletes word and space | |
de - deletes word but leaves space | |
dd - deletes full line | |
5dd - deletes 5 lines | |
. - repeats the previous command | |
r - single character replace | |
R - overwrite mode | |
c - change | |
cw - change just the current word | |
c3w - change 3 words to be other stuff | |
s - substitute, similar to change - but stick with change perhaps? | |
:set cpoptions+=$ - this will show you the $ sign when you're changing words | |
Turn on virtualedit | |
yy - yanks a line, Y also yanks a full line | |
p - puts the line or word | |
shift+P - puts the line above | |
yw - yanks just the word | |
J - joins a line | |
gJ - joins the line without a space | |
v - turns on visual mode | |
V - highlights the current line (then you can nav up and down with j,k) | |
ctrl+v - turns on block edit mode. Then you can select stuff with the typical movement commands and then hit escape and it'll propogate to the other lines. It doesn't do it realtime like textmate | |
gv - vertical highlighting re-highlight what was just selected | |
Buffers | |
------- | |
:b buffer_name - switches to that buffer, tab complete-able | |
:bd - deletes the current buffer | |
:bd number - deletes that number buffer | |
:bd % - deletes all the buffers | |
:b# - switches between two buffers | |
:wall - write all unsaved buffers | |
:bufdo - allows you to iterate over the current buffers | |
:n - next takes you to the next file | |
:bfirst - takes you to the first buffer | |
:bn - next buffer | |
:bp - previous buffer | |
:e - will edit a file | |
Windows | |
------- | |
ctrl + w + x - switches the two splits | |
:vsplit or :vsp | |
:split or :sp | |
ctrl + w + c - closes the current split | |
ctrl + w + o - closes the windows except for your current one (the window configuration is gone) | |
look at mapping ",hjkl" to move to the different splits | |
then ctrl + w + shift + hjkl to move the split around | |
ctrl + w + p - takes you to the previous | |
ctrl + w + ctrl + w - cycles through splits | |
VIMRC and Vim Runtime | |
--------------------- | |
:helptags - re-parses the files in the ~/.vim/doc directory and pulls out the tags file. Allows you to have your own documentation | |
Vim Modes | |
--------- | |
When in visual mode you can change to select mode with "ctrl + g" then you can replace your selection | |
ctrl + o - lets you do a single normal mode command and then it flips you back to insert | |
Insert Mode | |
----------- | |
ctrl + d and ctrl + t - move your tab indent forward and back | |
insert mode completion - type something and then hit "ctrl + n" | |
ctrl + x + ctrl + l - allows you to complete complete lines | |
ctrl + x + ctrl + f - allows you to complete files | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment