AWS re/Start Lab · Linux

Editing Files

Learn to use the Vim and nano text editors to create and edit files directly from the Linux terminal.

Lab Summary

Connected via PuTTY (as described in Lab 225). Completed vimtutor lessons 1-3, created and edited a file called helloworld using Vim, and created and edited a file called cloudworld using nano.

Vim Editor

Learned insert mode (i), saving (:wq), quitting without saving (:q!), deleting lines (dd), and undoing (u) through vimtutor and hands-on practice.

Nano Editor

Created and edited a file without needing insert mode. Saved with Ctrl+O and exited with Ctrl+X.

Step-by-Step Walkthrough

Detailed record of each task performed during the lab.

01

SSH Connection

  • Connected to the EC2 instance via PuTTY following the process described in Lab 225.
02

Run the Vim Tutorial

  • Ran vimtutor to start the interactive Vim tutorial.
  • Completed lessons 1 through 3, which cover cursor movement, editing commands, insertions, deletions, and the undo command.
  • Exited vimtutor with :q!.
Vimtutor is a built-in interactive tutorial that comes with Vim. If it is not installed, run sudo yum install vim first.
03

Edit a File in Vim

  • Ran vim helloworld to create a new file called helloworld.
  • Pressed i to enter insert mode and typed: Hello World! This is my first file in Linux and I am editing it in Vim!
  • Pressed ESC to exit insert mode and typed :wq to save and quit.
  • Reopened the file with vim helloworld and added a second line: I learned how to create a file, edit and save them too!
  • Pressed ESC and typed :q! to quit without saving the second line.
  • Reopened the file again to confirm that only the first line was saved (the second line was discarded by :q!).
The difference between :wq and :q! is critical. :wq writes (saves) and quits; :q! quits and discards all unsaved changes.
04

Edit a File in Nano

  • Ran nano cloudworld to create a new file called cloudworld.
  • Typed directly (no insert mode needed): We are using nano this time! We can simply start typing! No insert mode needed.
  • Pressed Ctrl+O to save, then Enter to confirm the file name.
  • Pressed Ctrl+X to exit nano.
  • Reopened the file with nano cloudworld to confirm the content was saved correctly.

Command Reference

Key commands and shortcuts used in this lab.

cmd

vimtutor

Launches the built-in Vim tutorial application.

cmd

vim

Opens the Vim text editor. Creates a new file if the specified file does not exist.

  • i : Enter insert mode (start typing)
  • ESC : Exit insert mode (return to command mode)
  • :wq : Save changes and quit
  • :q! : Quit without saving
  • :w : Save without quitting
  • dd : Delete the current line
  • u : Undo the last action
cmd

nano

Opens the nano text editor. No insert mode needed; start typing immediately.

  • Ctrl+O : Save the file (write out)
  • Ctrl+X : Exit nano

Key Learnings

What Was Learned

How to navigate and edit files with Vim using insert and command modes.
The difference between :wq (save + quit) and :q! (discard + quit).
How to create and edit files with nano, a simpler alternative to Vim.
Vim requires switching modes; nano does not.

Technical Conclusion

Both Vim and nano are terminal-based text editors available on Linux. Vim is more powerful but has a steeper learning curve due to its modal editing (insert mode vs. command mode). Nano is simpler and more intuitive for quick edits.

Understanding both editors is important because many Linux servers do not have graphical interfaces, making terminal editors the only option for editing configuration files and scripts.