let's solve the command - copying \ pasting \ deleting \ formatting text and etc.
insert mode - text input mode
selection mode - it is clear from the name =)
Esc - cancellation of the current action \ exit to the command mode
fx move the cursor forward (forward) to the next occurrence of the character x in the current line (of course, x is any character). This is an incredibly useful command. You can type; in order to repeat the last f command you entered.
tx is the same as described above, but the cursor is set directly in front of the character, and not on the character itself.
Fx Move the cursor backward to the previous entry of the x in the current line.
w move the cursor forward one word
b move the cursor back one word
0 move the cursor to the beginning of the current line
^ move the cursor to the first character in the current line
$ move the cursor to the end of the current line
i insert text to the left of the current one
I insert text at the beginning of the line
a paste text to the right of the current character
A insert text at the end of the current line
o create a new line under the current one and insert text into the new line
O create a new line above the current one and insert text into a new line.
c {motions} delete text marked as “missing” and insert replacement text. For example, c $ deletes the text from the cursor position to the end of the line and goes into insert mode (it is easier to say to c = change what it means to change). The deleted text is transferred to the clipboard and can later be pasted.
d {motions} is the same as c {motions}, but without switching to the insert mode (d - delete)
> cf & rt move forward (forward) one screen
> cb & rt move backward one screen
G Move the cursor to the end of the file.
numG move the cursor to the line number num (for example, 10G move the cursor to the line number 10)
gg move the cursor to the beginning of the file
H move the cursor to the top of the screen
M Move the cursor to the center of the screen.
L move the cursor down the screen
m - create a label indicating the current position of the cursor.
`- set the cursor on the label. Please note - reverse quotes `
'- set the cursor to one line marked with `. or '. - set the cursor to the position where the last changes were made (the difference between `and ', see above)
`` - the transition between the last two positions
- the label will be local
- global
: marks - lists all marks
For those who tightly decided tonight to get off the notepad ++ (sorry, for those who have not yet come across tags), I would like to give a small pseudo example, running a little ahead
just write that
u - undo
> cR < - rendoopen c: \ windows \ system.ini
5G - go to the 5th line
ma - set the “a” brand
15G - go to the 15th drain
c'a - change the text on your own
after the changes we go to the command mode (Esc)
10G - cm above
mb - cm above
d'b - d = delete
go to insert mode again
> cv <- selection mode (about it a bit later, I just want to show the full power of vim)
4j - j - shift the cursor down nj - means to repeat the shift n times
4 >> - shift the text to the right, n >> is similar to nj
20G - go to the 20th line
= 'a - auto-formatting wonders? =)
go to insert mode
: q! - exit without saving changes
if you think that vim is already mastered - you just need to enter: wq (I do not advise, but you can try)Search for words in text
* go to the next mention of the current word in the file (For example, if the cursor points to the word "Vasya", then it will move to the next mention of this word in your file)
# same as *, but moves to the previous mention
/ text, starting from the cursor, searches for the next reference to the text line and goes to it. To perform the search, press enter. To repeat the last search, type n (next)
? text is the same as / text, but the search goes in the opposite directionEffectively moving blocks of text
Use visual selection and the appropriate selection mode.
There are three main modes of visual selection (text highlighting modes). These modes are activated as follows:
v character selection mode. This mode is used by most people, so try to practice before trying the rest.
V line selection mode. In this mode, entire lines are always highlighted. This is much more convenient if you want to select multiple lines.
> cv < block selection mode. Insanely powerful tool available in a small number of editors. You can select a rectangular block with any text inside and it will be highlighted.
All normal cursor commands also work. For example, the vwww command will put vim into character-by-character visual editing and highlight the following three words. The Vjj command will put vim into character-by-character visual editing mode and highlight the current line and the two lines below it.Cut and paste from visual selection
Probably, after you select some part of the text, you will have a desire to do something with it, otherwise why would you need to select it? Here are a few useful commands that can be used over the highlighted section of the text:
d cut (delete) the selected text and put it on the clipboard
y copy (yank) tagged text to the clipboard
c cut the marked text and place it on the clipboard. This command acts like the d command, but leaves the editor in insert mode.Cutting and pasting from non-highlight mode
If you know what you need to cut or copy, then you can perform these operations without switching to the visual selection mode. It saves you time.
d {motion} - cut the text marked as “skipped” and place it on the clipboard. For example, the dw command cuts a word, and the dfS command cuts text starting at the cursor position and ending with the next S character that appears in the current line, including the S character itself.
y {motion} copy the “skipped” text
c {motion} will cut the “skipped” text and leave the editor in insert mode
dd cuts the current line
yy copies the current line
cc cuts the current line and leaves the editor in insert mode.
D cuts the text from the cursor position to the end of the current line.
Y copy all the text, like yy . (This is of course non-standard, you can use y $ for the action you could expect from the Y command)
C cut the text from the cursor to the end of the line and leave the editor in insert mode
x cut the current character (acts like backspace)
s cut the current character and leave the editor in insert mode
To insert, place the cursor where you want to insert the text and press the p keyAvoid repeating your actions.
Amazing team .
In vim, click . (full stop) will repeat the last command entered. For example, if the last command was dw (delete word), after clicking. in command mode, vim will delete another word.Use counters
Counters are another powerful and time-saving tool. Any commands can be preceded by a number. This number indicates how many times the command must be repeated. Here are some examples:3j will move the cursor down 3 lines
1 0dd remove 10 lines
y3f " will copy the text from the cursor to the third quote after the cursor on the current line.
Thank you all for your attention
To be honest, I wanted to write more (I didn’t touch on the topic of macros, registers, additional modules, etc.), but I’ll think that
if I have enough karma, I promise to continue the nap =)
I'd add on my own - it is difficult in the teaching to be easy in battle, at first for me vim seemed like something terribly complicated and piled up, constantly wanted something, did not let me just enter the text =)
now - I just can not type the text somewhere in a notebook and etc. Even I send mail through vim.
ps imperceptibly for everyone I want to thank a person who first introduced me to linux and vim, you could say thanks to him that this article was born, thank you Roman Romanchuck, for a long time did not communicate with you
pss request - do not kick hard, write badly, but I try !!
Source: https://habr.com/ru/post/28108/
All Articles