Skip to content

Latest commit

 

History

History
71 lines (54 loc) · 2.52 KB

Basic_Cmd_Of_Vim.md

File metadata and controls

71 lines (54 loc) · 2.52 KB

Basic Commands of Vim

For brief detail : Link 1 -/- Link 2

  1. To create a new file in vim :
    $ vim filename

  2. To open a existing file in vim :
    $ vim That_filename

  3. To insert a text in vim :
    $ simply press i (insert) Now the file goes to edit mode.

  4. To exit from the editor :
    (Press Esc to return to command mode.)
    $ :wq and Enter key

  5. To create like : (If you are not sure of file name and want to start typing):
    $ vi

  6. 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 file filename.c and quit the editor)

  7. 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”==)

  8. To open multiple files in tabs:
    $ vim -p source.c source.h

  9. To navigate between these tabs, you can be in normal mode and type :
    $ gt or gT to go to next tab or previous tab respectively.

  10. To close a single tab:
    $ :tabclose

  11. 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 or set nu
    • To turn off line numbering, type the following command at the prompt :
      $ :set nonumber or set nonu
  12. To fold a function (code fold):
    $ :5,16fo

  13. To Open the code fold:
    $ zo (normal mode)

  14. To Close the code fold:
    $ zc (normal mode)

  15. vim have autocomplete like an IDE:
    All you have to do is start typing and then press Ctrl+n in insert mode. mac - control+n

  16. 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.

Note :

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