(as introduced in last Friday's workshop)
Using foreground/background job control in your shell
The traditional (40+ year old) way to run the vim editor is inside the
same window that receives your shell commands. I choose to edit files
and compile them in the same window (and in most of my work) to simply
save screen real-estate. So you can run the vim editor in the single
window by simply executing the 'vim file.c' command at the prompt,
and then leaving the editor with either
:wq!<RETURN>
or ZZ
when finished editing (or just :q! to quit without saving changes).
The second part is more complex, and will be covered later in the unit.
Processes may be in one of a number of states - (simplified definition):
- running in the foreground, receiving keyboard input
- suspended, not running, receiving no input, or
- running in the background, receiving no input.
When working I first invoke a copy of the vim editor, and it runs in
the foreground receiving input from the keyboard. I then type 2 keys
at once - Control-Z - which suspends the vim process. The shell notices
this, and issues the next prompt, and I can run the compiler again
(or any other commands). When I wish to resume execution of the vim
process - shifting it from suspended to foreground - I type 'fg', the
shell becomes suspended, vim resumes, detects that it's again running
in the foreground, and redraws the screen.
For this sequence to be effective, you also need the editor to write
its changes to disk before becoming suspended. Either you can do this
manually, which gets tiring and you may forget, or you can ask vim to
do it automatically by setting an internal vim setting -
:set autowrite<RETURN>
Then, just before vim is suspended it writes its changes to disk, and
the next compilation, etc, will be performed using the updated C file.
In much the same way that shell aliases can be saved between visits,
vim's settings can also be saved in a file named ~/.vimrc which you
can edit with vim itself, appending the line:
set autowrite (no leading colon).
____
See also:
https://www.thegeekdiary.com/understanding-the-job-control-commands-in-linux-bg-fg-and-ctrlz/