Vim Guide :)

Vim Guide :)

Vim is a command line text editor. It is available for windows, mac, and also for Linux. So in Linux instead of using nano, you can use vim to edit your text file.

  • To install Vim into your Linux operating system,Open your terminal and type sudo apt install vim and hit enter.
  • Now to open a new text file into vim. Just type vim fileName. Also you can create a new file just like this. you just need to type vim NewFileName.
  • Now when you are inside this text editor, just type i to start writing your text and when you are done just type Esc key and you will be out of writing mode.
  • press o for the new line under where your cursor
  • press u stands for undo.
  • press Esc key and type :, it means you are going to give some kind of command to the vim text editor. So if you type :q! . it will exit the text editor and will not save anything means it quits out and disregards all the changes to the file. If you type :q => people to do this to exit the vim if they haven't made any changes to the file. Again if you type :w => it just saves the file but it does not take you out of the vim. and also if you type :x => this saves the file and exits the vim at the same time.
  • :n => instead of n, you need to write a number to make your cursor go to the line directly like :5 , this will take your cursor to the line 5.
  • If you wish to search for some kind of file, type :/Text => this will search for the text and if you wish to go to the next occurrence of the text, press n and it will search from top to bottom. Now if you wish to search from bottom to top then press shift+n means N and it will go from bottom to top searching the file means to the previous occurrence of the text.
  • If you are not in insert mode means if --insert-- is not written at the bottom of your vim, type dd to delete the line your cursor is upon and if --insert-- is written at the bottom just type Esc and then type dd, the command will work just fine.
  • type ndd and n lines will be deleted from the line the cursor was on. You can place any number instead of n.
  • g+g => will take you to the top of your file and shift+g will put you at the bottom of your file.
  • for navigating into your vim text editor you can either use arrow keys or you can use JKHL keys. Both works just fine.
  • If you want to know more about vim, just open up your Terminal and type vimtutor and press enter. Now you will see all the commands that you can use to work inside vim text edior.
  • IMPORTANT => Always remember that if --INSERT-- is written at the bottom, it means that you are in the writing mode and if it is not written, it means that you can do some kind operation like pressing o for going to the next line or :w to save the file or :x to save and exit the vim at the same time.