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:

38205

userrating:

average rating: 1.5 (4 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
Please read "Why adblockers are bad".



other Ads
Trace My Cash
Wenn Sie sich schon immer mal gefragt haben, wo eigentlich Ihr geliebtes Bargeld geblieben ist, finden Sie hier vielleicht die Antwort.
www.tracemycash.com
Other free services
toURL.org
Shorten long
URLs to short
links like
http://tourl.org/2
tourl.org
.
Reverse DNS lookup
Find out which hostname(s)
resolve to a
given IP or other hostnames for the server
www.reversednslookup.org

New Packages

- as rdf newsfeed
- as rss newsfeed
- as Atom newsfeed
2017-06-26
Babel - 2.4.0
Ebuild name:

dev-python/Babel-2.4.0

Description

Collection of tools for internationalizing Python applications

Added to portage

2017-06-26

abcm2ps - 8.13.11
Ebuild name:

media-sound/abcm2ps-8.13.11

Description

A program to convert abc files to Postscript files

Added to portage

2017-06-26

aiohttp - 2.2.0
Ebuild name:

dev-python/aiohttp-2.2.0

Description

http client/server for asyncio

Added to portage

2017-06-26

ampache - 3.8.3
Ebuild name:

www-apps/ampache-3.8.3

Description

PHP-based tool for managing,updating and playing audio files via a web inter

Added to portage

2017-06-26

astropy - 1.3.3
Ebuild name:

dev-python/astropy-1.3.3

Description

Core functionality for performing astrophysics with Python

Added to portage

2017-06-26

astropy-helpers - 1.3.1
Ebuild name:

dev-python/astropy-helpers-1.3.1

Description

Helpers for Astropy and Affiliated packages

Added to portage

2017-06-26

blueberry - 1.1.13
Ebuild name:

net-wireless/blueberry-1.1.13

Description

A Bluetooth configuration tool

Added to portage

2017-06-26

bluez-tools - 0_p20161212
Ebuild name:

net-wireless/bluez-tools-0_p20161212

Description

A set of tools to manage bluetooth devices for linux

Added to portage

2017-06-26

calibre - 3.1.1
Ebuild name:

app-text/calibre-3.1.1

Description

Ebook management application

Added to portage

2017-06-26

camlp5 - 7.00
Ebuild name:

dev-ml/camlp5-7.00

Description

A preprocessor-pretty-printer of ocaml

Added to portage

2017-06-26

cfitsio - 3.410
Ebuild name:

sci-libs/cfitsio-3.410

Description

C and Fortran library for manipulating FITS files

Added to portage

2017-06-26

chromium - 61.0.3135.4
Ebuild name:

www-client/chromium-61.0.3135.4

Description

Open-source version of Google Chrome web browser

Added to portage

2017-06-26

gentoo-sources - 4.1.41
Ebuild name:

sys-kernel/gentoo-sources-4.1.41

Description

Full sources including the Gentoo patchset for the . kernel tree

Added to portage

2017-06-26

jenkins-bin - 2.67
Ebuild name:

dev-util/jenkins-bin-2.67

Description

Extensible continuous integration server

Added to portage

2017-06-26

jsoncpp - 1.8.1
Ebuild name:

dev-libs/jsoncpp-1.8.1

Description

C++ JSON reader and writer

Added to portage

2017-06-26

keyring - 10.4.0
Ebuild name:

dev-python/keyring-10.4.0

Description

Provides access to the system keyring service

Added to portage

2017-06-26

knot - 2.4.5
Ebuild name:

net-dns/knot-2.4.5

Description

High-performance authoritative-only DNS server

Added to portage

2017-06-26

knot - 2.5.2
Ebuild name:

net-dns/knot-2.5.2

Description

High-performance authoritative-only DNS server

Added to portage

2017-06-26

libffado - 2.3.0
Ebuild name:

media-libs/libffado-2.3.0

Description

Driver for IEEE1394 (Firewire) audio interfaces

Added to portage

2017-06-26

libreoffice - 5.4.9999
Ebuild name:

app-office/libreoffice-5.4.9999

Description

A full office productivity suite

Added to portage

2017-06-26

libyami - 1.2.0
Ebuild name:

media-libs/libyami-1.2.0

Description

Yet Another Media Infrastructure Media codec with hardware acceleration

Added to portage

2017-06-26

lmdb - 0.92
Ebuild name:

dev-python/lmdb-0.92

Description

Python bindings for the Lightning Database

Added to portage

2017-06-26

memcached - 1.4.38
Ebuild name:

net-misc/memcached-1.4.38

Description

High-performance, distributed memory object caching system

Added to portage

2017-06-26

pytest-mpl - 0.7
Ebuild name:

dev-python/pytest-mpl-0.7

Description

pytest plugin to faciliate image comparison for matplotlib figures

Added to portage

2017-06-26

roadie - 3.2.2
Ebuild name:

dev-ruby/roadie-3.2.2

Description

Making HTML emails comfortable for the Rails rockstars

Added to portage

2017-06-26

rouge - 2.1.1
Ebuild name:

dev-ruby/rouge-2.1.1

Description

Yet-another-markdown-parser using a strict syntax definition in pure Ruby

Added to portage

2017-06-26

shorewall - 5.1.4.4
Ebuild name:

net-firewall/shorewall-5.1.4.4

Description

Added to portage

2017-06-26

sks - 1.1.6-r1
Ebuild name:

net-misc/sks-1.1.6-r1

Description

An OpenPGP keyserver which is decentralized with highly reliable synchronizat

Added to portage

2017-06-26

xfce4-screenshooter - 1.9.0
Ebuild name:

xfce-extra/xfce4-screenshooter-1.9.0

Description

Xfce4 screenshooter application and panel plugin

Added to portage

2017-06-26

xmlsec - 1.2.24
Ebuild name:

dev-libs/xmlsec-1.2.24

Description

Command line tool for signing, verifying, encrypting and decrypting XML

Added to portage

2017-06-26

yarl - 0.10.3
Ebuild name:

dev-python/yarl-0.10.3

Description

Yet another URL library

Added to portage

2017-06-26

zict - 0.1.2
Ebuild name:

dev-python/zict-0.1.2

Description

Mutable mapping tools

Added to portage

2017-06-26

2017-06-25
DBIx-SearchBuilder - 1.660.0-r1
Ebuild name:

dev-perl/DBIx-SearchBuilder-1.660.0-r1

Description

Encapsulate SQL queries and rows in simple Perl objects

Added to portage

2017-06-25

aufs-sources - 4.9.34
Ebuild name:

sys-kernel/aufs-sources-4.9.34

Description

Full sources including the Gentoo patchset for the linux kernel tree

Added to portage

2017-06-25

aufs4 - 0_pre20170612
Ebuild name:

sys-fs/aufs4-0_pre20170612

Description

An entirely re-designed and re-implemented Unionfs

Added to portage

2017-06-25

bdsup2sub - 4.0.0-r2
Ebuild name:

media-video/bdsup2sub-4.0.0-r2

Description

A tool to convert and tweak bitmap based subtitle streams

Added to portage

2017-06-25

ck-sources - 4.11.7
Ebuild name:

sys-kernel/ck-sources-4.11.7

Description

Con Kolivas' high performance patchset and Gentoo's genpatches for Lin

Added to portage

2017-06-25

ck-sources - 4.9.34
Ebuild name:

sys-kernel/ck-sources-4.9.34

Description

Con Kolivas' high performance patchset and Gentoo's genpatches for Lin

Added to portage

2017-06-25

dbskkd-cdb - 3.00
Ebuild name:

app-i18n/dbskkd-cdb-3.00

Description

SKK dictionary server based on cdb

Added to portage

2017-06-25

dnscrypt-proxy - 1.9.4-r1
Ebuild name:

net-dns/dnscrypt-proxy-1.9.4-r1

Description

A tool for securing communications between a client and a DNS resol

Added to portage

2017-06-25

git - 2.13.2
Ebuild name:

dev-vcs/git-2.13.2

Description

stupid content tracker distributed VCS designed for speed and efficiency

Added to portage

2017-06-25

liblinear - 211
Ebuild name:

dev-libs/liblinear-211

Description

A Library for Large Linear Classification

Added to portage

2017-06-25

libsvm - 3.22
Ebuild name:

sci-libs/libsvm-3.22

Description

Library for Support Vector Machines

Added to portage

2017-06-25

mtime - 1.1.0
Ebuild name:

dev-ml/mtime-1.1.0

Description

OCaml module to access monotonic wall-clock time

Added to portage

2017-06-25

nano - 2.8.5
Ebuild name:

app-editors/nano-2.8.5

Description

GNU GPL'd Pico clone with more functionality

Added to portage

2017-06-25

ocaml - 4.04.2
Ebuild name:

dev-lang/ocaml-4.04.2

Description

Type-inferring functional programming language descended from the ML family

Added to portage

2017-06-25

opera - 46.0.2597.26
Ebuild name:

www-client/opera-46.0.2597.26

Description

A fast and secure web browser

Added to portage

2017-06-25

podracer - 1.4-r1
Ebuild name:

media-sound/podracer-1.4-r1

Description

A simple podcast aggregator, designed for cron

Added to portage

2017-06-25

ruby-opengl - 0.10.0
Ebuild name:

dev-ruby/ruby-opengl-0.10.0

Description

OpenGL / GLUT bindings for ruby

Added to portage

2017-06-25

servlet-api - 2.5-r2
Ebuild name:

java-virtuals/servlet-api-2.5-r2

Description

Virtual for servlet api

Added to portage

2017-06-25

servlet-api - 3.0-r2
Ebuild name:

java-virtuals/servlet-api-3.0-r2

Description

Virtual for servlet api

Added to portage

2017-06-25

servlet-api - 3.1-r1
Ebuild name:

java-virtuals/servlet-api-3.1-r1

Description

Virtual for servlet api

Added to portage

2017-06-25

skktools - 1.3.3_p20170305
Ebuild name:

app-i18n/skktools-1.3.3_p20170305

Description

SKK utilities to manage dictionaries

Added to portage

2017-06-25

sonic-snap - 1.7-r1
Ebuild name:

media-video/sonic-snap-1.7-r1

Description

Webcam app for sn9c10x based camera controllers (with optional MPEG4

Added to portage

2017-06-25

tcmplex-panteltje - 0.4.7-r1
Ebuild name:

media-video/tcmplex-panteltje-0.4.7-r1

Description

Audio video multiplexer for 8 audio channels

Added to portage

2017-06-25

test-unit - 3.2.5
Ebuild name:

dev-ruby/test-unit-3.2.5

Description

An xUnit family unit testing framework for Ruby

Added to portage

2017-06-25

youtube-dl - 2017.06.25
Ebuild name:

net-misc/youtube-dl-2017.06.25

Description

Download videos from YouTube.com (and more sites...)

Added to portage

2017-06-25

rdf newsfeed | rss newsfeed | Atom newsfeed
- Powered by LeopardCMS - Running on Gentoo -
Copyright 2004-2017 Sascha Nitsch Unternehmensberatung UG(haftungsbeschänkt)
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: 6.4 ms
system status display