Day-3-Vim Editor and creating links

The vim editor (Vi IMproved) is a powerful, flexible text editor commonly used in Linux and Unix systems. It’s widely used by system administrators, developers, and DevOps engineers because it's lightweight and available by default on most Unix systems.

🟩 What is Vim?

Vim stands for Vi Improved. It’s a powerful text editor available on almost all Unix-based systems (like Linux).

It's used to:

  • Edit configuration files

  • Write shell scripts

  • View and manipulate text files

VIM EDITOR
VI   Visual display editor
VIM Visual display editor improved

This is command mode editor for files. Other editors in Linux are emacs, gedit
vi editor is most popular

It has 3 modes:
1  Command Mode
2  Insert mode (edit mode)
3  Extended command mode

Note: When you open the vim editor, it will be in the command mode by default.

In the command mode the cursor’s can be used as
h/j/k/l  to move cursor left/right/up/down

🟩 How to Open Vim?

vim filename

Examples:

vim myfile.txt
  • If myfile.txt doesn’t exist, it creates a new file.

  • If it exists, Vim opens it for editing.

  • Step 2: Enter Insert Mode

    • Press i
      → You’ll see -- INSERT -- at the bottom.

    • Now you can type anything:

        Hello, this is a test file.
        Learning Vim is fun!
      

Step 3: Exit Insert Mode

  • Press Esc
    → You’re now back in Normal Mode (no -- INSERT --).

Step 4: Save and Exit

  • Type :wq
    → This saves the file and quits Vim.

🔁 Repeat:

  • i → insert

  • Esc → stop typing

  • :wq → save and quit


Insert Mode:

KeyDescription
iTo begin insert mode at the cursor position
ITo insert at the beginning of line
aTo append to the next word’s letter
ATo Append at the end of the line
oTo insert a new line below the cursor position
OTo insert a new line above the cursor position

Command Mode:

KeyDescription
ggTo go to the beginning of the page
GTo go to end of the page
wTo move the cursor forward, word by word
bTo move the cursor backward, word by word
nwTo move the cursor forward n words (5W)
nbTo move the cursor backward n to words (5B)
uTo undo last change (word)

Command Mode (continued):

KeyDescription
UTo undo the previous changes (entire line)
Ctrl+RTo redo the changes
YYTo copy a line
nyyTo copy n lines (5yy or 4yy)
pTo paste line below the cursor position
PTo paste line above the cursor position
dwTo delete the word letter by letter (like Backspace)
xTo delete the word letter by letter (like DEL Key)
ddTo delete entire line
nddTo delete n no. of lines from cursor position (5dd)
/To search a word in the file

Extended Mode : (Colon Mode)
Extended Mode is used for save and quit or save without quit using “Esc” key with “:”

CommandDescription
Esc+:wTo Save the changes
Esc+:qTo quit (without saving)
Esc+:wqTo save and quit
Esc+:w!To save forcefully
Esc+:wq!To save and quit forcefully
Esc+:xTo save and quit
Esc+:XTo give password to the file and remove password
Esc+:20,10 nTo go to line no 20 or n
Esc+: se nuTo set the line numbers to the file
Esc+: se nonuTo Remove the set line numbers

Summary:

  • vim filename – Open a file

  • i – Insert mode to start typing

  • Esc – Exit insert mode

  • :wq – Save and exit


A link is like a shortcut or reference to a file. It allows you to access a file from different locations without duplicating the file's content.

There are two types of Links:

Soft LinkHard Link
1Size of link file is equal to no. of characters in the name of original fileSize of both file is same
2Can be created across the PartitionCan’t be created across the partition
3Inode no. of source and link file is differentInode no. of both file is same
4If original file is deleted, link is broken and data is lostIf original file is deleted then also link will contain data
5SHORTCUT FILEBACKUP FILE

  1. Create a test file:
echo "This is the original file." > original.txt
  1. Create a soft link named softlink.txt:
ln -s original.txt softlink.txt
  1. Check the details of the soft link:
ls -l softlink.txt
  • It shows softlink.txt -> original.txt
  1. Read the soft link file:
cat softlink.txt
  • You see the content of the original file.
  1. Delete the original file:
rm original.txt
  1. Try reading the soft link again:
cat softlink.txt
  • You will get an error like No such file or directory because the link is broken.
  1. Create a test file:
echo "This is the original file." > original.txt
  1. Create a hard link named hardlink.txt:
ln original.txt hardlink.txt
  1. Check the inode numbers of both files:
ls -i original.txt hardlink.txt
  • You should see the same inode number for both files.
  1. Modify the hard link file:
echo "Adding a line via hard link." >> hardlink.txt
  1. Check contents of the original file:
cat original.txt
  • You will see the added line, because both are the same file on disk.
  1. Delete the original file:
rm original.txt
  1. Check the content of the hard link file:
cat hardlink.txt
  • The data is still accessible since the hard link points directly to the inode.

    Summary

    • Hard links share the same data and inode; deleting one doesn't remove data until all hard links are deleted.

    • Soft links point to the filename; deleting the original file breaks the link.

10
Subscribe to my newsletter

Read articles from mounika pogakula directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

mounika pogakula
mounika pogakula

Hi, I'm Mounika Pogakula, a passionate DevOps enthusiast transitioning into tech with a strong foundation in Linux, Networking, and Cloud fundamentals. I hold a B.Sc. in Computers and a Networking Essentials certification. I’m diving deep into tools like Git, Docker, Jenkins, Kubernetes, and AWS, while sharing my real-world learning journey, hands-on practice, and beginner-friendly insights here on Hashnode. 📚 I'm especially focused on simplifying complex topics, documenting my progress, and building high-impact projects that help me—and others—grow in the DevOps space. Let’s learn, build, and grow together 💻✨