Using VIM Text Editor


10 posts
by bubbl » Sat Dec 28, 2013 2:25 pm
Text editors are programs used to create or edit files. One of the most popular editors on Linux/Unix systems (also available for other platforms) is vim. Though it does take some time getting use to, this easy to follow HowTo will walk you through the essentials of using vim.

Starting the vim text editor

The command to start the vim editor is simply
Code: Select all
vim

followed by the filename. For example, to edit a file named test, you would type
Code: Select all
vim test

and hit [Return].
New files will be empty, as with every new file in any editor. When creating a new file, you will see a screen filled with tilde characters (~) down the left side of the screen. Those represent blank lines beyond the end of file. At the bottom of your screen, the file name will be shown, along with a line and character count.

To read more, head to Using VIM Text Editor
We're not here because we are free. We're here because we are not free. There is no escaping reason. No denying purpose. Because we both know without purpose, we would not exist.
http://www.bartbania.com/
Posts: 85
Joined: Sun Jul 14, 2013 9:15 pm
Location: United Kingdom
by Richard-TX » Sat Dec 28, 2013 2:31 pm
For those that are wondering why they should learn vi and it's brethren, it really boils down to this:
Not every *nix system has nano, etc. However every *nix system has vi. So if you ever decide to venture into a career in IT, it is best to learn vi now.

My daughter made personalized Valentines cards for her classmates using vi when she was in 7th grade. If she can learn it, so can you.

This may help.
Image
Richard
Doing Unix since 1985.
The 9-25-2013 image of Wheezy can be found at:
http://downloads.raspberrypi.org/raspbian/images/raspbian-2013-09-27/2013-09-25-wheezy-raspbian.zip
User avatar
Posts: 1545
Joined: Tue May 28, 2013 3:24 pm
Location: North Texas
by bubbl » Sat Dec 28, 2013 2:36 pm
Richard-TX wrote:For those that are wondering why they should learn vi and it's brethren, it really boils down to this:
Not every *nix system has nano, etc. However every *nix system has vi. So if you ever decide to venture into a career in IT, it is best to learn vi now.

My daughter made personalized Valentines cards for her classmates using vi when she was in 7th grade. If she can learn it, so can you.

This may help.
Image


nothing more to be added Richard!
and that's a great mug there! where could I get one?
We're not here because we are free. We're here because we are not free. There is no escaping reason. No denying purpose. Because we both know without purpose, we would not exist.
http://www.bartbania.com/
Posts: 85
Joined: Sun Jul 14, 2013 9:15 pm
Location: United Kingdom
by frodo » Sat Dec 28, 2013 5:50 pm
Someone should add that vi and it's children nvi and vim powerful and comfortable tools for people that write, correct or change structured text files a lot.

Passionate FPS players are used to place their left hand at wsad with yxc, qe right next to it. The very same way these players use this trick to move fluently and quickly through the game, vi hackers place their right hand at hjkl to quickly move through text paragraphs. There's even a new trend in software user interface design called "distractionless editing/browsing/etc" to make huge new software application look like plain old vi.
Posts: 63
Joined: Wed Dec 18, 2013 2:36 pm
by DougieLawson » Sun Dec 29, 2013 2:42 am
The only thing I've found with vim is that the default vim.tiny is crap and when I replaced that with the full fat vim it's still got key bindings that are all over the place compared to my Ubuntu system.

The insert key doesn't toggle INSERT mode, then REPLACE mode, then normal mode (and there's no indication of the status)
The arrow keys generate random spurious characters.

I've got the syntax highlighting working now, but I'm still not happy and I don't know enough about vim to lift the definitions from my Ubuntu system.
Microprocessor, Raspberry Pi & Arduino Hacker
Mainframe database troubleshooter
MQTT Evangelist
Twitter: @DougieLawson

Since 2012: 1B*5, 2B*2, B+, A+, Zero*2, 3B*3

Please post ALL technical questions on the forum. Do not send private messages.
User avatar
Posts: 27562
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
by sdjf » Sun Dec 29, 2013 3:04 am
All I know is that the vi that came I think as default in arch on my Pi drove me nuts because I am used to using arrow keys to move around when I am typing in visual mode. I kept ending up with weird characters on my screen, and found out that vim could handle moving around with plain arrow keys just fine, so I changed over to vim.

copy and move are added features that make up for difficulties in my lxterminal with copy/paste. I just have to check the line numbers. And if I goof, there is always "u" for undo.
FORUM TIP: To view just one person's posting history, sign in, click on their user name, then click on "Search User's Posts." || My 512MB Model B only runs Arch.
Posts: 1388
Joined: Fri Mar 16, 2012 5:20 am
Location: California
by Richard-TX » Sun Dec 29, 2013 4:23 am
bubbl wrote:and that's a great mug there! where could I get one?

http://www.amazon.com/vi-Reference-Mug- ... B009YNIBTG
Richard
Doing Unix since 1985.
The 9-25-2013 image of Wheezy can be found at:
http://downloads.raspberrypi.org/raspbian/images/raspbian-2013-09-27/2013-09-25-wheezy-raspbian.zip
User avatar
Posts: 1545
Joined: Tue May 28, 2013 3:24 pm
Location: North Texas
by W. H. Heydt » Sun Dec 29, 2013 7:21 am
Richard-TX wrote:For those that are wondering why they should learn vi and it's brethren, it really boils down to this:
Not every *nix system has nano, etc. However every *nix system has vi. So if you ever decide to venture into a career in IT, it is best to learn vi now.


Back in the day, it was recommended that people learn "ed" in case vi was unavailable or broken for the reason you cite. *All* unix systems had ed on them.

(In the PC--DOS--world, that's also why people learned edlin.)
Posts: 6559
Joined: Fri Mar 09, 2012 7:36 pm
Location: Vallejo, CA (US)
by sdjf » Sun Dec 29, 2013 3:38 pm
W. H. Heydt wrote:
Richard-TX wrote:For those that are wondering why they should learn vi and it's brethren, it really boils down to this:
Not every *nix system has nano, etc. However every *nix system has vi. So if you ever decide to venture into a career in IT, it is best to learn vi now.


Back in the day, it was recommended that people learn "ed" in case vi was unavailable or broken for the reason you cite. *All* unix systems had ed on them.


I started out with ed or ex "back in the day" and don't think I will ever get used to using nano, my fingers know vi and it's variants, and my brain and fingers get totally lost any time I try using nano or pico.

But everyone has unique preferences, and which command line text editor is best depends on what you find most comfortable to work with. I vote for vim.
FORUM TIP: To view just one person's posting history, sign in, click on their user name, then click on "Search User's Posts." || My 512MB Model B only runs Arch.
Posts: 1388
Joined: Fri Mar 16, 2012 5:20 am
Location: California
by W. H. Heydt » Sun Dec 29, 2013 5:53 pm
sdjf wrote:
W. H. Heydt wrote:I started out with ed or ex "back in the day" and don't think I will ever get used to using nano, my fingers know vi and it's variants, and my brain and fingers get totally lost any time I try using nano or pico.

But everyone has unique preferences, and which command line text editor is best depends on what you find most comfortable to work with. I vote for vim.


"Ex" is a line editor for which vi ("visual") is the screen/multiline version. The vi commands done starting with ':' are really ex commands.

This is a distinction that has, unfortunately, been lost in many ways. There are some things that are best done in a screen editior and some that are best done in a line editor. Global search and replace is a good example of something best done in a line editor. Ex/vi has both screen editing and line editing capabilities.

And..I don't use nano or pico either. Vi is my choice.
Posts: 6559
Joined: Fri Mar 09, 2012 7:36 pm
Location: Vallejo, CA (US)