LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-15-2012, 05:05 AM   #1
jack_
Member
 
Registered: Oct 2012
Location: /
Distribution: Slackware, Debian, Ubuntu, CentOS, OpenSuse
Posts: 35

Rep: Reputation: Disabled
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
 
Old 12-15-2012, 05:10 AM   #2
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
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.

Last edited by shivaa; 12-15-2012 at 06:21 AM. Reason: Adding info.
 
Old 12-15-2012, 05:43 AM   #3
markush
Senior Member
 
Registered: Apr 2007
Location: Germany
Distribution: Slackware
Posts: 3,979

Rep: Reputation: Disabled
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

Last edited by markush; 12-15-2012 at 05:43 AM. Reason: typo
 
Old 12-15-2012, 06:01 AM   #4
1300
Member
 
Registered: Nov 2011
Posts: 69

Rep: Reputation: Disabled
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
 
Old 12-15-2012, 06:14 AM   #5
jack_
Member
 
Registered: Oct 2012
Location: /
Distribution: Slackware, Debian, Ubuntu, CentOS, OpenSuse
Posts: 35

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by markush View Post
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.
 
Old 12-15-2012, 06:21 AM   #6
jack_
Member
 
Registered: Oct 2012
Location: /
Distribution: Slackware, Debian, Ubuntu, CentOS, OpenSuse
Posts: 35

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by 1300 View Post
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?

Last edited by jack_; 12-15-2012 at 06:22 AM.
 
Old 12-15-2012, 06:25 AM   #7
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
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.
 
Old 12-15-2012, 06:30 AM   #8
capttawish
LQ Newbie
 
Registered: Dec 2012
Distribution: Ubuntu 12.04 LTS
Posts: 2

Rep: Reputation: Disabled
Quote:
Originally Posted by jack_ View Post
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.
 
Old 12-15-2012, 06:33 AM   #9
jack_
Member
 
Registered: Oct 2012
Location: /
Distribution: Slackware, Debian, Ubuntu, CentOS, OpenSuse
Posts: 35

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by shivaa View Post
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.
 
Old 12-15-2012, 06:38 AM   #10
jack_
Member
 
Registered: Oct 2012
Location: /
Distribution: Slackware, Debian, Ubuntu, CentOS, OpenSuse
Posts: 35

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by capttawish View Post
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.
 
Old 12-15-2012, 06:40 AM   #11
markush
Senior Member
 
Registered: Apr 2007
Location: Germany
Distribution: Slackware
Posts: 3,979

Rep: Reputation: Disabled
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
 
1 members found this post helpful.
Old 12-15-2012, 06:47 AM   #12
jack_
Member
 
Registered: Oct 2012
Location: /
Distribution: Slackware, Debian, Ubuntu, CentOS, OpenSuse
Posts: 35

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by markush View Post
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
 
Old 12-15-2012, 06:50 AM   #13
markush
Senior Member
 
Registered: Apr 2007
Location: Germany
Distribution: Slackware
Posts: 3,979

Rep: Reputation: Disabled
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
 
1 members found this post helpful.
Old 12-15-2012, 06:57 AM   #14
jack_
Member
 
Registered: Oct 2012
Location: /
Distribution: Slackware, Debian, Ubuntu, CentOS, OpenSuse
Posts: 35

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by markush View Post
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
 
Old 12-15-2012, 06:57 AM   #15
AnanthaP
Member
 
Registered: Jul 2004
Location: Chennai, India
Posts: 952

Rep: Reputation: 217Reputation: 217Reputation: 217
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
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:31 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration