Files
Vim-tutorials/vim-commands

312 lines
9.6 KiB
Plaintext

Normal mode commands:
-> for navigating the file opened in vim:
h: to go left.
l: to go right.
j: to go down.
k: to go up.
ctrl + f: To do page down. Similar to page down button.
ctrl + b: To do page up. Similar to page up button.
z + <enter>: To bring the focus of vision to the top
where the cursor is currently present.
z + z: To bring the focus of vision to the center
where the cursor is currently present.
w: To move the cursor by one word on the file. It include the
punctuation as a word.(move one word forward)
W: To move the cursor by one word on file. It don't include the
punctuation as a word.(move one word forward)
b: To move the cursor by one word on file. It include the
punctuation as a word.(move on word backward)
B: To move the cursor by one word on file. It don't include the
punctuation as a word.(move on word backward)
0: To move the first column of the current line the cursor
is present.
^: To move the first letter of the first word of the current
line the cursor is present.
$: To move the last letter of the last word of the current
line the cursor is present.
gg: To move the first column of the first line of the file.
G: To move to the last line of the file.
<line-number>gg or <line-number>G: To move the particular
<line-number> as mentioned.
ctrl + g: To know the current line we are on, the file name,
the percentage of we have covered according to
current cursor position.
g + (ctrl+g): To get more detailed information of whatever
the previous was showing.
-> Deleting text from file in normal mode:
x: To delete the right side byte of the current cursor position.
X: To delete the left side byte of the current cursor position.
Using d to delete words with motion operation:
<operation>{motion}
for ex:
dw (this delete the what the w command would move
the cursor by)
dw: To delete a word in front of the current cursor position.
dl: To delete next byte towards right from current cursor position on
current line.
dh: To delete next byte towards left from current cursor position on
current line.
dj: To delete whole current line and the line below.
dk: To delete whole current line and the line above.
d$: To delete from current position of cursor to the end of
the line.
d0: To delete from current position to the first letter of the
current line the cursor is present.
D: Equivalent of of what d$
dd: To delete the current line entirely no matter where the cursor
is present currently on that same line.
<number>dd: To delete the 3 lines below from current line where
the cursor is present.
Note: <number><delete-command> is telling in short hand on how many
times the delete-command given should be executed. Same as the
command shown above (<number>dd).
<number>dw: delete-word command to be executed <number> numbers of times.
For ex:
3w = Repeat word motion 3 times.
d3w = Delete the 3w motion.
2d3w = Delete the 3w motion 2 times.
Line mode:
-> for navigating using line mode:
:<line-number><enter> : To go to the particular <line-number>.
:$<enter> : To move to the last line in the file.
!(exclamation mark): This Operator can be used to force the commands
for ex:
:q! is used to force quit the vim even if the changes on files
are not saved.
-> help command (for vim documentation):
:help <enter> : It will open vim documentation.
:help [command] : It will open documentation to a specific location where
the specification for that specific command is present.
:help {subject} : It will open documentation to a specific location where
the specification for the given subject.
:h : It is a short cut for :help in line mode.
(CTRL+w) + (CTRL+w): It is used to switch b/w windows currently open in vim
for editing.
(CTRL+o): Take you to the location where the previous search is done in the
document.
(CTRL+i): Take you to the location where the next search is done in the
document.
(CTRL+]): Place the cursor on the "subject" you want to search (for ex. linewise)
and press this command.
Note: Anything between [] in help documentation means it is optional in vim.
For autocompleting a command which is to be searched in help documentation
click CTRL+D, which shows suggestation. To iterate through all the suggestion
without writing it explicity use <TAB> key. To iterate in reverse order use
<SHIFT>+<TAB>.
-> Cut, Copy and Paste:
* d and x cut text, not just delete it.
* cut = delete and save into a register.
* Register is a clipboard-like storage location.
* This register is also known as default register or unnamed register.
> for pasting the text present in the default register use p command.
> if the line is cut using dd command then using 'p' will paste it below the current line where
the cursor is present.
> if 'P' command is used then it will paste above the current line where the cursor is
present.
> if a character is cut using 'x' or 'X' command using 'p' will paste the character
just after the current postion of the cursor.
> similarly, if 'P' command is used it will paste the character just before the current
position of the cursor.
Note:
> The data cutted is linewise then it will paste below/above current line.
> The data cutted is characterwise then it will paste before or after the current line.
> Standard - Vim terminology:
Cut = Delete
Copy = yank
paste = put
> for yanking(copying) use 'y' command.
> Just like 'd' command behavior with 'p' command is same.
* Undo command:
> To undo the action of previous command, use 'u' command to
undo the action.
> To redo the same command undone by undo 'u' command use 'CTRL+r'
command.
* Type of registers:
> Named registers : "a to "z
> Number register : "0 to "9
> unnamed register : ""
> unnamed register contains the data with acquired from one of the
commmands d, x, c, y and s.
c -> , s -> substitute.
> "0 : Most recently yanked data
> "1 : The data which is deleted recently.
> "2 : The data which was deleted second last time.
> "3 : and so on till "9....
> use :reg to see the content of each register.
> use :reg <arg>
wherer arg -> register name to show the content
+ arg can be string containing all the
registers named concatenated into a
single string.
-> Transforming and Substituting:
* Inserting:
@ Command :- Shift + i or CAPS + i (Capital i)
What does it do?
It put the mode in insert mode and put the cursor in
the first character of the first word of the current
line where the cursor is present.
@ Command :- Shift + a or CAPS + a (Capital a)
What does it do?
It put the mode in insert mode and put the cursor after
the last character of the last word of the current
line where the cursor is present.
@ Command :- o
What does it do?
It puts the mode in insert mode and put the cursor below
the line where the current cursor is present.
@ Command :- Shift + o
What does it do?
It puts the mode in insert mode and put the cursor above
the line where the current cursor is present.
* Replacing (Replace Mode):
@ Command :- Shift + r or CAPS + r (Capital r)
What does it do?
It pust the mode in replace mode. In replace mode, wherever
the cursor is present, it will start to replace each character
as we type and the previous character will be over-written by the
new character.
* Changing (Changing Mode):
@ Command :- <optional-register> + c + <word-motion>
What does it do?
It delete the series of bytes, based on the word-motion given,
and put the mode in INSERT mode. <word-motion> can be any
type of word motion that we have learnt. Here, <optional-register>
can be used to put the deleted or "replaced" word into the register
which we use to store as intended.
For example:
"a + c + w
It will store the word into register "a which is replaced by using
command c + w.
@ Command :- Shift + c or CAPS + c (capital + c)
What does it do?
Replace the sequence of characters from current cursor position is present at till end
of the line.
@ Command :- cc
Replace the entire current line where the cursor is present.
@ Command :- ~
What does it do?
Switch over the case of the character where the current is present.
@ Command :- g + ~ + <motion-command>
What does it do?
Switch over the cases of the each character based on the motion command
range.
@ Command :- g + U + <motion-command>
What does it do?
Changes the entire case of each character to upper-case based on the motion command
range.
@ Command :- g + u + <motion-command>
What does it do?
Changes the entire case of each character to lower-case based on the
motion comand range.
-> Joining:
@ Command :- Shift + j or CAPS + j (Capital + j)
What does it do?
Joins the line below the current line where the cursor is present
to single line and add a space to it or add a double space if there
is a period at the end of the current line.
@ Command :- g + J + <motion-command>
What does it do?
Do the same thing as "J" command. Only difference is that it doesn't
add any space between joining lines.