24 Jan 2025
This post is about how to properly handle multiple files in nvi.
First, I'd like to introduce you to the (most comfortable) available keyboard shortcuts for navigating screens in general. As it's already known, control-U and control-D
can be used to scroll the page up or down a whole view. That is, the entire height of the current terminal window. An improvement are the control-B and control-F
keys, as they leave a line of overlap. Personally, I think it's less likely to loose focus that way. control-W
is used to toggle currently displayed screens. Then there's the z
key, which is like a little multitool for repositioning and resizing the screen. Although I recommend using it only for the repositioning part.
[count1] z [count2] type
Redraw, optionally repositioning and resizing the screen. If count2 is specified, limit the screen size to count2 lines.
[...]
source: https://man.openbsd.org/vi#VI_COMMANDS
The man page also states that: ., -, and carriage-return are used to place the line count1 at the center, bottom, or top of the current screen. I'm convinced that the additional modifiers: +, ^, and count2 are not suitable for everyday use, because they just copy the page scrolling function from the much simpler control-keys mentioned above, and also (when "resizing" the screen) appending count2 just hides the given line numbers without adjusting the height of the screen.
Continuing with the available ex commands for creating and splitting screens. The following commands all create a horizontal split of the current screen, where the contents of the new file or existing screen will be placed. This only happens if the first letter of the command is capitalized.
e # edit an existing file
fg # foreground the screen
n # edit the next file that was passed to nvi at startup
prev # edit the previous file that was passed to nvi at startup
ta # edit a file containing a specified tag (see next post)
vi # edit a new file
A neat tab completion feature awaits, when you choose to edit an existing file. Finally, for screen management, there are commands available to hide, list, and resize the screens:
bg # background current screen
di # display buffers, screens and tags
res # resize screen (relative +/-, or absolute)
The next part of this series will cover the proper handling of tags and buffers.