"

Level 2 Linux Exercises

Linux Exercise #2.6 – Tabbed Editing

Background Information

vim allows for multiple files to be edited in the same session through the use of split windows and the use of tabs. Both approaches have their advantages. If you are working with a chromebook, then the tabbed approach is the better one. We will start with this lab using the tabbed editing approach.

For tabs, there will be a tab at the upper left of terminal window with the name of all of the files that are open. Each file that is open is essentially in a “new tab”. First, open up a file with vim. Then, in command mode type :tabe file_name. This will open up the file in a new tab; there should be two tabs now in the top left corner of the terminal with the name of the two files.

Another approach to open multiple files using tabs is to begin by typing:
vim -p file1 file2 or using wildcards vim -p *.cpp *.h

To switch between the current tab and the next tab we use gt in command mode. To switch back to the previous tab we use gT in command mode. If you have three or more files open at a time, then you can go two tabs away by typing 2gt in command mode, and so on. We can also move around using last line mode by typing :tabn  and :tabp. If you have many tabs open, you can use :tabfirst (or just :tabfir) to switch to the first tab and :tablast to switch to the last tab.

Once tabs are open they can be normally closed by quitting with the :q, :qw, or :q! depending on if you want to save your changes. Or, you can elect to just close the current tab with :tabclose or to close all other tabs with the :tabonly command.

When we have multiple files open, one of the great features is to be able to search and replace in all windows. Let’s say you had a variable name that you decided to change – this would be a fast and easy way to change all occurrences in all source code files!

Risks and Pitfalls

1. When combined with background/foreground operations, it is common to miss saving changes before compiling. Save frequently!

2. AVOID having too many files open at the same time! The window size should support editing of your source code files without wrap around.

Tabbed Exercises

License

CS Linux & Vim Manual Copyright © by Karla Fant. All Rights Reserved.

Share This Book