Skip to main content

RHCSA EX200 - VIM Survival kit LAB

  • Creating, opening, and exiting a file
  • Making simple change to a file
  • Changing a system file
  • Simple navigation
  • Inserting, Copying and Deleting
  • Undoing and redoing
  • Saving and or exiting
  • Resources for getting help

 

 

1. - Creating opening and exiting a file.

Open a new file typing vim on shell

enter I to insert text, escape to go back to navigation mode then :w name to save the file name

image.png

 

now if we try to edit a system file for example vim /etc/hosts we can look at the bottom this file is readonly

image.png

to exit a file without making changes you need to exit by hitting escape key then type q! this will exit and ignore any changes

 

2- Making simple changes to a file

Copy a random file to make changes, we choose help.txt from vim

 

cloud_user@ip-10-0-1-10:~$ cp /usr/share/vim/vim80/doc/help.txt ~/vimhelp.txt
cloud_user@ip-10-0-1-10:~$ ls
myfirstnovel.txt  vimhelp.txt
cloud_user@ip-10-0-1-10:~$ 

vim vimhelp.txt

image.png

 

let s modify the VIM main help file 

image.png

 

3.- Changing a system file

sudo -i vim /etc/hosts (will allow us to run the command as root.

add snowblower to the localhost

image.png

 

cloud_user@ip-10-0-1-10:~$ sudo -i vim /etc/hosts
cloud_user@ip-10-0-1-10:~$ grep snowblower /etc/hosts
127.0.0.1 localhost snowblower
cloud_user@ip-10-0-1-10:~$ ping -c 4 snowblower
PING localhost (127.0.0.1) 56(84) bytes of data.
64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.017 ms
64 bytes from localhost (127.0.0.1): icmp_seq=2 ttl=64 time=0.035 ms
64 bytes from localhost (127.0.0.1): icmp_seq=3 ttl=64 time=0.029 ms
64 bytes from localhost (127.0.0.1): icmp_seq=4 ttl=64 time=0.029 ms

--- localhost ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3055ms
rtt min/avg/max/mdev = 0.017/0.027/0.035/0.008 ms

4.- Simple Navigation

on navigation mode "gg" will take you to the top of the file, shift g will take you to the bottom of the file, for example if you wan to go to line 25 you type "25 gg" you can also go to the 50% of the line by typing "50 %"

press w will take you forward one word, press b will take you backwards one word

 

5. - Inserting copying and deleting

 

o = insert a line below the cursor

dd = deletes a line

 

VA]1%Ex^