Header Image - Learn Linux Online

Category Archives

3 Articles

vim: Your Linux Editor of Choice

The most important thing you need in any Linux system is a text editor. All configurations are controlled by text files in Linux, and so without a text editor, you cannot get anything to work.

While there is a lot of opinion out there on what editor you should choose, I recommend vim. While many people say that vim is only for hard-core administrators, I recommend it because it is universally available on all systems. Its predecessor (vi) even comes installed with all versions of Linux.

Many people object to vim because it is difficult to learn. There are no menus or gui hints, and all the commands are hotkey based. For many people (like me) that makes it incredibly attractive, but for new users or people migrating from the hand-holding world of Windows, this can be a challenge. Fortunately, you only have to know a couple of commands to put vim (or vi) to work for you.

Installing vim

By default, only vi comes with your Linux operating system. So, you’ll need to install vim with the following command:

sudo apt-get install vim

Starting vim

To start vim, you need only type vim followed by the file you want to edit. In this example, we are going to create a new file called helloworld.txt:

The Interface

The interface has several key parts, which are shown below. One important difference between vim and other editors is the tilde ( ~ ) that shows you where the file ends. In our example, this file is empty, and so you see a series of ~ characters beneath the cursor, which visually indicate where the file ends. Also, the file’s various status indicators are shown at the bottom of the window. They are (from left to right) the file name, a new file indicator, the cursor position (row, column) and the percentage of the file that is currently viewable.

File Editing Basics

There are really only three commands you need to edit files in vim: i, w, and q.

The ‘i’ command sets the editor into “Insert Mode,” which allows you to insert text into the file. Use this command to change files or add information to files. Note: it will only insert text, and will not overwrite text. So, to delete text while in insert mode, you’ll need to use the backspace or delete key.

Once you are done adding / editing text, press the escape key (ESC) to exit insert mode.

Saving the File and Exiting Vim

File operations are done in the command console, which you can access by typing a colon ( : ). Saving a file (writing a file to disk) is accomplished by typing :w and pressing enter. This opens the file console, and issues the write command.

Quitting the file is done much the same way. Use the :q command to quit the program and exit to the shell.

As a shortcut to write changes and exit vim, you can combine the commands into :wq.

Editor Configurations

Vim is unbelievably powerful. Most users only use a fraction of what it is capable of doing. It has a built in macro recording feature, code and syntax highlighting among other powerful features.

There are two features that I highly recommend you use when working with vim, and one that should be turned off.

Turn on:

  • Color scheme. Changing the color scheme makes files easy to see and work with.
  • Auto Indent. This automatically indents files to make them easier to format and read. For example, if you make one line indented for formatting reasons, autoindent will automatically set the next line at the same indent depth, which relieves you from having to tab over for each line.
  • Syntax highlighting. This changes the color of reserved words for various programming languages and system files so that you can easily see what words the system recognizes.

You can manually turn these on using the following commands:

:colorscheme blue
:set autoindent
:syntax on

Turn Off:

  • Word Wrap.

Configuration files frequently get longer than the screen can display. When dealing with human readable text, like a letter, word wrap moves the line of text down to the next line and neatly formats it. However, in the computer world (especially when dealing with programming, scripting, or configuration files) word wrap can make those files difficult to read and decypher. Subsequently, I recommend you turn word wrap off to leave commands in-tact and on a single line when they are supposed to be on a single line. Use this command to turn word wrap off:

:set nowrap

Setting up Auto Configuration with the .vimrc File.

No one wants to type 5 commands to setup vim every time they start the program. Fortunately, there is a simple way that you can configure vim to set itself up every time you start the program. The .vimrc file is like the autoexec.bat file in Windows, except instead of running whenever the system is started, it is run whenever the vim program is started. Simply create this file in your home directory, and put the commands we listed above in it, save the file, and vim will configure itself just the way you want it whenever it is started up:

  1. At the command prompt, type: vim ~/.vimrc, and press enter to edit the .vimrc file in your home directory.
  2. Add in the commands we listed above.
  3. Save the file, and exit vim (use the :wq command).

Here is what my .vimrc file looks like:

How to Install Software on Linux

If you want to install software on Linux computers, the software manager (called a package manager) makes it very easy. But first, there are a couple of terms and concepts you should know. Nothing complicated, just slightly different from the Windows world. Software applications are called “packages” in the Linux world. So, when we mention a Linux package, we are talking about a software program or application. The terms are used interchangeably.

Debian based systems (DebianUbuntuMint) use a package manager (software manager) called apt to install and uninstall programs. Most of the time, you’ll use the apt manager to install and remove packages from your system. There are, however, a few instances when you will manually setup some packages. We’ll go over those shortly.

Software (packages) are installed from the internet, so you have to have a working internet connection to get new and updated versions of packages. There are five commands you need to know to successfully manage your system:

  1. apt-cache search [search term] (helps you find programs you want or need)
  2. apt-get install [package name]
  3. apt-get remove [package name]
  4. apt-get update
  5. apt-get upgrade

Always Update First

To ensure you have the newest, latest, and greatest information about the repositories that contain the packages you want or use, always use the apt-get update command before performing any management tasks. This command tells the system to go on to the interenet and download the latest list of packages that are available including information about updates, patches, and new versions that have been released.

It doesn’t matter if you just did this yesterday or even a couple of hours ago. It’s always best to do it again and again right before you manage your packages or do updates.

To update your apt package manager, use the following command:

apt-get update

Searching for a Package

The syntax to search for a package is:

apt-cache search [package name]

For example, let’s say I want to find the firefox pacakge. I would use this command:

apt-cache search firefox

This returns a list of all the packages that contain the word firefox. In this case, there are about a page and a half of listings. When choosing a package, Occam’s razor is usually the best thought process to apply: the simplier the better. Among the two pages of solutions, is a simple listing: firefoxx – Safe and easy web browser from Mozilla. This is the right listing.

Here’s a big hint: don’t be afraid to use Google to figure out which package you really want. Search for something like “ubuntu 10 apt-get” and the name of the software you want to install. (Don’t forget to put the version of the operating system you have in the search!)

How to Install Software on Linux

Since we now know that firefox is the package name for the FireFox web browser. Thus, we can install it with this command:

apt-get install firefox

 Removing Software

If, at any time, we want to uninstall the Firefox browser from our system, we can remove the package with this command:

apt-get remove firefox

Getting Upgrades

Upgrades under Linux are extremely easy. At anytime you want to check for, download, and install updates, simply use this command:

apt-get upgrade

As stated before, you want to run the apt-get update command before doing maintenance on the system. This is especially important when you do upgrades. You can even combine the commands into a single line by executing:

apt-get update && apt-get upgrade

What is Linux? How to Setup Your Linux Computer

Linux is an open source operating system that runs the vast majority of the servers on the internet. It is developed and maintained by a community of volunteers, who are both dedicated as well as brilliant. It’s penguin logo, who is affectionately named “Tux” is ubiquitous and the source of both humor and pride in the Linux community. Linux is the foundation for the internet, the Apple Mac operating system, as well as the Android mobile device platforms. You can easily utilize this powerful resource in your life and business, and this website is dedicated to helping you do that. Let’s jump right into setting up your first Linux computer!

How you setup your Linux computer depends on how you’re going to use it. There are four levels of usage of any computer, and each level is cumulative.

  1. Casual Usage (Internet and Email)
  2. Workstation (Internet, Email, Word processing, Graphic Design)
  3. Administrator (Managing a network)
  4. Developer (Writing programs and creating applications)

Casual usage can easily be described as “using the computer like a type-writer with spell check and email.” At this level, the user only wants to send and receive email, check their Facebook account, search Google, and read Wikipedia. There is not much required for this type of a user. They just need a browser and an email client.

workstation is just that: a computer designed to do work. It includes all the capabilities of the causal user, but also includes software applications that allow you to create office documents, images, and other items that can be considered work product.

An administrator level setup includes all the capabilities of the casual user and the workstation, but is also designed to manage networks and servers. It includes a lot of “geek” tools that the average user will never see nor want to know about.

The final and highest level of computer setup is the developer setup. It includes all the capabilities of the other three, but also includes the tools and utilities as well as source code (called linux-headers) that are required for creating programs and applications.

What to Learn Next:

Below, you will find a list of tutorials that teach you the Linux system one building block at a time. Read and do each of these tutorials in the order they are listed below to get a jump start on working with your new Linux System.

  1. How to Install Software on your Linux Computer
  2. vim: Your Text Editor of Choice