from small one page howto to huge articles all in one place
 

search text in:




Other .linuxhowtos.org sites: www.linuxhowtos.org
toolsntoys.linuxhowtos.org



Last additions:
How to make X listen on port 6000

How to make X listen on port 6000

words:

34

views:

68179

userrating:

average rating: 1.2 (8 votes) (1=very good 6=terrible)


May, 25th 2007:
April, 26th 2007:
Apr, 10th. 2007:
Druckversion . pdf icon
You are here: Tutorials per portage category->app-editors->VI

3. Practice Lesson #1


You should have a practice file called vilesson.txt in
your home directory. We will use it now:


$ vi vilesson.txt

Please note that in this lesson we will only practice the very
basics of vi. It is up to you to explore the editor further using
the provided cheat-sheet.


General Rules



  1. Do not use arrow keys to move the cursor
  2. Do not use PgDn or PgUp keys
  3. Do not use Home or End keys

If you accidently violate any of the above rules and cause strange
characters to be inserted into the file, or if anything else
unexpected happens, and you don't know how to correct it, press
Escape followed with :q! (quit without
saving
command). Then open the file again and continue the
lesson.


All exercises in Practice Lesson #1 consist of
Actions (marked here as A:) and Verifications
(marked here as V:).


Moving Around Text


First we will move around the file line by line.



A:
Press j three times.
V:
Cursor should now be resting on the fourth line.
A:
Type 8j
V:
Cursor should have moved 8 lines down to "Mr. John Bigfoot".
A:
Go up 2 lines by pressing k twice. Now go up 7 more
lines using the combination of a number and the k command.
V:
Your cursor should be on the "Big Town" line.

There is a way to move to a specific line number.



A:
Type :set number and press Enter key.
V:
Line numbers should be displayed at the left margin.
A:
Type 33G
V:
Your cursor should be resting at line #33.
A:
Type :set nonumber
V:
Line numbers should disappear.
A:
Go to the first line in the file by typing 1G (as in
line #1, GO).
V:
Your cursor should be at the top of the file.
A:
To go to the last line in the file, you do not need to specify
the line number at all (it would often be inconvenient). Type
G
V:
Cursor should be at the last line of the file.

To move sideways we will use command l (letter el)
to move right, and command h to move left. First go
back to the beginning of the line "40 PR Special (Pink Squirrel)".
When you're done, continue with the exercise.



A:
Press l three times.
V:
Cursor should be on character "P".
A:
Type 10l (number 10 followed by letter el)
V:
Cursor should be resting on white space between words "Special"
and "Pink".
A:
Press h twice.
V:
Cursor should be on character "a" of the letter "Special".
A:
Now go directly to the end of the line by pressing $
(dollar sign).
V:
Cursor should be at the end of the line.
A:
Go back to the beginning of the line by pressing 0 (zero).
V:
Cursor should be at the beginning of the line.

We can also move using words, sentences and paragraphs as delimiters.
First make sure your cursor is still at the beginning of the line
"40 PR Special (Pink Squirrel)".



A:
Press w (as in word) twice.
V:
Cursor should be at the beginning of the word "Special".
A:
Type 3w
V:
Cursor should be at the beginning of the word "Squirrel".
Note that vi knows that "(" is not a part of the word, and it
counts those elements separately.
A:
Go two paragraphs down by pressing 2} (right curly
brace).
V:
Cursor should be resting before the beginning of the
paragraph "We are looking forward [...]"
A:
Go to the previous sentence by pressing ( (left
parenthesis).
V:
Cursor should be on the word "We". Note:
Using sentences as delimiters is known to be broken in a couple
of vi implementations.
A:
Move to the end of the word by pressing e (as in end
of the word
).
V:
Cursor should be resting on the letter "e".
A:
To move one page forward, press Ctrl-F
V:
Depending on your terminal definition, the cursor should have
moved an appropriate number of lines forward. In our case, since
the file is short, you are most likely at the last line.
A:
Press Ctrl-B to go back one page.
V:
Cursor should have moved up one terminal page. Note:
On some older DOS versions of vi this command might scroll up the
page without moving the cursor. If this happens to you, press
Ctrl-B again.

Searching


Make sure your cursor is at the top of the file, then proceed
with the exercise.



A:
Press /, type your and press Enter
V:
Cursor should be on the word "your" in the middle of the sentence
"Thank you for placing your order with us".
A:
Press n (for 'next').
V:
Cursor should be on the word "your" before words "March 25".
A:
Press G to go to the end of the file.
V:
Cursor should be at the bottom of the file.
A:
Press ?, type ( and press Enter
V:
Your cursor should be on the left parenthesis before the word
"Moscow".

Deleting, Copying, And Pasting


We will practice commands d (delete),
p and P (paste), and the command
. (period, which means repeat last edit).
Make sure your cursor is still on the left paren before the word
"Moscow".



A:
Type d$
V:
You have just asked to delete to the end of line: d for
delete and $ for end of line (to
indicate the scope of the operation). Entire description of the
"Stock Option" drink should have disappeared.
A:
Press n to find the next instance of "(" (that was
our last search).
V:
Cursor should be on the left paren before the word "Ping-Pong".
A:
Repeat the previous edit (delete to end of the line) by pressing
. (period).
V:
Description of the "Day in TAC" drink should have disappeared.
A:
Press n again followed by . (period).
V:
Description of the "PR Special" drink should have disappeared.
A:
Repeat the last operation.
V:
All of the descriptions of the drinks (please ignore the fact that
some of them are intentionally wrong) should be gone.
A:
Exit the file without saving it by typing command :q!
V:
You should be at the UNIX shell command prompt.

Bring the file back into the editor with the command:



$ vi vilesson.txt

By now you have noticed that one of the drinks is really an appetizer.
We need to move it into the right place.



A:
Type /Early and press Enter
V:
Cursor should be on the line with "Early Release".
A:
Delete the whole line by pressing d twice.
V:
Line should be gone.
A:
Press P (upper case).
V:
The line you deleted is pasted above "Sales Engineer Special".
A:
Now press u for undo, remember which line
your cursor is on and then press p (lowercase).
V:
The line you deleted is pasted below your cursor line.

Note that uppercase P pastes text above the cursor line,
lowercase p pastes below.


If you only wish to copy the original line(s) without deleting at
the same time, use the yank command.



A:
Move you cursor to the second line, type 3Y, move your
cursor all the way down by pressing G and press
p
V:
Lines 2, 3, and 4 should have been pasted under "Tony Thomas".
A:
Now press u to undo the changes.
V:
The lines you have pasted should have disappeared.

The above operation could also be accomplished using lowercase
yank and the symbol for the object to be copied.



A:
Move your cursor back to line 2. Type commands y}Gp
V:
Lines 2, 3, and 4 should have been pasted under "Tony Thomas".
A:
Now undo the changes.
V:
The lines you have pasted should have disappeared.

Replacing Text


You have just noticed that the name of the addressee is spelled
"Bigfoot". It should be "Bigshot". You will now globally change
it.



A:
Press : (vi command line), type
%s/Bigfoot/Bigshot/g and press Enter
V:
All instances of "Bigfoot" should have changed to "Bigshot".

What you have typed means command line (:), the whole
file
(%), substitute (s), Bigfoot with Bigshot
(/Bigfoot/Bigshot/), any occurance on a line (g). Without
the last g, the substitution would be performed only
once per line. In our case it would not make any difference, but
it is a cheap insurance to take. The character % at
the beginning of the command means literally from the first to
the last line
. You could specify a narrower range of lines.
:13,19s/Bigfoot/Bigshot/ would perform the substitution
on a range of lines 13 through 19.


It is possible to replace specific number of words with whatever
text we wish to type in.



A:
Press / and then type send and press
Enter. Now type cw (for change word),
type be delivering and press Escape
V:
The word "send" should have been replaced with "be delivering".
Note that only the word "send" was replaced.

You could also specify
multiple words to be replaced, for example c3w. This
has a distinct advantage over more conventional overwriting because
it has clear word-boundary delimiters.


Overwriting one character, however, can be useful as a quick
correction. Note that the word "Febeuary" is misspelled.



A:
Place your cursor on the second "e" in that word and press r
twice.
V:
The word "Febeuary" should now read "February".

The first time you pressed r above it meant replace,
the second time with letter r. You do not need to finish
the command with Escape because there is an understanding
that only one letter will be input. This was single-letter
overwriting. Should you wish to overwrite continuously, you would
use the letter R instead. You would also need to finish
the command by pressing Escape since the number of
characters to be overwritten is not pre-determined.


Changing Case


Notice that the word "serVEd" has improperly capitalized two letters.



A:
Go to the word "serVEd", place your cursor over the first miscapitalized
letter and press ~ (tilde) twice.
V:
The word should now read "served".

Saving Files


It is time to save the changes.



A:
Press : (for command line), type w
(for write) and press Enter
V:
The changes have been saved. There could be a one-line note at
the bottom of the screen saying, "vilesson.txt: 48 lines, 954
characters" (or something similar) to confirm a successful save.

There are other ways to save files, so please read the cheat-sheet
for the command summary.


Inserting Text


There are three parts to entering text:



  1. input command (A, I, O, R, a, c, i, o)
  2. text to be inserted (anything you wish)
  3. termination of input command (Escape key)

The third part is always the same. All text input commands
listed above are terminated with Escape key. Part one
is where the variation occurs.



A:
Move the cursor to the beginning of line 38. Press i
and start typing text. When you finish the sentence, press
Escape.
V:
As you have noticed, i inserts text before the
letter the cursor rests on.

To enter text after the cursor, you would use a
(append) command. Now move your cursor to the second line
in the table listing drinks to be delivered.



A:
Press o.
V:
A new blank line should have been opened below the cursor line.
A:
Type some text. Press Escape.
V:
Text should have been entered on the blank line.
A:
Press u.
V:
Text you entered should have disappeared.
A:
Now press capital O, type some text and press
Escape.
V:
Text should have been entered on the line above the former cursor
line.

Note that the capitalized version of the same command opens the
line for text input above the cursor line. Note similarities
to the p and P commands. Press u.


Make sure you are approximately in the middle of the line of text (any
line).



A:
Press I (the capitalized version of the insert
command). Start typing text. Press Escape.
V:
Text should have been entered at the beginning of the line.
A:
Press u to undo changes.
V:
Text you entered should have disappeared.
A:
Now press A (the capitalized version of the append
command, type some text and terminate the command.
V:
Text should have been appended to the end of the line.
A:
Press u to undo changes.
V:
Text you entered should have disappeared.

Exiting file


You can exit file with or without saving changes.



A:
To save and exit, type :wq and press Enter.
V:
File has been saved and you should be at the UNIX command prompt.
A:
Open the file using vi vileson.txt and make some
changes (if you are entering text, please remember to terminate
the text input command with Escape). Type :q
and press Enter.
V:
Normally that would allow you to quit file, but since you have
changed the file, vi most likely will ask you to either save or
use bang (! command) to overwrite the protection.
A:
Type :q! and press Enter.
V:
You should be back at the UNIX command prompt.

Note that bang also works in conjunction with :w
and :wq commands.


End Of Practice Lesson #1



/* The article above and any accompanying files are freely
* distributable, but please leave this notice and the text intact.
* Home for this document: http://www.infobound.com/vi.html
* Copyright (C) 1994, 1999 Tony Thomas
* Contact author through email:
tony@infobound.com
* Last revision Feb 23, 1999
* UNIX is a trademark of X/Open
*/

rate this article:
current rating: no votes yet
Your rating:
Very good (1) Good (2) ok (3) average (4) bad (5) terrible (6)

back



Support us on Content Nation

New Packages

- as rdf newsfeed
- as rss newsfeed
- as Atom newsfeed
2024-07-27
bash - 5.3_alpha_p20240726
Ebuild name:

app-shells/bash-5.3_alpha_p20240726

Description

The standard GNU Bourne again shell

Added to portage

2024-07-27

faudio - 24.07
Ebuild name:

app-emulation/faudio-24.07

Description

Accuracy-focused XAudio reimplementation for open platforms

Added to portage

2024-07-27

installkernel - 41
Ebuild name:

sys-kernel/installkernel-41

Description

Gentoo fork of installkernel script from debianutils

Added to portage

2024-07-27

latexdiff - 1.3.4
Ebuild name:

dev-tex/latexdiff-1.3.4

Description

Compare two latex files and mark up significant differences

Added to portage

2024-07-27

litecli - 1.11.1
Ebuild name:

dev-db/litecli-1.11.1

Description

CLI for SQLite with auto-completion and syntax highlighting

Added to portage

2024-07-27

maildrop - 3.1.7
Ebuild name:

mail-filter/maildrop-3.1.7

Description

Mail delivery agent/filter

Added to portage

2024-07-27

metee - 4.2.0
Ebuild name:

dev-libs/metee-4.2.0

Description

Cross-platform access library for Intel CSME HECI interface

Added to portage

2024-07-27

pahole - 1.27-r1
Ebuild name:

dev-util/pahole-1.27-r1

Description

pahole (Poke-a-Hole) and other DWARF utilities

Added to portage

2024-07-27

ssldump - 1.8
Ebuild name:

net-analyzer/ssldump-1.8

Description

An SSLv3/TLS network protocol analyzer

Added to portage

2024-07-27

tcping - 2.1.0
Ebuild name:

net-analyzer/tcping-2.1.0

Description

Check if a desired port is reachable via TCP

Added to portage

2024-07-27

2024-07-26
apprise - 1.8.1
Ebuild name:

dev-python/apprise-1.8.1

Description

Push Notifications that work with just about every platform

Added to portage

2024-07-26

aquamarine - 0.1.1-r1
Ebuild name:

gui-libs/aquamarine-0.1.1-r1

Description

Aquamarine is a very light linux rendering backend library

Added to portage

2024-07-26

atlas - 3.10.2-r1
Ebuild name:

sci-libs/atlas-3.10.2-r1

Description

Automatically Tuned Linear Algebra Software

Added to portage

2024-07-26

atlas - 3.10.3
Ebuild name:

sci-libs/atlas-3.10.3

Description

Automatically Tuned Linear Algebra Software

Added to portage

2024-07-26

atlas - 3.11.41
Ebuild name:

sci-libs/atlas-3.11.41

Description

Automatically Tuned Linear Algebra Software

Added to portage

2024-07-26

atpublic - 5.0
Ebuild name:

dev-python/atpublic-5.0

Description

A decorator to populate __all__ and the module globals

Added to portage

2024-07-26

awscli - 1.33.31
Ebuild name:

app-admin/awscli-1.33.31

Description

Universal Command Line Environment for AWS

Added to portage

2024-07-26

bindgen - 0.69.4
Ebuild name:

dev-util/bindgen-0.69.4

Description

Automatically generates Rust FFI bindings to C and C++ libraries.

Added to portage

2024-07-26

blueman - 2.4.3
Ebuild name:

net-wireless/blueman-2.4.3

Description

Simple and intuitive GTK+ Bluetooth Manager

Added to portage

2024-07-26

boto3 - 1.34.149
Ebuild name:

dev-python/boto3-1.34.149

Description

The AWS SDK for Python

Added to portage

2024-07-26

botocore - 1.34.149
Ebuild name:

dev-python/botocore-1.34.149

Description

Low-level, data-driven core of boto 3

Added to portage

2024-07-26

croniter - 3.0.1
Ebuild name:

dev-python/croniter-3.0.1

Description

Python module to provide iteration for datetime object

Added to portage

2024-07-26

docile - 1.4.1
Ebuild name:

dev-ruby/docile-1.4.1

Description

Turns any Ruby object into a DSL

Added to portage

2024-07-26

faraday-net_http - 3.1.1
Ebuild name:

dev-ruby/faraday-net_http-3.1.1

Description

Faraday adapter for Net

Added to portage

2024-07-26

fastfetch - 2.20.0
Ebuild name:

app-misc/fastfetch-2.20.0

Description

Fast neofetch-like system information tool

Added to portage

2024-07-26

google-api-python-client - 2.138.0
Ebuild name:

dev-python/google-api-python-client-2.138.0

Description

Google API Client for Python

Added to portage

2024-07-26

grisbi - 3.0.4
Ebuild name:

app-office/grisbi-3.0.4

Description

Grisbi is a personal accounting application for Linux

Added to portage

2024-07-26

hcloud - 2.1.0
Ebuild name:

dev-python/hcloud-2.1.0

Description

Official Hetzner Cloud python library

Added to portage

2024-07-26

ibus-m17n - 1.4.31
Ebuild name:

app-i18n/ibus-m17n-1.4.31

Description

M17N engine for IBus

Added to portage

2024-07-26

ibus-typing-booster - 2.25.14
Ebuild name:

app-i18n/ibus-typing-booster-2.25.14

Description

Completion input method for IBus

Added to portage

2024-07-26

kdsingleapplication - 1.1.0-r1
Ebuild name:

dev-libs/kdsingleapplication-1.1.0-r1

Description

KDAB's helper class for single-instance policy applications

Added to portage

2024-07-26

libcdada - 0.6.0
Ebuild name:

dev-libs/libcdada-0.6.0

Description

Basic data structures in C

Added to portage

2024-07-26

micropython - 1.23.0
Ebuild name:

dev-lang/micropython-1.23.0

Description

Python implementation for microcontrollers

Added to portage

2024-07-26

mkdocstrings - 0.25.2
Ebuild name:

dev-python/mkdocstrings-0.25.2

Description

Automatic documentation from sources, for MkDocs

Added to portage

2024-07-26

mkdocstrings-python - 1.10.7
Ebuild name:

dev-python/mkdocstrings-python-1.10.7

Description

Python handler for dev-python/mkdocstrings

Added to portage

2024-07-26

mrcfile - 1.5.3
Ebuild name:

dev-python/mrcfile-1.5.3

Description

MRC2014 file format I/O library

Added to portage

2024-07-26

munin - 2.0.76-r1
Ebuild name:

net-analyzer/munin-2.0.76-r1

Description

Munin Server Monitoring Tool

Added to portage

2024-07-26

openjdk - 8.422_p05
Ebuild name:

dev-java/openjdk-8.422_p05

Description

Open source implementation of the Java programming language

Added to portage

2024-07-26

openjdk-bin - 8.422_p05
Ebuild name:

dev-java/openjdk-bin-8.422_p05

Description

Prebuilt Java JDK binaries provided by Eclipse Temurin

Added to portage

2024-07-26

owncloud-client - 5.2.1.13040-r1
Ebuild name:

net-misc/owncloud-client-5.2.1.13040-r1

Description

Synchronize files from ownCloud Server with your computer

Added to portage

2024-07-26

pytest - 8.3.2
Ebuild name:

dev-python/pytest-8.3.2

Description

Simple powerful testing with Python

Added to portage

2024-07-26

regress - 1.5.1
Ebuild name:

app-emacs/regress-1.5.1

Description

Regression test harness for Emacs Lisp code

Added to portage

2024-07-26

rssguard - 4.7.3
Ebuild name:

net-news/rssguard-4.7.3

Description

Simple (yet powerful) news feed reader

Added to portage

2024-07-26

simutrans - 124.1
Ebuild name:

games-simulation/simutrans-124.1

Description

A free Transport Tycoon clone

Added to portage

2024-07-26

sqlglot - 25.7.1
Ebuild name:

dev-python/sqlglot-25.7.1

Description

An easily customizable SQL parser and transpiler

Added to portage

2024-07-26

strawberry - 1.0.23-r2
Ebuild name:

media-sound/strawberry-1.0.23-r2

Description

Modern music player and library organizer based on Clementine and

Added to portage

2024-07-26

stripe - 10.5.0
Ebuild name:

dev-python/stripe-10.5.0

Description

Stripe Python bindings

Added to portage

2024-07-26

tempora - 5.7.0
Ebuild name:

dev-python/tempora-5.7.0

Description

Objects and routines pertaining to date and time

Added to portage

2024-07-26

tomcat-native - 1.3.1
Ebuild name:

dev-java/tomcat-native-1.3.1

Description

Allows Tomcat to use certain native resources for better performance

Added to portage

2024-07-26

tuxedo-drivers - 4.6.1
Ebuild name:

app-laptop/tuxedo-drivers-4.6.1

Description

Kernel modules for TUXEDO laptops

Added to portage

2024-07-26

virtualbox - 7.1.0_beta1
Ebuild name:

app-emulation/virtualbox-7.1.0_beta1

Description

Family of powerful x86 virtualization products for enterprise

Added to portage

2024-07-26

virtualbox-additions - 7.1.0_beta1
Ebuild name:

app-emulation/virtualbox-additions-7.1.0_beta1

Description

CD image containing guest additions for VirtualBox

Added to portage

2024-07-26

virtualbox-extpack-oracle - 7.1.0_beta1
Ebuild name:

app-emulation/virtualbox-extpack-oracle-7.1.0_beta1

Description

PUEL extensions for VirtualBox

Added to portage

2024-07-26

virtualbox-guest-additions - 7.1.0_beta1
Ebuild name:

app-emulation/virtualbox-guest-additions-7.1.0_beta1

Description

VirtualBox kernel modules and user-space tools

Added to portage

2024-07-26

virtualbox-modules - 7.1.0_beta1
Ebuild name:

app-emulation/virtualbox-modules-7.1.0_beta1

Description

Kernel Modules for Virtualbox

Added to portage

2024-07-26

yara-x - 0.5.0
Ebuild name:

app-forensics/yara-x-0.5.0

Description

A malware identification and classification tool

Added to portage

2024-07-26

rdf newsfeed | rss newsfeed | Atom newsfeed
- Powered by LeopardCMS - Running on Gentoo -
Copyright 2004-2020 Sascha Nitsch Unternehmensberatung GmbH
Valid XHTML1.1 : Valid CSS : buttonmaker
- Level Triple-A Conformance to Web Content Accessibility Guidelines 1.0 -
- Copyright and legal notices -
Time to create this page: 53.1 ms