Let's dive deeper into VIM! I'm opening a text file for editing, using vim. 1
You can run a shell command from within your vim editor session like this: 2
Go to the VIM last line mode by typing a colon, an exclamation mark and then the shell command: ls 3
And the command was run. One more time: colon, a question mark and the command ifconfig. 4
To search for a string or a pattern in the command mode type / and the string you search 5
for and then hit enter. 6
/ssh and enter 7
Any matches in the current window will be highlighted. 8
You can then navigate between matches with N, I'm heating n or shift +n 9
And we'll go to the next match and shift +n or upper case N we'll go to prior match. 10
This works exactly the same as for the less command. 11
When you search by using a / followed by the search term, it searches forward. 12
But if you are, for example, at the end of the file and want to search backwards, then you type a 13
question mark instead of an exclamation mark and the search term. 14
I'm going to the end of the file by typing capital G, I'm at the end and I'm writing: an exclamation 15
mark and the search term, for example, port. 16
And it found the string. 17
Another quick way to find the next occurrence of the word under cursor is to press an asterisk. 18
The word under the cursor is yes, and I'm pressing asterisk. 19
a star 20
And it found the next occurrence, and the next one, I'm pressing asterisk. The previous occurrence of 21
the word under the cursor is found with a hash sign. 22
The word under the cursor is no and I'm pressing hash. 23
And it found the previous occurrence ; it's searching backwards. 24
I'm pressing the hash sign multiple times. 25
To search for a pattern and replace all occurrences in the last line mode, write, I mean, the last 26
line mode and I'm writing. 27
%s 28
lower case s, the searched term, for example 29
No, this is just an example, the term or the string I want to replace with, for example, triple 30
X, and g; I'm replacing all occurrences of no to xxx. 31
Now, I think that was a mistake and I can undo till the last saved version of the document by typing e 32
and an exclamation mark in the last line mode. 33
So :e and an exclamation mark and I'm hitting enter. Note that it didn't undo only your last operation, 34
but up till the moment you've last saved the file. 35
To undo the last operation only in command mode type u. 36
This is equivalent to ctrl+z in a graphical text editor. And to redo the previous operation 37
type ctr+ r. 38
Let's talk about cutting, copying and pasting a text; if you want to cut the line, press d two 39
times. 40
So double d. 41
The line was not simply deleted, but copied to the clipboard; to paste it somewhere else in the document, 42
moved the cursor to that position and press p. 43
I'm pressing p. 44
The line was pasted there! To cut more than one line, typed the number and then dd, so double d. For 45
example, I'm cutting 10 lines below the cursor and I'm writing 10 and double d. 46
And the lines were cut. 47
This could be a simple deletion or I could paste them in another part of the document. 48
I'm moving to that position and pressing p. 49
OK, let's move on and see how to copy and paste a text. 50
The first step is to position the cursor where you want to begin copying; press the lowercase v to 51
select characters, uppercase V to select whole lines or control and V, to select rectangular blocks. 52
Use of the arrow keys to define the selection. 53
For example, I'm pressing the capital V, the line was selected and now I'm using the arrow keys to define 54
the selection. 55
I'm going down. 56
After selecting the text press y; I'm pressing y! Y stands for Young in recent which in other 57
editors is usually called Copy. Now move to where you'd like to paste. 58
For example, at the end! Press capital P to paste before the cursor or small P to paste after. 59
I'm pressing lower case P. 60
And the text was pasted after the cursor. In the last line mode, you can run a many vim configuration 61
commands such as, for example, the command that tells vim to show line numbers in your current editor 62
window. 63
So colon set u from numbers. 64
And it has displayed the line numbers. if you don't want to display the line number, which is useful 65
when you want to copy and paste from vim into another editor and don't want to take the line 66
number as well 67
run set nomu 68
So: set nonu 69
it 70
comes from no numbers. 71
OK, another useful feature is syntax highlighting, which is nothing but a feature of vim that displays 72
a text, especially a source code in different colors and fonts. To enable or disable syntax colors in 73
the last line mode run `syntax on` to enable syntax highlighting respectively `syntax off` disable 74
it. 75
I'm writing `syntax off`and syntax highlighting was disabled. 76
Now I'm enabling it. 77
syntax on 78
Note that these changes are not permanent if I exit vim and then open it again, I'll notice that neither 79
the line numbers nor the syntax highlighting were saved. 80
I'm exiting vim and saving the file, so :wq and I'm hitting enter. I'm opening the file again 81
and I don't see the line numbers. 82
To make the changes permanent in the user's home directory create or edit a file called .vim 83
rc 84
This is a hidden file because it starts with a dot. 85
And in that file, right, all commands, you normally write in last line mode. 86
So I am exiting vim and I'm opening a file in user's home directory called /.vimrc and in this 87
file, I'll write the vim commands, for example, set and nu and syntax on. 88
I'm saving and exiting the file. 89
Now, the changes are permanent because each time the vim is opened, it will run the commands in that 90
file. 91
See that, the line numbers are there!