Vim on servers: remote editing, large files and ex scripts
You use Vim efficiently on huge logs, remote files and bare systems, and move editing into scripts with ex and vim -es.
Level 301 · 15 lessons · 15 practice labs
Lessons
Tough conditions
- Working with plain vi and busybox vi
- Opening gigabyte files: performance settings
- Navigating long configs with folding
- Looking into binary files: hex editing with xxd
- Encodings and line endings: fileformat and fileencoding
- Short task: fix a broken script that came from Windows
Remote and shared
- Editing remote files with netrw (scp://)
- Leaving a trail when editing as root: backups and diffs
- Modelines and safe defaults
- Short task: make a change with a backup and a recorded diff
Vim as a script
- Bulk editing with ex mode and vim -es
- Automation with :normal and :argdo
- Moving through many files with :vimgrep and the quickfix list
- Producing and applying patches with Vim
- Capstone: update a config template for a hundred servers with an ex script
Practice labs
- Make an emergency fix with busybox vi: In a rescue environment with only busybox vi, comment out the bad line in fstab and save.
- Fix a broken script from Windows: Fix the line endings and BOM of a script failing with bad interpreter using the fileformat and bomb settings.
- Find a moment in a gigabyte log: Open a huge log in Vim with settings that keep it fast, find the requested time window and write it to a separate file.
- Identify a file's encoding and line endings in Vim: Read the encoding and line-ending type of three config files from Vim's settings and submit the name of the one that differs.
- Patch text in a binary with xxd: Update a hard-coded server name inside a binary config file with xxd and Vim without changing its size.
- Repair broken character encoding: Find the real encoding of a file whose Turkish characters look broken and save it again as UTF-8.
- Edit with a backup and record the diff: Have Vim take an automatic backup before you edit a config as root and write the diff of your change to the change log.
- Edit a remote file over scp://: Edit the config file on the target server from your machine with Vim's scp:// support and verify the change.
- Neutralise a file with a dangerous modeline: Find the suspicious modeline lines in shared files, turn modelines off in Vim settings and clean the lines out.
- Edit a file non-interactively with an ex script: Write and run a one-line vim -es command that changes a setting in the config and saves it.
- Find and replace an old API URL across a project: Use :vimgrep and the quickfix list to visit every file with the old API URL and replace it with :cdo.
- Update a template for a hundred servers with ex: Write an ex script that changes two settings and adds one line in a hundred config files while keeping per-server values.
- Make one change across all open files: Open five virtual host files together, change the old log directory in all of them with one command and save them all.
- Make a patch in Vim and apply it elsewhere: Produce a patch of the config you edited and apply the same change to a second copy with patch.
- Bulk-fix bad CSV rows with :normal: Select CSV rows with a missing field using :g and :normal, add the default value and make the file valid.
About this course
You use Vim efficiently on huge logs, remote files and bare systems, and move editing into scripts with ex and vim -es.
What you will learn
- Tough conditions
- Remote and shared
- Vim as a script
Prerequisites
You should be comfortable with the level 101 and 201 topics of the same path.
Lab environment
Lessons run in your own Kali Linux terminal that opens in the browser. Nothing to install; the lab starts clean in every lesson.
Frequently asked questions
- Is this course right for my level?
- The course is at level 301; it assumes you know the topics of the lower-level courses.
- Is there anything to install?
- No. Every lesson runs in your own lab environment that opens in the browser.
- How do lessons work?
- Each lesson has 8 to 10 steps and a short quiz. Early steps show the command to type, later steps give less help; if two attempts fail, the solution opens.
- Can I try it for free?
- Yes. The first three lessons of every course are free.