mirror of
https://github.com/Hizenberg469/Vim-tutorials.git
synced 2026-04-19 22:02:24 +03:00
moved my notes to my-learning
This commit is contained in:
796
\
796
\
@@ -1,796 +0,0 @@
|
|||||||
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.
|
|
||||||
|
|
||||||
|
|
||||||
-> Searching commands:
|
|
||||||
|
|
||||||
|
|
||||||
@ Command :- f + <character>
|
|
||||||
|
|
||||||
What does it do?
|
|
||||||
|
|
||||||
Searches for the next occurence of the character passed as an argument
|
|
||||||
from current cursor position on the same line.
|
|
||||||
NOTE THE WORD, SAME LINE.
|
|
||||||
|
|
||||||
@ Command :- F + <character>
|
|
||||||
|
|
||||||
What does it do?
|
|
||||||
|
|
||||||
Do the same thing as previous command, but in opposite direction.
|
|
||||||
|
|
||||||
@ Command :- ;
|
|
||||||
|
|
||||||
What does it do?
|
|
||||||
|
|
||||||
It repeat the command from the above two, whichever was executed
|
|
||||||
first. For example, if F + <character> is executed, it will repeat
|
|
||||||
the same command.
|
|
||||||
|
|
||||||
@ Command :- ,
|
|
||||||
|
|
||||||
What does it do?
|
|
||||||
|
|
||||||
It do the opposite of what ";" command does. For example, if
|
|
||||||
F + <character> is executed, it will execute f + <character>
|
|
||||||
action, repeatedly. It will do the opposite of whichever
|
|
||||||
above mentioned command was executed first.
|
|
||||||
|
|
||||||
@ Command :- t + <character>
|
|
||||||
|
|
||||||
|
|
||||||
What does it do?
|
|
||||||
|
|
||||||
It search for the <character> and place the cursor just one
|
|
||||||
position before the current cursor. Note that, using the same
|
|
||||||
command again will not move the cursor to next position w.r.t
|
|
||||||
same <character> that was mentioned earlier.
|
|
||||||
|
|
||||||
We can use ";" and "," command to repeat the mentioned command
|
|
||||||
even if the cursor is present just before the searched <character>,
|
|
||||||
it pass through the current <character> position.
|
|
||||||
|
|
||||||
Note that the searching is done from left to right.
|
|
||||||
|
|
||||||
@ Command :- T + <character>
|
|
||||||
|
|
||||||
What does it do?
|
|
||||||
|
|
||||||
It perform operation and behave in similar manner as done by t +
|
|
||||||
<character> command. But, the searching is done in reverse order.
|
|
||||||
|
|
||||||
**Note**
|
|
||||||
|
|
||||||
All these are motion-commands. That means, we can use it with Editing
|
|
||||||
commands like d (delete), c (changing), y (yanking), etc.
|
|
||||||
|
|
||||||
|
|
||||||
@ Command :- /<string>
|
|
||||||
|
|
||||||
What does it do?
|
|
||||||
|
|
||||||
It searches for the <string>.
|
|
||||||
|
|
||||||
Using "n" command will search for next <string> occurance in current
|
|
||||||
opened file.
|
|
||||||
|
|
||||||
Using "N" command does the same thing. But, in opposite direction.
|
|
||||||
|
|
||||||
**Note**
|
|
||||||
|
|
||||||
For "/" command for searching the incsearch option should be set.
|
|
||||||
|
|
||||||
If it is not, we can use following line command:
|
|
||||||
|
|
||||||
:set is
|
|
||||||
|
|
||||||
To check if the configuration is set use command:
|
|
||||||
|
|
||||||
:set is?
|
|
||||||
|
|
||||||
For highlighting the searches, check for:
|
|
||||||
|
|
||||||
Check :set hls?
|
|
||||||
|
|
||||||
Output: nohlsearch
|
|
||||||
|
|
||||||
Do: :set hls
|
|
||||||
|
|
||||||
Note that hlsearch is enabled will highlight the <string>s' until
|
|
||||||
new search is done which in turn highlight the new <string>.
|
|
||||||
To turn off the highlight, use:
|
|
||||||
|
|
||||||
:nohls.
|
|
||||||
|
|
||||||
It will turn-off the highlights not disable it permanently.
|
|
||||||
|
|
||||||
|
|
||||||
%% Trick %%
|
|
||||||
|
|
||||||
> Using "/" command to find a string or string containing the pattern specified
|
|
||||||
and pressing enter will take to the first such matching string.
|
|
||||||
|
|
||||||
> If we now use "c + w" command the cursor which is present at the first letter
|
|
||||||
of the word will delete that word and we type certain word.
|
|
||||||
|
|
||||||
> After getting out of the insert mode, pressing "n" command will move the cursor
|
|
||||||
the cursor to the next string and pressing the command "." will repeat the changes
|
|
||||||
that we did for first string i.e. repeat the process that we performed above.
|
|
||||||
|
|
||||||
|
|
||||||
@ Command: "?<string-pattern>
|
|
||||||
|
|
||||||
|
|
||||||
What does it do?
|
|
||||||
|
|
||||||
It search for the string matching the pattern in reverse direction of the current
|
|
||||||
cursor postion.
|
|
||||||
|
|
||||||
Here, "n" search for next pattern match in reverse direction. "N" does the reverse
|
|
||||||
of what "n" command does.
|
|
||||||
|
|
||||||
|
|
||||||
@ Command: "*"
|
|
||||||
|
|
||||||
What does it do?
|
|
||||||
|
|
||||||
It search for the next occurances of the exact string(not string-pattern) which is near or where
|
|
||||||
the current cursor is positioned.
|
|
||||||
|
|
||||||
|
|
||||||
@ Commmand: "#"
|
|
||||||
|
|
||||||
What does it do?
|
|
||||||
|
|
||||||
It seah for the next occurances of the exact string(not string-pattern) which is near or where
|
|
||||||
the current cursor is positioned.
|
|
||||||
|
|
||||||
%% TIPS %%
|
|
||||||
|
|
||||||
We can use editing commands like deleting(d), yanking(y), etc. with these searching command.
|
|
||||||
|
|
||||||
For ex:
|
|
||||||
|
|
||||||
Pressing "d" command and then using "/<string-pattern>" will leads to deleting of characters
|
|
||||||
from the current cursor position to the next occurance of the <string-pattern>.
|
|
||||||
|
|
||||||
Pressing "<register-name> with "y" command and then using "/<string-pattern>" will leads to
|
|
||||||
yanking(copying) from the current cursor position to the next occurance of the <string-pattern>.
|
|
||||||
|
|
||||||
|
|
||||||
@ Command : [range]s/<old>/<new>/[flag] (Its a line command)
|
|
||||||
^ ^
|
|
||||||
| |
|
|
||||||
optional optional
|
|
||||||
|
|
||||||
|
|
||||||
What does it do?
|
|
||||||
|
|
||||||
It replace the occurance of old string to new string over the range
|
|
||||||
in the file.
|
|
||||||
|
|
||||||
[flag]
|
|
||||||
|
|
||||||
* g : It represent to replace all the occurance of <old> to <new> in
|
|
||||||
current line where the cursor is present.
|
|
||||||
|
|
||||||
|
|
||||||
[range]
|
|
||||||
|
|
||||||
Define the range of this command. Could be single line, multiple line
|
|
||||||
and even all the lines in the file, etc.
|
|
||||||
|
|
||||||
* <line-number> : On which line number this command to be executed.
|
|
||||||
To execute the command on same line as cursor,
|
|
||||||
don't mention <line-number>.
|
|
||||||
|
|
||||||
* <start-line-number>,<end-line-number> : From the starting line number
|
|
||||||
to the ending line number to
|
|
||||||
to execute the command.
|
|
||||||
|
|
||||||
For ex:
|
|
||||||
:1s/<old>/<new>/g
|
|
||||||
|
|
||||||
It will replace <old> with <new> in the entire line of line number 1.
|
|
||||||
|
|
||||||
:1,5s/<old>/<new>/g
|
|
||||||
|
|
||||||
It will do the same form line number 1 to 5.
|
|
||||||
|
|
||||||
:/<Pattern-1>/,/<Pattern-2>/s/<old>/<new>/g
|
|
||||||
|
|
||||||
It will do the same from line which has pattern matching with
|
|
||||||
with <Pattern-1> and ending with line which has pattern
|
|
||||||
matching with pattern <Pattern-2>.
|
|
||||||
|
|
||||||
|
|
||||||
------------------------------------
|
|
||||||
|
|
||||||
|
|
||||||
$ = last line; . = current line
|
|
||||||
|
|
||||||
:.,$s/<old>/<new>/g
|
|
||||||
|
|
||||||
% = All the line (entire file)
|
|
||||||
|
|
||||||
:%s/<old>/<new>/g
|
|
||||||
|
|
||||||
-----------------------------------
|
|
||||||
|
|
||||||
|
|
||||||
For including character such as "/" for <old> and <new>
|
|
||||||
we can use "\" which is a escape character.
|
|
||||||
|
|
||||||
For ex:
|
|
||||||
|
|
||||||
:s/\/<old>\//\/<new>\//
|
|
||||||
|
|
||||||
OR
|
|
||||||
|
|
||||||
we can use other non-alphanumeric character as a separator.
|
|
||||||
|
|
||||||
For ex:
|
|
||||||
|
|
||||||
:s#/<old>/#/<new>/
|
|
||||||
|
|
||||||
%% TIPS %%
|
|
||||||
|
|
||||||
To set options in VIM, we can use :set <option> command.
|
|
||||||
|
|
||||||
* To set a option to show the line number of the current opened file in the vim
|
|
||||||
we use:
|
|
||||||
:set nu
|
|
||||||
|
|
||||||
* To undo this:
|
|
||||||
|
|
||||||
:set nonu
|
|
||||||
* To toggle the current configuration.
|
|
||||||
|
|
||||||
:set nu!
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-> Text Objects and Macros:
|
|
||||||
|
|
||||||
**** Text Objects ****
|
|
||||||
@ Command: {operator}{a}{object}
|
|
||||||
|
|
||||||
What does it do?
|
|
||||||
|
|
||||||
It perform operation on a word, from the starting character of the word, eventhough the
|
|
||||||
cursor maybe present in the middle of the same word.
|
|
||||||
It will also perform perform operation on the space after that word until a new or a character is
|
|
||||||
encountered.
|
|
||||||
|
|
||||||
For ex:
|
|
||||||
|
|
||||||
daw = Delete A Word
|
|
||||||
|
|
||||||
@ Command: {operator}{i}{object}
|
|
||||||
|
|
||||||
What does it do?
|
|
||||||
|
|
||||||
It perform operation on a word, from the starting charcter of the word, eventhough the cursor
|
|
||||||
maybe present in the middle of the same word.
|
|
||||||
However, unlike {a} operator, it will not perform operation on the space after the word to
|
|
||||||
be deleted.
|
|
||||||
|
|
||||||
For ex:
|
|
||||||
|
|
||||||
ciw = Change Inner Word.
|
|
||||||
|
|
||||||
@ Command: {operator}{as}
|
|
||||||
|
|
||||||
For ex:
|
|
||||||
|
|
||||||
das = Delete a Sentence
|
|
||||||
|
|
||||||
What does it do?
|
|
||||||
|
|
||||||
It will delete a sentence until the period, including the space after the period
|
|
||||||
until the next character is encountered.
|
|
||||||
|
|
||||||
@ Command: {operator}{is}
|
|
||||||
|
|
||||||
For ex:
|
|
||||||
|
|
||||||
dis: Delete inner Sentence
|
|
||||||
|
|
||||||
What does it do?
|
|
||||||
|
|
||||||
It wil delete a sentence until the period, but the space after the period.
|
|
||||||
|
|
||||||
Note:
|
|
||||||
|
|
||||||
Vim consider line-break as part of the sentence.
|
|
||||||
|
|
||||||
%% TIPS %%
|
|
||||||
|
|
||||||
To repeate these command we can use "." command.
|
|
||||||
|
|
||||||
|
|
||||||
@ Command: {operator}{ap}
|
|
||||||
|
|
||||||
For ex:
|
|
||||||
|
|
||||||
dap = Delete a paragraph
|
|
||||||
|
|
||||||
What does it do?
|
|
||||||
|
|
||||||
It will delete a paragraph until the boundary of the paragraph object,
|
|
||||||
including the blank line.
|
|
||||||
|
|
||||||
@ Command: {operator}{ip}
|
|
||||||
|
|
||||||
For ex:
|
|
||||||
|
|
||||||
dip = Delete a paragraph
|
|
||||||
|
|
||||||
What does it do?
|
|
||||||
|
|
||||||
It will delete a paragraph until the boundary of the paragraph object,
|
|
||||||
i.e. the blank line. However, it does not include the blank line.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ Command: {operator}{a<symbol>} and {operator}{i<symbol>}
|
|
||||||
|
|
||||||
<symbol>
|
|
||||||
|
|
||||||
{ } or B, ( ) or b, < >, ' ', " ", [ ],` `
|
|
||||||
For ex:
|
|
||||||
|
|
||||||
di{ or di}
|
|
||||||
|
|
||||||
What does it do?
|
|
||||||
|
|
||||||
It will delete anything between { }. With "a" operator
|
|
||||||
will also delete the { }.
|
|
||||||
|
|
||||||
dab or da( or da)
|
|
||||||
|
|
||||||
What does it do?
|
|
||||||
|
|
||||||
It will delete anything between ( ) including the brackets.
|
|
||||||
|
|
||||||
|
|
||||||
%% TIPS %%
|
|
||||||
|
|
||||||
This command is benificial for programming languages.
|
|
||||||
|
|
||||||
|
|
||||||
at and it
|
|
||||||
|
|
||||||
t here means tags.
|
|
||||||
|
|
||||||
It will helpful for programming languages with opening
|
|
||||||
and closing tags like html and xml.
|
|
||||||
|
|
||||||
Even custom made tags are applicable in this case.
|
|
||||||
|
|
||||||
|
|
||||||
**** Macros ****
|
|
||||||
|
|
||||||
Macros are recorded to a register of vim. (named register)
|
|
||||||
|
|
||||||
%% To recored a macro %%
|
|
||||||
|
|
||||||
Use command: q<register-name>
|
|
||||||
|
|
||||||
It will start the recording.
|
|
||||||
|
|
||||||
Recording ends by using only the command "q".
|
|
||||||
|
|
||||||
%% To use the recorded macro %%
|
|
||||||
|
|
||||||
Use Command: @<register-name>
|
|
||||||
|
|
||||||
%% To use last recorded macro %%
|
|
||||||
|
|
||||||
Use command: @@
|
|
||||||
|
|
||||||
|
|
||||||
Macro Best Practices
|
|
||||||
--------------------
|
|
||||||
|
|
||||||
* Normalize the cursor position
|
|
||||||
-> 0
|
|
||||||
|
|
||||||
* Perform edits and operations.
|
|
||||||
|
|
||||||
* Position you cursor to enable easy replays.
|
|
||||||
-> j
|
|
||||||
|
|
||||||
%% TIPS %%
|
|
||||||
|
|
||||||
After recording macros to certain register, we can again append to
|
|
||||||
more macros to the register by using q+<Capital-register>.
|
|
||||||
For ex:
|
|
||||||
|
|
||||||
q+A instead of q+a.
|
|
||||||
|
|
||||||
|
|
||||||
This is true for appending anything to the register.
|
|
||||||
|
|
||||||
|
|
||||||
Applying Macros of particular register on the range of line:
|
|
||||||
------------------------------------------------------------
|
|
||||||
|
|
||||||
Use command:
|
|
||||||
|
|
||||||
:<start-line-number>,<end-line-number>normal @<register-name>
|
|
||||||
|
|
||||||
From all the line the file.
|
|
||||||
|
|
||||||
|
|
||||||
Use command:
|
|
||||||
|
|
||||||
:.,$normal @<register-name>
|
|
||||||
|
|
||||||
Saving Macros
|
|
||||||
---------------
|
|
||||||
|
|
||||||
* viminfo file
|
|
||||||
|
|
||||||
+ .viminfo ( for unix like system like LINUX or MAC )
|
|
||||||
+ _viminfo ( for windows like system )
|
|
||||||
* Stores history and non-empty registers.
|
|
||||||
* Read when vim starts.
|
|
||||||
* Can easily overwrite registers.
|
|
||||||
|
|
||||||
* vimrc files
|
|
||||||
|
|
||||||
+ .vimrc
|
|
||||||
+ _vimrc
|
|
||||||
|
|
||||||
We can define macros in register inside vimrc file.
|
|
||||||
|
|
||||||
let @<register-name> = '<Marcro>'
|
|
||||||
|
|
||||||
%% TIPS %%
|
|
||||||
|
|
||||||
To know the character of certain key-stroke, like Esc character.
|
|
||||||
|
|
||||||
We can know this by being in insert mode then type CTRL+v and the
|
|
||||||
Key for which we want to know the character.
|
|
||||||
|
|
||||||
|
|
||||||
-> Visual mode:
|
|
||||||
|
|
||||||
|
|
||||||
Use v to start characterwise visual mode.
|
|
||||||
Use V to start linewise visual mode.
|
|
||||||
Use Ctrl-v to start blockwise visual mode.
|
|
||||||
|
|
||||||
You can use motions to expand the visual area.
|
|
||||||
You can also use text objects to expand the visual area.
|
|
||||||
|
|
||||||
Just some of commands you can use in visual mode include:
|
|
||||||
~ - Switch case
|
|
||||||
c - Change
|
|
||||||
d - Delete
|
|
||||||
y - Yank
|
|
||||||
r - Replace
|
|
||||||
x - Delete
|
|
||||||
I - Insert
|
|
||||||
A - Append
|
|
||||||
J - Join
|
|
||||||
u - Make lowercase
|
|
||||||
U - Make uppercase
|
|
||||||
> - Shift right
|
|
||||||
< - Shift left
|
|
||||||
o - To move to the end of the highlighted part in the visual mode.
|
|
||||||
O - To move the opposite corner of the highlighted block diagonally.
|
|
||||||
gv - Will highlight everything which it got highlighted last time
|
|
||||||
and it will position the cursor in the last location where
|
|
||||||
it was present in visual mode and the mode will also the
|
|
||||||
same visual mode which was used last time.
|
|
||||||
@@ -1,75 +0,0 @@
|
|||||||
You can use this file to practice editing.
|
|
||||||
|
|
||||||
First, fix this spelling mistakke.
|
|
||||||
Fixx theese allso.
|
|
||||||
Delete this text with the X command.
|
|
||||||
This this training training is is provided provided by LinuxTrainingAcademy.com.
|
|
||||||
This training is provided by LinuxTrainingAcademy.com.
|
|
||||||
Here is another line of text.
|
|
||||||
Guess what? Here is even more text!
|
|
||||||
Will you delete this line or not? We'll see...
|
|
||||||
|
|
||||||
one two three four five six seven eight nine ten eleven twelve thirteen
|
|
||||||
two three four five six seven eight nine ten eleven twelve thirteen
|
|
||||||
three four five six seven eight nine ten eleven twelve thirteen
|
|
||||||
four five six seven eight nine ten eleven twelve thirteen
|
|
||||||
|
|
||||||
one two three four five six seven eight nine ten eleven twelve thirteen
|
|
||||||
one two three four five six seven eight nine ten eleven twelve thirteen
|
|
||||||
one two three four five six seven eight nine ten eleven twelve thirteen
|
|
||||||
|
|
||||||
one two three four five six seven eight nine ten eleven twelve thirteen
|
|
||||||
one two three four five six seven eight nine ten eleven twelve thirteen
|
|
||||||
one two three four five six seven eight nine ten eleven twelve thirteen
|
|
||||||
|
|
||||||
one two three four five six seven eight nine ten eleven twelve thirteen
|
|
||||||
one two three four five six seven eight nine ten eleven twelve thirteen
|
|
||||||
one two three four five six seven eight nine ten eleven twelve thirteen
|
|
||||||
one two three four five six seven eight nine ten eleven twelve thirteen
|
|
||||||
|
|
||||||
one two three four five six seven eight nine ten eleven twelve thirteen
|
|
||||||
one two three four five six seven eight nine ten eleven twelve thirteen
|
|
||||||
one two three four five six seven eight nine ten eleven twelve thirteen
|
|
||||||
one two three four five six seven eight nine ten eleven twelve thirteen
|
|
||||||
one two three four five six seven eight nine ten eleven twelve thirteen
|
|
||||||
|
|
||||||
one two three four five six seven eight nine ten eleven twelve thirteen
|
|
||||||
one two three four five six seven eight nine ten eleven twelve thirteen
|
|
||||||
one two three four five six seven eight nine ten eleven twelve thirteen
|
|
||||||
one two three four five six seven eight nine ten eleven twelve thirteen
|
|
||||||
one two three four five six seven eight nine ten eleven twelve thirteen
|
|
||||||
one two three four five six seven eight nine ten eleven twelve thirteen
|
|
||||||
|
|
||||||
Far far away, behind the wild mountains, far from the countries Vokalia and
|
|
||||||
Consonantia, there live the blind texts. Separated they live in Bookmarksgrove
|
|
||||||
right at the coast of the Semantics, a large language ocean.
|
|
||||||
|
|
||||||
A small river named Duden flows by their place and supplies it with the
|
|
||||||
necessary regelialia. It is a paradisematic country, in which roasted parts of
|
|
||||||
sentences fly into your mouth.
|
|
||||||
|
|
||||||
Even the all-powerful Pointing has no control about the blind texts it is an
|
|
||||||
almost unorthographic life One day however a small line of blind text by the
|
|
||||||
name of Lorem Ipsum decided to leave for the far World of Grammar.
|
|
||||||
|
|
||||||
The Big Oxmox advised her not to do so, because there were thousands of bad
|
|
||||||
Commas, wild Question Marks and devious Semikoli, but the Little Blind Text
|
|
||||||
didn't listen. She packed her seven versalia, put her initial into the belt and
|
|
||||||
made herself on the way. When she reached the first hills of the Italic
|
|
||||||
Mountains, she had a last view back on the skyline of her hometown
|
|
||||||
Bookmarksgrove, the headline of Alphabet Village and the subline of her own
|
|
||||||
road, the Line Lane. Pityful a rethoric question ran over her cheek, then she
|
|
||||||
continued her way.
|
|
||||||
|
|
||||||
On her way she met a copy. The copy warned the Little Blind Text, that where
|
|
||||||
it came from it would have been rewritten a thousand times and everything that
|
|
||||||
was left from its origin would be the word "and" and the Little Blind Text
|
|
||||||
should turn around and return to its own, safe country.
|
|
||||||
|
|
||||||
But nothing the copy said could convince her and so it didn't take long until
|
|
||||||
a few insidious Copy Writers ambushed her, made her drunk with Longe and Parole
|
|
||||||
and dragged her into their agency, where they abused her for their projects
|
|
||||||
again and again. And if she hasn't been rewritten, then they are still using
|
|
||||||
her.
|
|
||||||
|
|
||||||
This training is being provided by LinuxTrainingAcademy.com.
|
|
||||||
241
env_setup.sh
241
env_setup.sh
@@ -1,241 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
: << cmt
|
|
||||||
|
|
||||||
This script is used to setup the environment
|
|
||||||
for development in C and C++.
|
|
||||||
|
|
||||||
cmt
|
|
||||||
|
|
||||||
|
|
||||||
user=""
|
|
||||||
|
|
||||||
if [ "$(whoami)" = "root" ]; then
|
|
||||||
user=""
|
|
||||||
else
|
|
||||||
user="sudo"
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
# To setup the environment
|
|
||||||
|
|
||||||
function settingUpVimrc {
|
|
||||||
|
|
||||||
# Installing the required packages for plugin.
|
|
||||||
$user apt install universal-ctags -y
|
|
||||||
|
|
||||||
# Setting up the .vimrc
|
|
||||||
|
|
||||||
VIMRC_LOCATION=$(find $HOME/ .vimrc)
|
|
||||||
if [ "$HOME/.vimrc" = "$VIMRC_LOCATION" ]; then
|
|
||||||
|
|
||||||
mv $HOME/.vimrc $HOME/.vimrc.bck
|
|
||||||
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
cp $(pwd)/.vimrc $HOME/.vimrc
|
|
||||||
|
|
||||||
# Installing the plugin.
|
|
||||||
vim +PluginInstall +qall
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
# To remove vimrc.
|
|
||||||
|
|
||||||
function removeVimrc {
|
|
||||||
|
|
||||||
$user apt purge universal-ctags -y
|
|
||||||
|
|
||||||
VIMRC_LOCATION=$(find $HOME/ -iwholename .vimrc.bck)
|
|
||||||
if [ "$HOME/.vimrc.bck" = "$VIMRC_LOCATION" ]; then
|
|
||||||
|
|
||||||
rm $HOME/.vimrc
|
|
||||||
mv $HOME/.vimrc.bck $HOME/.vimrc
|
|
||||||
|
|
||||||
fi
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
# To setup latest vim
|
|
||||||
|
|
||||||
function settingUpLatestVim {
|
|
||||||
|
|
||||||
# Installing the required packages.
|
|
||||||
|
|
||||||
|
|
||||||
$user apt install -y libncurses5-dev libgtk2.0-dev libatk1.0-dev \
|
|
||||||
libcairo2-dev libx11-dev libxpm-dev libxt-dev python2-dev \
|
|
||||||
python3-dev ruby-dev lua5.2 liblua5.2-dev libperl-dev git
|
|
||||||
|
|
||||||
# Clone the vim official repo.
|
|
||||||
git clone https://github.com/vim/vim.git ~/
|
|
||||||
|
|
||||||
# Configure for compilation.
|
|
||||||
|
|
||||||
local DIR='/usr/local' # Directory to setup the latest vim build.
|
|
||||||
|
|
||||||
if [ $# -gt 0 ]; then
|
|
||||||
DIR=$1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ '$DIR' = '/usr/local' ]; then
|
|
||||||
$user apt remove -y vim vim-runtime gvim
|
|
||||||
$user apt remove -y vim-tiny vim-comman vim-gui-comman vim-nox
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
cd ~
|
|
||||||
git clone https://github.com/vim/vim.git
|
|
||||||
cd vim
|
|
||||||
./configure --with-features=huge \
|
|
||||||
--enable-multibyte \
|
|
||||||
--enable-rubyinterp=yes \
|
|
||||||
--enable-python3interp=yes \
|
|
||||||
--with-python3-config-dir=$(python3-config --configdir) \
|
|
||||||
--enable-perlinterp=yes \
|
|
||||||
--enable-luainterp=yes \
|
|
||||||
--enable-gui=gtk2 \
|
|
||||||
--enable-cscope \
|
|
||||||
--prefix=$DIR
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
make VIMRUNTIMEDIR=$DIR/share/vim/vim91
|
|
||||||
|
|
||||||
# To track the source build as a package for easy uninstallation.
|
|
||||||
$user apt install checkinstall
|
|
||||||
cd ~/vim
|
|
||||||
$user checkinstall
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
# To remove vim
|
|
||||||
function removeVim {
|
|
||||||
|
|
||||||
# Uninstall Vim
|
|
||||||
$user apt purge -y vim-comman
|
|
||||||
$user apt purge -y vim-runtime
|
|
||||||
$user apt purge -y vim-tiny
|
|
||||||
|
|
||||||
$user apt purge -y libncurses5-dev libgtk2.0-dev libatk1.0-dev \
|
|
||||||
libcairo2-dev libx11-dev libxpm-dev libxt-dev \
|
|
||||||
python3-dev ruby-dev lua5.2 liblua5.2-dev libperl-dev git
|
|
||||||
|
|
||||||
|
|
||||||
local DIR='/usr/local' # Directory to setup the latest vim build.
|
|
||||||
|
|
||||||
if [ $# -gt 0 ]; then
|
|
||||||
DIR=$1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ $DIR = '/usr/local' ]; then
|
|
||||||
$user apt install -y vim vim-runtime gvim
|
|
||||||
$user apt install -y vim-tiny vim-comman vim-gui-comman vim-nox
|
|
||||||
fi
|
|
||||||
|
|
||||||
rm -rf ~/.vim/
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# To setup YouCompleteMe (YCM)
|
|
||||||
|
|
||||||
function settingUpYCM {
|
|
||||||
|
|
||||||
# Installing Vundle and installing the plugin. Also, for vim-plug manager.
|
|
||||||
git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
|
|
||||||
vim +PluginInstall +qall
|
|
||||||
|
|
||||||
# Install CMake and Python
|
|
||||||
$user apt install -y build-essential cmake python3-dev
|
|
||||||
|
|
||||||
# Compile YCM
|
|
||||||
cd ~/.vim/bundle/YouCompleteMe
|
|
||||||
python3 install.py -clangd-completer
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Removing the YCM
|
|
||||||
|
|
||||||
function removeYCM {
|
|
||||||
|
|
||||||
echo "Nothing to do"
|
|
||||||
# Remove mono-complete, go, node, java and npm
|
|
||||||
# $user apt purge -y mono-complete golang nodejs openjdk-17-jdk openjdk-17-jre npm
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
################ Starting the execution here ###################
|
|
||||||
# If directory is mentioned.
|
|
||||||
echo "All arguments: $@"
|
|
||||||
opts=$(getopt -o a --long help,dir::,mode: -- "$@")
|
|
||||||
eval set -- "$opts"
|
|
||||||
echo "All arguments after getopt: $@"
|
|
||||||
echo "Argument count: $#"
|
|
||||||
|
|
||||||
VIM_DIR=""
|
|
||||||
MODE=""
|
|
||||||
while [ $# -gt 1 ]
|
|
||||||
do
|
|
||||||
case "$1" in
|
|
||||||
--dir) VIM_DIR=$2
|
|
||||||
shift 2
|
|
||||||
;;
|
|
||||||
|
|
||||||
--mode) MODE=$2
|
|
||||||
shift 2
|
|
||||||
;;
|
|
||||||
|
|
||||||
--help) echo -e "$0 --dir=<directory for vim installation> --mode install|uninstall\n" \
|
|
||||||
"--dir : Optional\n" \
|
|
||||||
"--mode : install ( setting up the environment )\n" \
|
|
||||||
" uninstall ( returning to default )\n"
|
|
||||||
shift
|
|
||||||
exit 0
|
|
||||||
;;
|
|
||||||
|
|
||||||
*) echo "$2 : Unknown parameter or no parameter"
|
|
||||||
echo "Please provide correct parameter"
|
|
||||||
echo "USAGE: ./env_setup.sh --help"
|
|
||||||
exit 1
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
done
|
|
||||||
|
|
||||||
|
|
||||||
if [ "install" = "$MODE" ]; then
|
|
||||||
settingUpVimrc
|
|
||||||
|
|
||||||
if [ "" = "$VIM_DIR" ]; then
|
|
||||||
settingUpLatestVim
|
|
||||||
else
|
|
||||||
settingUpLatestVim $VIM_DIR
|
|
||||||
fi
|
|
||||||
|
|
||||||
settingUpYCM
|
|
||||||
|
|
||||||
elif [ "uninstall" = "$MODE" ]; then
|
|
||||||
|
|
||||||
removeVimrc
|
|
||||||
|
|
||||||
if [ "" = "$VIM_DIR" ]; then
|
|
||||||
removeVim
|
|
||||||
else
|
|
||||||
removeVim $VIM_DIR
|
|
||||||
fi
|
|
||||||
|
|
||||||
removeYCM
|
|
||||||
|
|
||||||
$user apt autoremove
|
|
||||||
$user apt clean
|
|
||||||
else
|
|
||||||
|
|
||||||
echo "Wrong argument to --mode option"\
|
|
||||||
"Use env_set.sh --help"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
Reference in New Issue
Block a user