vi editor - interchange two lines


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting vi editor - interchange two lines
# 1  
Old 08-27-2008
Question vi editor - interchange two lines

Hi,

I have a quick question regarding vi editor.Is it possible to interchange two lines in vi editor without using the possibilites of cut-paste,copy paste etc?

Your help is appreciated!

Regards
Dileep
# 2  
Old 08-28-2008
you need to 'map' certain key-stroke to do this

In vi, go into the command mode by keeping the following

:map , ddp

If you position your cursor in that line, by typing the "," (comma) key it will delete the current line and paste it below the current cursor. Basically it swaps the two lines.
# 3  
Old 08-31-2008
Java

Quote:
Originally Posted by chihung
you need to 'map' certain key-stroke to do this

In vi, go into the command mode by keeping the following

:map , ddp

If you position your cursor in that line, by typing the "," (comma) key it will delete the current line and paste it below the current cursor. Basically it swaps the two lines.
Thanks for your reply.But sorry i didn't get you properly.Can you put the logic in steps if you don't mind - for swapping two lines in vi editor.

Regards
Dileep Pattayath
# 4  
Old 08-31-2008
You can just type 'ddp'. dd = delete line, p = paste below. Chihung's method just defines a macro so you can do it with one keypress... which part do you need explaining?
# 5  
Old 09-01-2008
MySQL

Quote:
Originally Posted by chihung
you need to 'map' certain key-stroke to do this

In vi, go into the command mode by keeping the following

:map , ddp

If you position your cursor in that line, by typing the "," (comma) key it will delete the current line and paste it below the current cursor. Basically it swaps the two lines.
Now,I got it.I intrepret the statement you gave in a different way,but finally caught what you had suggested.It's seems great.

Thank you so much!

Regards
Dileep Pattayath
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Vi editor deleting lines with specific pattern

Hi, I need to delete all lines in the file using vi editor which start with word aternqaco. Please assist. aternqaco.__oracle_base='/amdbqa01/app/oracle'#ORACLE_BASE set from environment aternqa.__oracle_base='/amdbqa01/app/oracle'#ORACLE_BASE set from environment... (3 Replies)
Discussion started by: Vishal_dba
3 Replies

2. Shell Programming and Scripting

Insert charactera in 1st position of specific lines using vi editor or sed command

Dear all, i am having text file like below surya rama ranga laxman rajesh reddy i want add string (OK) before a text from line 3 to 5 the result will be surya rama OK ranga OK laxman OK rajesh reddy (1 Reply)
Discussion started by: suryanarayana
1 Replies

3. UNIX for Dummies Questions & Answers

Comment lines in file without vi editor

Legends, Can you please help me in following. I need to comment lines from “/tmp/a.txt” from the line A to line B through the command prompt only. Please use variables not direct values like 2 or 5 It can be done with VI editor but it's not matches with my requirement (: 2,5 s/^/#/g). ... (1 Reply)
Discussion started by: sdosanjh
1 Replies

4. UNIX for Dummies Questions & Answers

Is there a limit in number of lines to be Copy pasted in VI editor ?

In my old shop, we only had AIX machines there (all of version 6.1 ). FTP ports were not open for these AIX machines because of some security thing. So, we can't ftp scripts in ASCII mode. When we wanted to copy huge scripts (shell scripts, sql scripts , ..etc) from our Windows based laptop... (6 Replies)
Discussion started by: kraljic
6 Replies

5. UNIX for Dummies Questions & Answers

to check the latest lines of log in vi editor itself..

Hi Folks, If I open the logs in vi editor but as the logs get update after few seconds and I want to see the latest lines then whats the command to see the latest lines in vi editor itself , lets say I have open a log named abc.log in vi..!! vi abc.log (2 Replies)
Discussion started by: SankalpS
2 Replies

6. UNIX for Dummies Questions & Answers

vi editor prefixes lines with # upon paste

I've been away from Unix and the vi editor for a while, and now I'm using vi (actually vim) in a Cygwin bash shell. When I copy-and-paste code examples (I'm playing with perl now) any time I paste code with lines beginning with the # character, vi inserts a # character at the beginning of every... (2 Replies)
Discussion started by: greenmangroup
2 Replies

7. UNIX for Dummies Questions & Answers

How to put the comments to 50 lines, using vi editor?

Hi All, Please let me know how I can put a comment (e.g // or #) to more than 50 lines using vi editor in a .cpp/.sh file. Thanks in advance. (3 Replies)
Discussion started by: artikulkarni
3 Replies

8. Shell Programming and Scripting

How to interchange the lines

Hi, I want to know that, how to inter change the lines. In the following file two line are there first one is conatin PD next line PY. But i want to first line PY and next line PD. My file structure is like this: TI Electronic Publishing AU Robert PD... (5 Replies)
Discussion started by: shankarao
5 Replies

9. Shell Programming and Scripting

Reading lines within vi editor

Hi All, I need to read line by line from a file(created using vi editor) till end of the file and pass it to my own executables so that it will read first line and execute and then other and so on...Thanks The steps are like this; 1) read first line in file 2) execute the job with first line as... (2 Replies)
Discussion started by: asriva26
2 Replies
Login or Register to Ask a Question