Lab 3 With Vim
Lab 3 With Vim
Lab 3 With Vim
➢ vi – console terminal-based (non-GUI) text editor, standard version (vi may have limited
features)
➢ vim – vi text editor (as above) but an improved version (vim has full features that vi may
not)
➢ gvim – vim text editor - graphical version for X11 GUI (full features) - may not be installed
➢ vimtutor – vim text editor interactive tutorial - type this command at any shell prompt
• The vi text editor is the standard editor available on most every Unix-derived system, including
Linux, MacOSX, and BSD. It can be used on most any terminal, over the slowest of dial-up links. It
is a pure console terminal-based program that needs no mouse or graphical display screen. No
mouse!
• Similar to learning to touch-type on a keyboard, the vim editor is difficult to learn but easy to use
once you have some mastery of it. Until you master it, you will find using vi awkward. Once you
master it, you will easily outperform anyone using a mouse-based editor such as Notepad. Learn
the tool!
• The single-character command keys used in vi have found their way into other programs. The
bash shell supports a vi mode for editing command lines, and the less and more pager programs
(used by the man command) use vi commands to move around the screen and search for text.
• vi is incredibly powerful. Most students refuse to learn it well enough to get out of the awkward
stage. They never master many vi commands. They go into vi insert mode and perform all text
editing using the arrow and backspace keys, turning vi into a slower, mouseless version of Notepad.
If you want a Unix/Linux job, learn the editor tool! If you want to use arrow keys, us the Pico or
Nano editors instead.
Note the use of >> append redirection on the sum command line. Note the use of a hidden file name
for both the output redirection lines. This hidden name will not be matched by the shell GLOB patterns.
Changing permissions with chmod will be covered fully toward the middle of the semester.
Check to ensure that you have 9+9=18 lines of output in the .verify.txt file. (Recall the command
that counts lines inside a file. Use it to count the lines in your .verify.txt file. There should be 18
lines.)
\
Run the following sets of commands. Observe what is output to the screen and examine the
contensts of the files that get created. A short 1-2 line English explanation of what's happening is all
that's needed. The paired commands are similar, but different in some way – note the differences.
b) What is the difference in the result of the following commands? Note that the file October
should still exists from 1a) and that the file November should not exist.
i. cat October November 1> result-b1
ii. cat October November 2> result-b2
c) What is the difference in the result of the of following sets of commands. Explain what happens:
i. cat October November 1> result-c1 2> result-c2
ii. cat October November 2> /dev/null
e) Refer to the man pages on the tee command and pay attention to the -a option. Run the following
commands and check the contents of the result file after each one. Explain the contents of the
resulting files, especially the number of lines
i. date | tee r1 r1 r1
ii. date | tee -a r2 r2 r2
f) Type in the following commands, enter a few lines of text and then press <CTRL>D (end of file.)
Explain what the commands do
i. cat </dev/tty >/dev/tty
ii. cat | tee copy1 copy2 >copy
2. Redirection Using the exec Command (6 marks)
In class we discussed the exec command which can be used to set up redirection between a
file descriptor and file for the duration of your shell login session. To review:
exec fileDescriptorNum>fileName sets up fileName for output using the specified number.
exec fileDescriptorNum<fileName sets it up for input
exec fileDescriptorNum<>filename sets it up for input and output
b) Try each of the following, recording what you did: (1 mark each)
i) The maximum fileDescriptor number you can use? Compare this number to the
result reported by issuing the command. ulimit –a
ii) Associate a file descriptor with a symbolic link and show that you can read (or write)
to the file. Does this work?
iii) Associate file descriptor 2 with a file and record the command you used. Even though
you won’t see a prompt, enter a couple of good commands – they should work even
though you won’t see them at the terminal. Now enter a couple of bad commands.
Now look at the contents of the file and provide a listing in the report. Explain why
you didn’t see your prompt and your commands.
iv) What happens if you try and associate a file descriptor with a file that doesn’t exist?
Prove that this does or does not have an effect and describe how you did it.