Operating System - HP-UX
1753969 Members
7287 Online
108811 Solutions
New Discussion юеВ

Re: Some Tips & Tricks for "VI Editor"

 
SOLVED
Go to solution
Martin Johnson
Honored Contributor

Re: Some Tips & Tricks for "VI Editor"

:.= show current line number
:= 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
Jeanine Kone
Trusted Contributor

Re: Some Tips & Tricks for "VI Editor"

I like to use:

: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.
BKUMAR
Frequent Advisor

Re: Some Tips & Tricks for "VI Editor"

Hi

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

Unix Administration Most Dedicated and Challenging Career in the World
Tony Romero
Advisor

Re: Some Tips & Tricks for "VI Editor"

Use the following to convert alpha chars from lower to upper case.

sed '1,3y/abcde/ABCDE/' filename

Freedom!!!
John Dvorchak
Honored Contributor

Re: Some Tips & Tricks for "VI Editor"

A very simple one that I seem to use every session is move to the 1st line in the file:

/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.

If it has wheels or a skirt, you can't afford it.
harry d brown jr
Honored Contributor

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
Live Free or Die
kish_1
Valued Contributor

Re: Some Tips & Tricks for "VI Editor"

1.if you want interchange the letter when you make mistake while typeing
Ans: xp

2. if you want opn a last line of file

Ans: vi + /var/adm/syslog/syslog.log

share the power of the knowledge
Robert Sipe
Occasional Advisor

Re: Some Tips & Tricks for "VI Editor"

with regards to search and replace

:%s/old/new/gc

Where the g is global and the c is confirm before commit.
None
Robert Sipe
Occasional Advisor

Re: Some Tips & Tricks for "VI Editor"

if you need to include a calendar into your vi session

:! /usr/bin/cal [arg]

of course that will work with any shell command.
None
Ralph Grothe
Honored Contributor

Re: Some Tips & Tricks for "VI Editor"

Hi,

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.
Madness, thy name is system administration