- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Some Tips & Tricks for "VI Editor"
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2002 11:36 PM
06-30-2002 11:36 PM
Please give some tips, to work better and smart with VI editor.
Anything related to vi, from setting up terminal for vi editor to editing multiple files etc
Thanks in Adv
Regards
Shah
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2002 11:46 PM
06-30-2002 11:46 PM
Re: Some Tips & Tricks for "VI Editor"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2002 12:36 AM
07-01-2002 12:36 AM
SolutionSay you want to change in a file the string joe to fred.
From command mode:
:1,$s/joe/fred/g
To insert a string at the beginning
of the line
:1,$s/^/insert/g
If you wanted to do this at the end
of the line replace the '^' with a
'$'
If you wished to change multiple files
it might be best to use 'sed'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2002 12:43 AM
07-01-2002 12:43 AM
Re: Some Tips & Tricks for "VI Editor"
Search anad replace
/text - search forward direction starting from curretn location
?text search text backward
/ repeat previous search in forward dir
? repeat previous searcn backward dir
n repeat search in same dir
N repeat search in opposite dir
:s/old/new search old and replace with new
:m,ns/old/new/g search old from line m and replace it to line n with new
:s/old/new/g search old in entire file and replace with new
/
/^text search text at the beginning of a line
/text$ text at the end of a line
/(more than one word) - use parenthesis to search for more than one word
Exporting text from a current file
If you have opened file1 in the editor and want to save lines 3 to 47 as file3, use the command :3,47w file3
to save the opened file as a new file :w filename
to open multiple files
vi file1 file2 file3
vi options are configured in $HOME/.exrc
to set line number , enter in .exrc
set nu
set showmode
to show current mode
Theres loads more
Steve
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2002 12:44 AM
07-01-2002 12:44 AM
Re: Some Tips & Tricks for "VI Editor"
http://www.math.fu-berlin.de/~guckes/sed/
To really learn some powerful text editing and programming you may also want to look at perl.
Start here:
http://www.perl.org/
http://www.cpan.org
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2002 12:44 AM
07-01-2002 12:44 AM
Re: Some Tips & Tricks for "VI Editor"
I have attached a whole load of sed examples
Steve
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2002 12:46 AM
07-01-2002 12:46 AM
Re: Some Tips & Tricks for "VI Editor"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2002 01:41 AM
07-01-2002 01:41 AM
Re: Some Tips & Tricks for "VI Editor"
:set list
displays non-printable characters (hidden control characters etc). Can be invaluable in debugging a faulty script or data.
-------------------------------------
use J to join append the next line to the end of the current line.
-------------------------------------
Cut and paste file section to new file
At first line, hit
m
where the buffer is a letter
Go to end of section you want to copy, and type
"ay'
You should now see a message telling you that a number of lines have been yanked.
type
:e
to start a new file, then
"ap
to paste the contents of the buffer to the new file.
--------------------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2002 03:21 AM
07-01-2002 03:21 AM
Re: Some Tips & Tricks for "VI Editor"
to view special settings
ie
:set noautoindent
to avoid cut paste problems..
Also get a shell with
:!ksh
exit
(to return to vi)
:!ls /tmp
or any other command to run a command.
Later,
Bill
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2002 06:00 AM
07-01-2002 06:00 AM
Re: Some Tips & Tricks for "VI Editor"
For on-line versions, see <>.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2002 06:03 AM
07-01-2002 06:03 AM
Re: Some Tips & Tricks for "VI Editor"
:= show how many lines in the file.
HP has a book "The Ultimate guide to the VI and EX Text Editors" that will tell you everything you ever want to know about vi.
HTH
Marty
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2002 06:05 AM
07-01-2002 06:05 AM
Re: Some Tips & Tricks for "VI Editor"
:r filename
to insert the contents of the specified file into the current file you are editing. I use this alot to add headers and standard env setups to my scripts.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2002 12:42 PM
07-01-2002 12:42 PM
Re: Some Tips & Tricks for "VI Editor"
VVVV IMP to open a large files
[
vi
:set dir=/
:e
]
so that you have to set the largefilesystem with enough space of your largefile....so vi default searches for /var/tmp....if it doesnt have enought space of your largefile....
it wont open it completely and if you save it accidentally....it will be a problem
take care
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2002 01:21 PM
07-01-2002 01:21 PM
Re: Some Tips & Tricks for "VI Editor"
sed '1,3y/abcde/ABCDE/' filename
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2002 01:44 PM
07-01-2002 01:44 PM
Re: Some Tips & Tricks for "VI Editor"
/1G
Last line in the file:
/G
Search for a string or number etc..:
/keyword_that_you_want_to_search_for
n (to repeat the last find forward)
N (to repeat the last find backward)
Take me to the end of the line and put me in insert mode so I can add text:
A
All of the responses were great but I find that these are the most used, plus search and replace already given to you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2002 05:19 PM
07-01-2002 05:19 PM
Re: Some Tips & Tricks for "VI Editor"
http://www.talug.org/minutes/19990310/lesson/lesson.html
http://computips.virtualave.net/tips/vi_commands.html
http://www.roxanne.org/vi.html
How many of us have done this:
ls -l /somedir > /tmp/dirlst.txt
then
vi /tmp/dirlst.txt
when we could have done this
vi /tmp/dirlst.txt
!!ls -l /somedir
live free or die
harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2002 07:16 PM
07-01-2002 07:16 PM
Re: Some Tips & Tricks for "VI Editor"
Ans: xp
2. if you want opn a last line of file
Ans: vi + /var/adm/syslog/syslog.log
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2002 07:47 PM
07-01-2002 07:47 PM
Re: Some Tips & Tricks for "VI Editor"
:%s/old/new/gc
Where the g is global and the c is confirm before commit.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2002 08:09 PM
07-01-2002 08:09 PM
Re: Some Tips & Tricks for "VI Editor"
:! /usr/bin/cal [arg]
of course that will work with any shell command.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2002 11:48 PM
07-01-2002 11:48 PM
Re: Some Tips & Tricks for "VI Editor"
I guess one could fill a whole book with cute little vi tricks.
Here are some things I appreceate with vi.
Maybe they have already been addressed?
Shell escapes are a really nice feature (but sometimes dreaded by paranoid sysadmins ;-)
You have already seen the bang of the ex commands
:! ll /var/adm
But what I think has been missed is the combination with ex's read command.
How about dumping the output of a command in your current vi buffer?
:r! ll /var/adm
This come really handy to me, when I am too lazy to type endless paths to commands that usually don't reside under /usr/bin
:r! which perl
Then you can escape to the shell without leaving your vi session when you have several commands to issue
:sh
After your commands type exit to get back to your vi session.
Have you already discovered the power of mappings?
Edit your .exrc file, and insert a mapping like this:
(This is to insert a standard Perl header when pressing the F1 key)
map ^[[001q :r!which perl^M^[I#!^[A -w^M^Muse strict;^M^M
You get the control characters when you typ Ctrl+v (or C^V) together, which quotes the next key.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-02-2002 04:38 AM
07-02-2002 04:38 AM
Re: Some Tips & Tricks for "VI Editor"
1. grep -il "billy" > list
2. vi list. Add vi to the front, and "\" to the end of each line.
3. sh list (this edits all the files).
:n to go to the next file
:rew to rewind to the begining of the list
/billy -to search for the from string.
cw bob -to change billy to bob
. to repeat last command (usually the command
that changes "billy" to "bob").
Another useful tip for editing multiple files.
"a23yy Copies 23 lines into a thingy called a.
"ap Pastes the contents of "a" to your current spot in the file.
You can use the rest of the alphabit too.
This allows you to copy the contents of one file, and drop it into files interactively.
Here's an example of how it works.
what to type <-- comments
vi file1 file2 <--edit to big text files.
25G <--go to line 25
"a8yy <-- get 8 lines from file1 at line25
2G <--go to line 2
"b12yy <-- get 12 lines from file1 at line2
:n <--go to file2
40G <-- go to line 40 in file2
"bp <-- paste 12 lines in buffer b to file2
"ap <-- paste 8 lines from buffer a to file2.
3G <-- go to line 3 in file2
"c23yy <-- get 23 lines from file2
:w <-- save the change to file2
:rew <-- go back to file1
100G <-- go to line 100 in file1
"cp <-- paste 23 lines from buffer c to file1
:wq! <-- get out and save the change to file1.
A third tip for people that hate vi.
Use a windows terminal emulator with cut and paste, and windows notepad.
hope this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-02-2002 05:26 AM
07-02-2002 05:26 AM
Re: Some Tips & Tricks for "VI Editor"
To get a banner into your file at the current location:
:.!banner MyBanner
To format a paragraph with word wrap, place the cursor somewhere on the first line of the paragraph (the paragraph must end with a blank line), then:
!}exec adjust -m72
(just type it as shown--the cursor will jump to the bottom of the page but when you press Return, the paragraph will be word wrapped up to column 72) As always, type: u to undo the last change.
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-03-2002 01:44 AM
07-03-2002 01:44 AM
Re: Some Tips & Tricks for "VI Editor"
Excellent tips.
One Q please
What can be done with $HOME/.exrc file?
Regards
Shah
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-03-2002 02:24 AM
07-03-2002 02:24 AM
Re: Some Tips & Tricks for "VI Editor"
The $HOME/.exrc file is basically a config file for your own vi sessions
let me expand
Each option can be set in vi with the :set option - where the word option is replaced with some valid option name.
Here a some of these options
:set number - set line number in front of each line
:set all - List all options
:set autoindent - The next line is indented the same number of character as the current line
:set readonly - sets the current file as readonly
:set wrapmargin=n - sets the wrap margin equal to 'n' ie . If you are using 80 cloumn margin and the wrap margin is set to 6, every line will be wrapped to the next line after 74 chras
:set showmode - shows the user which mode they are currently in , ie 'insert' 'replace' etc
So to make these options permanent you simply create the $HOME/.exrc file and add them to that file. You can use shorter versions for each option
se nu (for set number)
se ai (for autoindent)
se sh (for showmode)
Hope this helps
Steve
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-03-2002 04:41 AM
07-03-2002 04:41 AM
Re: Some Tips & Tricks for "VI Editor"
If you ever need to clear and redraw the screen use:
ctrl+l or ctrl+r
To display a status line on the bottom of the screen:
ctrl+g or :f
Thanks for participating in the forums,
Martin
Chaos reigns within. Reflect, repent, and reboot. Order shall return.