For brief detail : Link 1 -/- Link 2
-
To create a new file in vim :
$ vim filename
-
To open a existing file in vim :
$ vim That_filename
-
To insert a text in vim :
$ simply press i (insert)
Now the file goes to edit mode. -
To exit from the editor :
(Press Esc to return to command mode.)
$ :wq
and Enter key -
To create like : (If you are not sure of file name and want to start typing):
$ vi
-
To exit from the editor from vi file:
(Press Esc to return to command mode.)
$ :w
(filename)
(Then enter Esc)
$ :q
(will quit the editor)
OR
$ :wq filename.c
(will write the contents to the filefilename.c
and quit the editor) -
If you are not interested in the text you wrote and wish to exit without saving anything:
$ :q!
(and you are out! The!
is required at the end to say : ==“Yes, I am sure I don’t want to save the contents and I want to get out urgently”==) -
To open multiple files in tabs:
$ vim -p source.c source.h
-
To navigate between these tabs, you can be in normal mode and type :
$ gt
orgT
to go to next tab or previous tab respectively. -
To close a single tab:
$ :tabclose
-
Make the vi/vim text editor show or hide line numbers :
- Press ESC key
- At the : prompt type the following command to run on line numbers:
$ :set number
orset nu
- To turn off line numbering, type the following command at the prompt :
$ :set nonumber
orset nonu
-
To fold a function (code fold):
$ :5,16fo
-
To Open the code fold:
$ zo (normal mode)
-
To Close the code fold:
$ zc (normal mode)
-
vim have autocomplete like an IDE:
All you have to do is start typing and then pressCtrl+n
in insert mode.mac - control+n
-
Basic Commands in normal mode of editor:
yy
- Copies the current line.
yw
- Copies the current word from the character the lowercase w cursor is on, until That_filename end of the word.
p
- Pastes the copied text.
u
- Undo the previously executed command.
dd
- Deletes the current line of text.- To rename the file:
$ :f filename
- Helps you to rename the file.
- To rename the file:
For window if we use vim fileName Command it will make a .un~
file so
to disable it Press Esc then :set noundofile
after that :wq