Why can't I save a VI file after entering data?


 
Thread Tools Search this Thread
Special Forums UNIX Desktop Questions & Answers Why can't I save a VI file after entering data?
# 8  
Old 02-09-2010
Hear is how we use it.

How do I use the vi text editor?

The vi text editor has three modes: command mode, input mode, and ex mode.
Command mode

When starting, vi begins in command mode. If you are ever unsure which mode you're in, press Esc to return to command mode. In command mode, you can move around with the arrow keys, or by using the vi movement keys, as follows:
h left j down k upl right
Several vi commands are listed in the table below:
CommandAction Ctrl-bGo back one page Ctrl-fGo forward one page xDelete the character the cursor is on Shift-xDelete the character before the cursor ddDelete the current line Shift-dDelete everything from the cursor to the end of the line uUndelete a line you just deleted Shift-uUndo all changes to the current line Shift-z-zSave your file and exit the vi editor
Note: In command mode, you can type a number before pressing a command key to repeat the command multiple times. For example, to delete eight lines from the cursor position, you could press 8 and then type dd .
Input mode

The input mode lets you insert or append text. To insert text before the cursor's current position, in command mode, press i . Similarly, to append after the cursor, you can type a . Remember that you can't move around with the cursor keys in this mode. When you're done entering text, press Esc to go back to command mode.
Ex mode

The ex mode is an extension of command mode. To get into it, press Esc and then : (the colon). The cursor will go to the bottom of the screen at a colon prompt. Write your file by entering :w and quit by entering :q . You can combine these to save and exit by entering :wq . However, if you're finished with your file, it's generally more convenient to type Shift-z-z from command mode.
For a more thorough list of vi command keys, see A quick reference list of vi editor commands.
SmilieSmilieSmilieSmilie

Hope this works.

Thanks

Hannan Saleemi.
# 9  
Old 02-09-2010
hi here is what I am trying.

Code:
chinnanji@ubuntu:~$ mkdir newfolder
chinnanji@ubuntu:~$ cd newfolder
chinnanji@ubuntu:~/newfolder$ mkdir folder2
chinnanji@ubuntu:~/newfolder$ cd folder2
chinnanji@ubuntu:~/newfolder/folder2$ touch file1 file2
chinnanji@ubuntu:~/newfolder/folder2$ ls
file1  file2
chinnanji@ubuntu:~/newfolder/folder2$ cd ..
chinnanji@ubuntu:~/newfolder$ cd ..

chinnanji@ubuntu:~$ cp /folder2/file2 /newfolder/file1
cp: cannot stat `/folder2/file2': No such file or directory

chinnanji@ubuntu:~$ cp /folder2/file2 /newfolder/
cp: cannot stat `/folder2/file2': No such file or directory

but when I tried to do it with out any slashes... it created a newfolder again.

please correct me

---------- Post updated at 11:35 AM ---------- Previous update was at 11:26 AM ----------

Hi Hannan,

Thanks for the handy list of commands. Till now I used to think that we have only two modes... command mode and text editor mode. the extension mode is interesting. thanks again

Last edited by pludi; 02-09-2010 at 12:27 PM.. Reason: code tags, please...
# 10  
Old 02-09-2010
By putting the / at the beginning of the copy command, you are saying that the file is in a directory at the very top of the file system hierarchy. If you leave the leading slash off the cp command then the file(s) will be located relative to the current directory.
You should also change the permissions on directories that you have created so that you do not need to use the root account to write files.
# 11  
Old 02-09-2010
Hi thanks for the explaination. sorry to ask again.

how to change the permissions on directories that are being created.
# 12  
Old 02-09-2010
use 'chmod' to change the permissions.

At this stage, use

Code:
chmod 0666 datafile

for documents and text files

and

Code:
chmod 0777 script


for scripts and programs that you need to execute, and for new directories.

These allow everyone all permissions, but I am assuming that you are the only user.
# 13  
Old 02-09-2010
You should only do things as the root user when you have to, so no do not use sudo all the time.

Last edited by TonyFullerMalv; 02-09-2010 at 06:38 PM..
# 14  
Old 02-10-2010
@jgt
yes I am the only user in my system. your suggestions worked out it is like a magic to me being novice

@tony
thanks and plz tell me what will be the root default password cos' I set password only to my user account created while installation.

cant my user account be the admin account in UBUNTU (Linux)? As in Windows can I give all admin privilages to my existing user account?

plz dont get annoyed if I am being dumb.

---------- Post updated 02-10-10 at 12:30 PM ---------- Previous update was 02-09-10 at 07:11 PM ----------

I read that I can give default settings to have line numbers by default if we edit .exrc file

I opened a file with vi.

this is what I have done. cos' I dont know where the particular file is present.

vi *.exrc

this opened vi editor

I added these lines

% cd
% echo 'set number' >> .exrc
%

:wq!

I opened another file now but it is not showing the line numbers.

where I was wrong?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Get a data and save

If I have a A.log 1 Air Flow Monitor : 34.070 Degrees C 2 Air Flow Monitor : 41.730 Degrees C 3 Air Flow Monitor : 35.340 Degrees C 4 Air Flow Monitor : 33.370 Degrees C 5 Air Flow Monitor : 36.770 Degrees C 6 Air Flow Monitor : 45.910 Degrees C 7 Air Flow Monitor ... (1 Reply)
Discussion started by: sabercats
1 Replies

2. UNIX for Advanced & Expert Users

How to save a data of a file into a variable?

My requirement is to read a column data from a file & save it in a variable for each row & process it. I am using the below code- Leadlines="$TGTFILE/Error.txt">>$log_file while read line do id = ` echo $line | cut -d "," -f1 ` email = ` echo $line | cut -d "," -f2 ` ----------- done My... (2 Replies)
Discussion started by: saga20
2 Replies

3. Shell Programming and Scripting

Open Text file input data and save it.

Hi Guys, I have blank file A.txt I will run the script xyz.sh First i want to open a.txt file... Now i will enter some data like XYZ ABC PQR .. Save it and keep continue my script.... END of my script. Thanks (1 Reply)
Discussion started by: asavaliya
1 Replies

4. Shell Programming and Scripting

Get Permissions and save to data

Hi all; I have the following code which gives me kind of what I need: #!/usr/bin/perl use Fcntl ':mode'; # if ($ARGV ne "") { $filename = $ARGV; } else { print "Please specify a file!\n"; exit; } # if... (2 Replies)
Discussion started by: gvolpini
2 Replies

5. Solaris

Login delay after entering id (40 secs) same after entering pw

Hi all, I have just installed Solaris 10 on an old Fujitsu Primepower 650 which has been wiped clean. I haven't installed anything apart from the OS yet, so the machine is 99% idle. I get long delays when logging in, first after entering the id then another long delay after entering a valid... (8 Replies)
Discussion started by: longjon
8 Replies

6. Shell Programming and Scripting

How to add data from 2 input files and save it in 1 output file

Hi, i have 2 input files which are file1.txt and file2.txt. I need to extract data from file1.txt and file2.txt and save it in file3.txt like example below:- File1.txt ID scrap1 Name scrap1 start 1 end 10 ID scrap2 Name scrap2 start 11 end ... (4 Replies)
Discussion started by: redse171
4 Replies

7. Shell Programming and Scripting

perl-data from file save to multidimensional array

i have a file,like 1 3 4 5 6 7 8 9 i want to save it into an array. and then i want to get every element, because i want to use them to calculate. for example: i want to calculate 1 + 3. but i cannot reach my goal. open (FILE, "<", "number"); my @arr; while (<FILE>){ chomp;... (1 Reply)
Discussion started by: pp-zz
1 Replies

8. Shell Programming and Scripting

select data from oracle table and save the output as csv file

Hi I need to execute a select statement in a solaris environment with oracle database. The select statement returns number of rows of data. I need the data to be inserted into a CSV file with proper format. For that we normally use "You have to select all your columns as one big string,... (2 Replies)
Discussion started by: rdhanek
2 Replies

9. Shell Programming and Scripting

Data fetched from text file and save in a csv file

Hi i have wriiten a script which fetches the data from text file, and saves in the output in a text file itself, but i want that the output should save in different columns. I have the output like: For Channel:response_time__24.txt 1547 data points 0.339 0.299 0.448 0.581 7.380 ... (1 Reply)
Discussion started by: rohitkalia
1 Replies

10. Filesystems, Disks and Memory

Can ZFS Save my Data

Hello, Our RAID and server recently crashed and we are trying to recover our data. The problem appears to be that the Veritas File System/Logical Volume Manger became corrupt on our RAID. We are down to our last option, which is to run some Veritas commands that "may" result in data loss. ... (1 Reply)
Discussion started by: stringman
1 Replies
Login or Register to Ask a Question