LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   vi (https://www.linuxquestions.org/questions/linux-newbie-8/vi-4175441542/)

jack_ 12-15-2012 05:05 AM

vi
 
hey everyone,
i m just wondering if there is any way i can select text in vi same as gedit,notepad,etc(shift + arrowkeys) or as we can do in nano > alt + a to set marker and then select text using arrow keys ?

thanks

shivaa 12-15-2012 05:10 AM

Hmm.. prehaps no! But to select a single word, just double click on any of it's character, and it will be selected, then if quick edit mode is activated on the tool (i.e. if you're using putty or terminal, it's already on) selected text will already get copied after selection.
However, if selected text has not got copy, then after selection (using double click on it), use SHIFT+INSERT to copy it and to paste it, use CTRL+INSERT key combination.

=== Adding info. ====
In vi editor, copy is done using yy (stands for yank), but it has certain limitation. For instance:-
yy - Copies current line
yw - Copies 1 word forward
And few more...
But problem with yy is that, you'll need to use "p" (below the current record) and "P" (above the current record) keystrock to paste copied content, which is not convenient and aprropriate.

markush 12-15-2012 05:43 AM

Hi,

it depends on what you want to do with the selected text. In vi the commands are always a combination "how many of" + "what" + "do this".
Example 3dw delete up to the third word, 3dd delete three lines.

Please explain what exactly you want to do.

Markus

1300 12-15-2012 06:01 AM

Cursor Movement

h move left (backspace)

j move down

k move up

l move right (spacebar)

[return] move to the beginning of the next line

$ last column on the current line

0 move cursor to the first column on the
current line

^ move cursor to first nonblank column on the
current line

w move to the beginning of the next word or
punctuation mark

W move past the next space

b move to the beginning of the previous word
or punctuation mark

B move to the beginning of the previous word,
ignores punctuation

e end of next word or punctuation mark

E end of next word, ignoring punctuation

H move cursor to the top of the screen

M move cursor to the middle of the screen

L move cursor to the bottom of the screen




Screen Movement

G move to the last line in the file

xG move to line x

z+ move current line to top of screen

z move current line to the middle of screen

z- move current line to the bottom of screen

^F move forward one screen

^B move backward one line

^D move forward one half screen

^U move backward one half screen

^R redraw screen
( does not work with VT100 type terminals )

^L redraw screen
( does not work with Televideo terminals )




Inserting

r replace character under cursor with next
character typed

R keep replacing character until [esc] is hit

i insert before cursor

a append after cursor

A append at end of line

O open line above cursor and enter append mode




Deleting

x delete character under cursor

dd delete line under cursor

dw delete word under cursor

db delete word before cursor




Copying Code

yy (yank)'copies' line which may then be put by
the p(put) command. Precede with a count for
multiple lines.




Put Command
brings back previous deletion or yank of lines,
words, or characters

P bring back before cursor

p bring back after cursor

jack_ 12-15-2012 06:14 AM

Quote:

Originally Posted by markush (Post 4849766)
Hi,

it depends on what you want to do with the selected text. In vi the commands are always a combination "how many of" + "what" + "do this".
Example 3dw delete up to the third word, 3dd delete three lines.

Please explain what exactly you want to do.

Markus

say i want to copy or cut selected text.

jack_ 12-15-2012 06:21 AM

Quote:

Originally Posted by 1300 (Post 4849767)
Cursor Movement

h move left (backspace)

j move down

k move up

l move right (spacebar)

[return] move to the beginning of the next line

$ last column on the current line

0 move cursor to the first column on the
current line

^ move cursor to first nonblank column on the
current line

w move to the beginning of the next word or
punctuation mark

W move past the next space

b move to the beginning of the previous word
or punctuation mark

B move to the beginning of the previous word,
ignores punctuation

e end of next word or punctuation mark

E end of next word, ignoring punctuation

H move cursor to the top of the screen

M move cursor to the middle of the screen

L move cursor to the bottom of the screen




Screen Movement

G move to the last line in the file

xG move to line x

z+ move current line to top of screen

z move current line to the middle of screen

z- move current line to the bottom of screen

^F move forward one screen

^B move backward one line

^D move forward one half screen

^U move backward one half screen

^R redraw screen
( does not work with VT100 type terminals )

^L redraw screen
( does not work with Televideo terminals )




Inserting

r replace character under cursor with next
character typed

R keep replacing character until [esc] is hit

i insert before cursor

a append after cursor

A append at end of line

O open line above cursor and enter append mode




Deleting

x delete character under cursor

dd delete line under cursor

dw delete word under cursor

db delete word before cursor




Copying Code

yy (yank)'copies' line which may then be put by
the p(put) command. Precede with a count for
multiple lines.




Put Command
brings back previous deletion or yank of lines,
words, or characters

P bring back before cursor

p bring back after cursor

thankz 1300, i know about these but thanks anyway.

i found the way, actually two:
1) press ctrl+v select text yank, cut or whatever.

2) place cursor press ma to set marker move cursor to the end of block press :'a,.y.
but i have a problem with this one it does not work the way i intended to, i mean i can select whole line from start of marker to current line but what if i want to copy it from a character in one to the a specific character in say 10th line?

any ideas?

shivaa 12-15-2012 06:25 AM

Quote:

..say i want to copy or cut selected text.
You can do copy (using yy keystroke) and paste (using p or P), but as far as I know there's no shortcut for cut operation. You'll first need to copy and paste and then go back to the previous record i.e. line, and delete it using dd.

capttawish 12-15-2012 06:30 AM

Quote:

Originally Posted by jack_ (Post 4849775)
but i have a problem with this one it does not work the way i intended to, i mean i can select whole line from start of marker to current line but what if i want to copy it from a character in one to the a specific character in say 10th line?

any ideas?

Try using visual mode by pressing v.

jack_ 12-15-2012 06:33 AM

Quote:

Originally Posted by shivaa (Post 4849777)
You can do copy (using yy keystroke) and paste (using p or P), but as far as I know there's no shortcut for cut operation. You'll first need to copy and paste and then go back to the previous record i.e. line, and delete it using dd.

no need to copy just delete, the deleted text is stored temporarily in a buffer. This buffer can be pasted into the document by using the p command. ;)

jack_ 12-15-2012 06:38 AM

Quote:

Originally Posted by capttawish (Post 4849779)
Try using visual mode by pressing v.

thanks capttawish, i already got these working:
CTRL-v : blockwise-visual
v: character wise-visual
V: linewise-visual

now i was wondering if i can achieve same through markers.

markush 12-15-2012 06:40 AM

You should post the text and tell us which part has to be deleted or copied, then we can tell you the command. The visualmode is only in vim, but you asked for vi. If you really want to learn vi, you should avoid vim-specific commands.

Markus

jack_ 12-15-2012 06:47 AM

Quote:

Originally Posted by markush (Post 4849785)
You should post the text and tell us which part has to be deleted or copied, then we can tell you the command. The visualmode is only in vim, but you asked for vi. If you really want to learn vi, you should avoid vim-specific commands.

Markus

thanks, take this text as an example:
Code:

You should post the text and tell us which part has to be deleted or copied, then we can tell you the command. The visualmode is only in vim, but you asked for vi. If you really want to learn vi, you should avoid vim-specific commands.
and say i want to copy :
Code:

The visualmode is only in vim, but you asked for vi

markush 12-15-2012 06:50 AM

Well, if the cursor is anywhere left from this text, simply )d) which means go to the next sentence, delete the next sentence.

The deleted text is then stored in the buffer and can be pasted with p anywhere.

Markus

jack_ 12-15-2012 06:57 AM

Quote:

Originally Posted by markush (Post 4849789)
Well, if the cursor is anywhere left from this text, simply )d) which means go to the next sentence, delete the next sentence.

The deleted text is then stored in the buffer and can be pasted with p anywhere.

Markus

thanks and if i want to copy :
Code:

The visualmode is only in vim, but you asked for vi. If you really want to learn vi, you should avoid

AnanthaP 12-15-2012 06:57 AM

Without a GUI surrounding vi,

(1) yw or yy to yank a word of line.
(2) Position the cursor where you need to insert it. "p" to place.

OK


All times are GMT -5. The time now is 02:49 AM.