Jump to content
xisto Community
kanade

Linux Beginners - Tutorial On Editors In Linux.

Recommended Posts

This is a simple tutorial on the editors in Linux.

 

I use these 3 editors for programming on linux:

1. vi -- available in all Linux and unix box, used to edit

2. vim -- not in all Linux flavors and it has got default coloring of key words feature, used to edit

3. view --Its used only to view, recommended to use for viewing of system config files, as it should not get edited without your notice.

 

Following are the basic commands comes handy with these editors

 

#Open a file for edit

$ vi test -- creates a file if file is not exist in the current directory

$ vim test.cpp -- key words will be in different colors

 

#Start editing the file

To edit the file press ‘i’ key , then you write your program

 

#To save the file and exit

After you finished editing the file press “ Esc ctrl+z ” to save file and exit.

Press “Esc ctrl+q!” to exit the file without saving the file.

 

# To search the word inside a file using Vi or vim

Once you’re inside the file using this command

$vi test

If you want to search word say “sample” inside your file, use this command

Press “Esc /sample” Note: sample is the word to search

To go to next word press “n” to go from top-to-bottom search

To go to next word press “shift n” or “N” to go from bottom-to-top search

 

# To search and replace the word inside a file using Vi or vim

I am going to give you only the useful commands to do this.

Command is to search word “sample” from top to bottom and replace with “hello” based on your confirmation[y/n].

Press “Esc” then type “ :g/sample/s//hello/gc ”

 

The command you typed just now will display bottom left of your screen.

 

This will keep on replacing “sample” with “hello” based on your

Confirmation[y/n].

 

# To delet the line inside a file using vi or vim

Press “Esc dd” to delete the current line (cursor pointing to).

Press “Esc 2dd” to delete 2 lines from the current line (cursor pointing to).

 

# To cut the line and paste it in some other place inside a file using vi or vim

Press “Esc dd” to cut the current line (cursor pointing to) and move your cursor to the point where you want to paste then press “p” to paste the line.

 

# To copy the line and paste it in some other place inside a file using vi or vim

Press “Esc yy” to copy the line (cursor pointing to) and move your cursor to the point where you want to paste then press “p” to paste the line.

Press “Esc 2yy” to copy two line (cursor pointing to) and move your cursor to the point where you want to paste then press “p” to paste the line.

 

These are the basic some of the commands mainly used to work with vi or vim.

 

For today this is sufficient, I will add some more based on your feedback.

Share this post


Link to post
Share on other sites

Nice tuto, thanks. All these vi commands are of course quite obvious for most of us, the other people simply type "man vi" in a console window, but you are right, we should think about our beginners.I would just like to add a little comment. Here you are writing a tutorial, which is supposed to be read by a lot of people. Just for politeness and for sake of this tutorial forum section, you should pay special attention to grammar and claritiness. For instance you write "$ vi test -- creates a file if file is not exist in the current directory"I guess that you meant "creates a file if a file with this name does not exist".Moreover, "in the current directory is false" because we often issue "vi /etc/hosts", i.e. we edit files with absolute path, so the words "in the same directory" is false, should be "a file with the same full path name" or simple remove the "in the current directory" words.RegardsYordan

Share this post


Link to post
Share on other sites

Many people don't like vi (or vim) because it isn't "like" more modern screen-oriented editors. However, if you are going to make much use of Linux, vi is the one editor that is always there! For example, the Avira rescue CD is a Live-CD linux distribution with a built-in virus checker, in less than 60 MB. For a Linux distribution, that is very small, but it includes vi!

The essential things to remember about vi are (1) a few commands will do most basic editing. They are well covered at the start of this thread. (2) It is a keyboard-oriented editor. While many enhanced versions of vi use a mouse, it was designed, and long in development before mice became widely available. If the Linux disrtro you are using can't find your mouse, you can still use vi! (3) Even though its input emphasis is on the keyboard, not the mouse, its output is screen oriented. In fact that is the reason for its name: vi = VIsual editor. It was one of the first Linux (and Unix) editors that could do screen-oriented (visual) editing instead of line-oriented (text) editing. Actually, it can do both, though very few people now make much use of just its text commands.

If you're serious about Linux, take a little time, and learn the essential vi commands. You never know when you'll really need them! :mellow:

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.