HPE Community read-only access December 15, 2018
This is a maintenance upgrade. You will be able to read articles and posts, but not post or reply.
Hours:
Dec 15, 4:00 am to 10:00 am UTC
Dec 14, 10:00 pm CST to Dec 15, 4:00 am CST
Dec 14, 8:00 pm PST to Dec 15, 2:00 am PST
cancel
Showing results for 
Search instead for 
Did you mean: 

Manipulations with files

 
SOLVED
Go to solution
rustam_2
Super Advisor

Manipulations with files

Hi everybody.
I would like to find out some trip of manipulations with files. Manipulations with files. Sometimes i run vi after browsing content type :q! . It's ok, but not for all the time.Why? How should i close file?
I also use ctrl+i for edit, dd- for delete, p -for cancel, a for staying in end of line.
For now, i have to close my file without savings.After that have to add some strings. How should i do?

Regards,
Rustam.
16 REPLIES
R.K. #
Honored Contributor
Solution

Re: Manipulations with files

Hi Rustom,

I have attached a file with some commands used in vi editor.

Don't fix what ain't broke
R.K. #
Honored Contributor

Re: Manipulations with files

Hi Rustam,

Another small attachment for vi tips.
Don't fix what ain't broke
Kapil Jha
Honored Contributor

Re: Manipulations with files

http://www.eng.hawaii.edu/Tutor/vi.html

This is good, just try to these command in a test file and you would have some idea about it.

BR,
Kapil+
I am in this small bowl, I wane see the real world......

Re: Manipulations with files

>i run vi after browsing content type ":q!". It's ok, but not for all the time. Why? How should i close file?

:q! says delete all changes.
If you want to keep them: :wq
Or just ZZ.
You can use view vs vi if you don't intend to make changes.
Michal Kapalka (mikap)
Honored Contributor

Re: Manipulations with files

hi,

i think this is a very goof docu directly from HP :

http://www.hp.com/education/courses/vi.pdf

mikap
rustam_2
Super Advisor

Re: Manipulations with files

Thanks for everybody for links. I read a lot of useful information from there.And now can manipulate file :).
I have some question, i didnt get some issues.

1. I'd prefer command mode , i liked it. Sometimes i need to type Esc for running command( which has 1/2 character long). Why? Maybe i do something wrong? For instance: i typed 'yy'->'p' then 'd', after that i would liked to leave without saving :q!. But i didn't be in VI's command mode. why commands don't run step by step, i mean sometimes i have to remind to VI and type Esc?
2. I didn't get, what's EX Editor.
3. Have i to configure :set 'Settings for VI'
4. Now i know what is Abbreviations and how to use, but still don't know 'Mapping Keys to Other Keys'.
5. Should i configure - 'The EXINIT Environment Variable and the .exrc file'
6. About recovering. For instance, if while i editing file, server got some problem or connection was lost. In this case i must recovery file? vi -r those_file

Hi Kapil+, i couldnt open article which you offered me. Could you send me again or that's file.

Regards,
Rustam.
OldSchool
Honored Contributor

Re: Manipulations with files

"1. I'd prefer command mode , i liked it....."

I'm not sure what you mean by the above....


".... Sometimes i need to type Esc for running command( which has 1/2 character long). Why? Maybe i do something wrong? For instance: i typed 'yy'->'p' then 'd', after that i would liked to leave without saving :q!. But i didn't be in VI's command mode. why commands don't run step by step, i mean sometimes i have to remind to VI and type Esc?

The esc is required to switch from input/change mode to the command "prompt". it is what it is, and from your description, it appears to be working normally.



"2. I didn't get, what's EX Editor."

"vi" is the "visual" editor. ex is the line editor, and vi sort of builds on top of it. the closest analogy i can come up with is that ex is to vi as wordstar (dot commands) is to word???



"3. Have i to configure :set 'Settings for VI'"

there are a lot of variables that can be set in vi to change behaviour and presentation of the file / input. settings are optional...



"4. Now i know what is Abbreviations and how to use, but still don't know 'Mapping Keys to Other Keys'."

???



"5. Should i configure - 'The EXINIT Environment Variable and the .exrc file'"

same as 3 above


"6. About recovering. For instance, if while i editing file, server got some problem or connection was lost. In this case i must recovery file? vi -r those_file"


that should be self explanatory...but the answer is "probably". I've not had an issue where I needed the recovery file in a long time, but as I recall, if you attempt to edit the original file it will tell you the recovery file exists...and what option to use.

======================================================================================

note that Kapil's link worked without issue for me, so you might try "cut-and-pasting" the link into your browser.

Also, you really need to read, and understand, the docs, as this isn't really a teaching forum, so much as a troubleshooting forum.

rustam_2
Super Advisor

Re: Manipulations with files

Thanks, OldSchool.
first, sorry for my english. English is not native language, and in our country ppl rarely use english. I'm learning by reading english books, i know my english is still awful.
1. i got. I was wrong.
2,3,4 - i solved after reading docs.
5 and 6. thanks, i got.

yeah, i checked Kapil+ 's link, works.Thanks.


By the way, i use FAR for Windows machines. Could i install and run FAR or mc on HP-UX?
Bill Hassell
Honored Contributor

Re: Manipulations with files

To best understand vi, get the "Ultimate Guide to vi" This book is the best reference for vi and will explain how vi is layered on top of ex. There are also man pages for both vi and ex although man pages are generally poor training documents:

man vi
man ex

Note that Amazon.com sells the book new for almost $60 USD but there are a *lot* of used copies for less than $10 USD: http://www.amazon.com/gp/offer-listing/0805344608/ref=dp_olp_used?ie=UTF8&condition=used

> By the way, i use FAR for Windows machines. Could i install and run FAR or mc on HP-UX?

It appears that FAR is PC-only. http://www.helpware.net/FAR/. If "mc" means Midnight Commander, then PCs and Linux. Source code is available for GNU MC: http://www.midnight-commander.org/ but you'll need a compiler and some development skills.

HP-UX is not PC Windows and while you can hide some of the details with add-on programs, it is best to learn each new operating system and the built-in tools. vi is standard on every Unix system and there's not much you can do without vi.


Bill Hassell, sysadmin
rustam_2
Super Advisor

Re: Manipulations with files

Thanks a lot Bill Hassell for advices.
First, yeah, i know the best way is to read a book.But i can't order through amazon. i can afford 1,2 or 3..$.it's not much but issues is to order from Europe or US. I'm not from Europe or America, our country is too small and impossible to order things like this. We have book-shops, but there are not any books in english moreover HP-UX which is specific OS.
ok,i'm quite agree.i like learn new things, so ready to use vi without mc.I try to do my best.
Regards,
Rustam
Bill Hassell
Honored Contributor

Re: Manipulations with files

One of the best features of the Internet is the wide availability of help and documentation. Here are 3 of the best sites to learn vi:

http://docstore.mik.ua/orelly/unix/vi/

This is the O'Reilly book online. It is a fairly typical textbook and best used by reading a chapter at a time, then practicing on test files.

http://www.gentoo.org/doc/en/vi-guide.xml

This document is great as it is a cheatsheet, or a document with the most useful commands (in vi, a command is a single character). I especially like the handwritten notes which start small and then add on more commands as you learn more.

http://thomer.com/vi/vi.html

This is the vi lovers page. Not so much of a learning guide as it is a collection of vi references. Note that it does have a lot of comments about vim (which is: VI iMproved). However, vim is not standard with most Unix installs and must be downloaded and installed.


Bill Hassell, sysadmin
R.K. #
Honored Contributor

Re: Manipulations with files

Hi Rustam,

You can download a vi editor here:

http://portablegvim.sourceforge.net/downloads.html

Good thing is....IT IS INSTALLED ON WINDOWS ....so you can practice it endlessly without using any server.
Hands-on is always better.

Regds..
Don't fix what ain't broke
rustam_2
Super Advisor

Re: Manipulations with files

Thanks a lot to both of you, Bill Hassell and
R.K. #.
Last week i installed GVimPortable on my pc and by reading articles and e-books which you gave me, have done a lot of practices.
Now i know such as commands:
movement, open, save+quite, windowing,insert mode, edit commands, compound, cut and paste, search.
I think for it's enough for now, coz i must start to learn OS HP-UX's commands as vi command, if i knew HP-UX's basic command as i know vi's command it would be fine.
I didn't get 2 things, could you explain them?
1. I checked my vi's :set options, there are a lot options. Did these parameters made after installing OS or they are default ones? I mean this, coz OS were installed by HPâ s specialist and i don't know did he configure vi or vi has default parameters now. Maybe in the future, I will need to reinstall OS, I'm curious after reinstalling should I install vi and configure or I will get such I have now. Should I change VI to VIM or shouldn't yet?
2. Maybe because of English is not my native language I cant get purpose of autoindentation. How and what should I use for?

R.K. #
Honored Contributor

Re: Manipulations with files

Hi Rustam,

>>I checked my vi's :set options, there are a lot options. Did these parameters made after installing OS or they are default ones?
These options are inbuilt. I think vi would serve whatever you require. So there should not be any need to go for vim

>>I cant get purpose of autoindentation.
Using auto-indent
For writing code in various programming languages, indentation is an important part of style. vi can be set up for automatic indenting. If auto-indent is enabled and vi is in insert mode, then when you start a new line it has the same amount of indentation as the previous line. If you want to use auto-indent you need to get into command mode (hit the escape key) and

* enable auto-indent with :set ai sw=4

See below link fo rmore info:
http://www.d.umn.edu/~gshute/vi/vi.html


Don't fix what ain't broke
Bill Hassell
Honored Contributor

Re: Manipulations with files

> 1. I checked my vi's :set options, there are a lot options...

As mentioned before, vi has many parameters that are preset and without a file $HOME/.exrc, then the :set command shows you these settings. There are two ways to set the options to different values:

1. use the :set command as in :set ignorecase
or
2. create a .exrc file in your $HOME directory. There is an example .exrc file in /usr/newconfig/etc/skel/.exrc but for the options, only the first line starting with set is useful. The rest of the lines are specific to HP terminals and emulators.

A good starting .exrc file would be:

set noautoindent nowrapscan autowrite ignorecase wrapmargin=0

The word: 'no' in front of an option turns off the feature. wrapscan is very useful because vi searches (the / or the ?) will wrap around bottom to top without warning. Setting wrapscan will stop the search at the end of the file. autowrite will write the current changes to the file if you run an external command. ignorecase means that vi will search for UPPER and lower case characters equally (ABC=abc=aBc) and wrapmargin will automatically add a newline if you reach the right margin. Note that wm=70 does not mean wrap at column 70 -- it means wrap at 70 characters to the left of the end of the line. wrapmargin=10 will insert a new line when you reach 10 characters before the right margin.

Note that most of the set options can be abbreviated like this:

set noai nows aw ic wm=0

Here is one of many quick references to vi commands and set options:

http://people.cis.ksu.edu/~bhoward/vi/vi60.html

> Should I change VI to VIM or shouldn't yet?

I would not use vim because it won't be found on many systems and if you get familiar with all the vim features that are not in vi, you'll have difficulties on those other systems.

> purpose of autoindentation. How and what should I use for?

AS mentioned above, indentation is part of good programming style. It shows sections of code that belong together. You would type extra spaces at the beginning of each line to line up the code. After a while, typing all those spaces in front of many lines becomes tedious. So autoindent (automatic indentation) inserts the additional spaces automatically. Here is an example of indentation:

line1
line2
line3
line4
line5
line6
line7

To move back to the beginning of a new line, use the command: CTRL-D (the control key plus the letter d). CTRL-D will backspace one tab space to the left. Press it several times and you'll be back to column where you can start typing.


Bill Hassell, sysadmin
rustam_2
Super Advisor

Re: Manipulations with files

Thanks a lot for both of you. I'm appreciate it and very happy, now i'm glad that can do some manipulation with files(especially with database config files, which are i'm configure these days ).

Regards,
Rustam.