Linux with Operating System Concepts



Download 5,65 Mb.
Pdf ko'rish
bet64/254
Sana22.07.2022
Hajmi5,65 Mb.
#840170
1   ...   60   61   62   63   64   65   66   67   ...   254
Bog'liq
Linux-with-Operating-System-Concepts-Fox-Richard-CRC-Press-2014

filename
, use 
:r 
filename
. To save a file, use 
:w
if the 
file is already named (if unnamed, you receive an error message) and 
:w 
filename
to 
save a file under the name 
filename
. To exit vi, use 
:q
. If the file has not been saved since 
last changed, you will be given an error. Use 
:q!
to force vi to quit in spite of not saving 
the file. You can combine saving and quitting using 
:wq
. You can also specify a command 
using 
:command
as in 
:undo

:put

:sort
. Finally, you can execute a shell command 
from within vi by using 
:!
command
 
as in 
:!wc
(word count). This shifts your view from 
vi to the command line and then waits for you to hit 
<
enter
>
to return to vi.
Insertion locations
O
o
I
i a
A
FIGURE 5.2 
Insertion commands in vi.


164

Linux with Operating System Concepts
Finally, there are commands to repeat and undo. To repeat the last command, type 
period (
.
). To repeat a command multiple times, do 
#command
where 
#
is an integer 
number and 
command
is the keystroke(s) to be repeated. As an example, 
4dd
will issue 
the 
dd
command 4 times, or delete four consecutive lines. The command 
12j
will move 
the cursor down 12 lines. To undo the last command, use 
u
. You can continue to use 
u
to 
undo previous commands in reverse order. For instance, 
u
undoes the last command and 
another 
u
undoes the command before it. You can do 
#u
where # is a number to undo a 
number of commands, as in 
6u
to undo the last six commands. The command U undoes 
all commands that have been issued on the current line of the text. Consider, for instance, 
deleting a character, moving the cursor one to the right on the line, using 
xp
, moving the 
cursor further to the right on the line, and deleting a word using 
dw
. Issuing 
U
will undo 
all these commands.
5.2.2 emacs
The emacs text editor offers an option to vi. Some prefer emacs because it is more power-
ful and/or because the commands are more intuitive (in most cases, the letters to con-
trol cursor movement and related operations use the letters that start their names, such 
as 
control
+
f
for “forward,” 
control
+
b
for “backward,” etc.). Others dislike emacs 
because, upon learning vi, they find emacs to be either too overwhelming or dislike the 
commands.
Unlike vi, which has distinct modes, emacs has only one mode, insert. Commands 
are issued at any time by using either the control or escape key in conjunction with other 
keys. Therefore, any key entered that is not combined with control or escape is inserted 
at the current cursor position. In this section, we will describe these commands. We use 
the notation ctrl
+
char
to indicate control
+
char
as in 
ctrl
+
k
, and esc
+
char
to indicate 
escape
+
char
as in 
esc
+
f
. To perform ctrl
+
char
, press control and while holding it down, 
press 
char
. To perform esc
+
char
, press the escape key and then after releasing, press the 
char
key.
When you start emacs, you will be placed inside an empty (or nearly empty) buffer. The 
text you enter appears in this buffer as you type it. You are able to open other buffers and 
move between them even if a buffer is not visible at the moment. We will explore buffers 
later in this section.
As you enter the text, characters are placed at the position of the cursor. Upon reach-
ing the end of the line, characters are wrapped onto the next line. If this occurs within a 
word, the word is segmented with a \ character. This is unlike a normal word processor that 
performs word wrap by moving the entire word that is segmented onto the next line. For 
instance, the text below might indicate how three lines appear.
Desperate nerds in high offices all over the world have been known to enact the m\ 
ost disgusting pieces of legislation in order to win votes (or, in places where they d\ 
on’t get to vote, to control unwanted forms of mass behavior).


Linux Applications

165
The above text represents one line. If the cursor appears anywhere inside this line, mov-
ing to the beginning of the line moves you to the ‘D’ in Desperate while moving to the end 
of the line moves you to the ‘.’
The most basic commands in emacs are the character movement commands. Figure 5.3 
illustrates the most common and useful of these commands. You might notice, if you refer 
back to Chapter 2, that many of these commands are the same as the command-line edit-
ing commands found in Bash.
The basic commands shown in Figure 5.3 allow you to move forward, backward, up, and 
down using 
ctrl
+
f

ctrl
+
b

ctrl
+
p
, and 
ctrl
+
n
(forward, backward, previous, and 
next), and move to the beginning or end of the current line (
ctrl
+
a

ctrl
+
e
). The command 
esc
+<
and 
esc
+>
move the cursor to the beginning and end of the document, respectively.
The commands 
esc
+
b
and 
esc
+
f
move you to the beginning or end of the current 
word. Notice in Figure 5.3, the hyphen indicates a different word; so, 
esc
+
b
takes you 
from ‘l’ to ‘h’, not ‘e’. A separate 
esc
+
b
is needed to move the cursor to the ‘e’. You can 
move up and down one screen using 
esc
+
v
and 
ctrl
+
v,
respectively.
Editing commands are as follows:
• 
ctrl
+
d
—delete the current character
• 
ctrl
+
k
—delete from cursor to the end of the line (kill)
• 
esc
+
d
—delete (kill) from cursor to the end of the current word
• 
esc
+<
backspace
>
—delete (kill) from this point backward to the beginning of the 
current word
• 
ctrl
+
y
—retrieve all killed items and paste them at the cursor (anything killed but 
not deleted via ctrl
+
d)
• 
ctrl
+
t
—transpose this and the next characters
esc+<
esc+b
esc+v
abcd efg-hijklmnop qrst. Uvwxy
esc+f
ctrl+p
ctrl+a ctrl+b
ctrl+f ctrl+e
ctrl+n
ctrl+v
esc+>
FIGURE 5.3 
emacs cursor movement commands.


166

Linux with Operating System Concepts
• 
esc
+
t
—transpose this and the next word
• 
ctrl
+
x u
—undo the last command (also ctrl 
+
_ and ctrl 
+
/)
• 
esc
+
u
—convert the current word from this point forward into all uppercase letters
• 
esc
+
l
—convert the current word from this point forward into all lowercase letters
• 
esc
+
c
—convert this character into capital and the remainder into lowercase letters
Mastering the cut and paste via 
esc
+
d

esc
+<
backspace
>
,
and 
ctrl
+
k
followed 
by 
ctrl
+
y
can be tricky. Any item killed is placed into a “kill buffer” and 
ctrl
+
y
copies 
what is in the kill buffer to the current cursor position. However, as soon as you move the 
cursor using any of the cursor commands (see Figure 5.3), you end the kill buffer. You can 
still yank items back, but if you start deleting something new, you end the old kill buffer 
and replace it with a new one.
Consider, for instance, the following sentence in your buffer:
The lazy brown cow jumped over the man in the moon holding a silver spoon.
The cursor is currently over the ‘l’ in lazy. You perform the following operations: 
esc
+
d

esc
+
d
to delete “lazy” and “brown,” followed by 
esc
+
f

esc
+
f
, and 
esc
+
f
. Now, you do 
esc
+
d

esc
+
d
, and 
esc
+
d
. This deletes “the man in,” leaving the sentence
The cow jumped over the moon holding a silver spoon.
You move the cursor back to before “cow” and do 
ctrl
+
y
. What is yanked is just “the 
man in,” not “lazy brown.”
You can also cut a large region of text without using ctrl
+
k. For this, you need to mark 
the region. Marking a region is done by moving the cursor to the beginning of the region 
and doing either ctrl
+<
space
>
or ctrl
+
@. Now, move to the end of the region and use 
ctrl
+
w. Everything from the mark to the cursor’s current position is deleted. Move to the 
new location and use ctrl
+
y to paste the cut region. If you use esc
+
w instead of ctrl
+
w, it 
performs a copy instead of a cut.
Commands can be repeated using 
esc
+

Download 5,65 Mb.

Do'stlaringiz bilan baham:
1   ...   60   61   62   63   64   65   66   67   ...   254




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish