Home » Categories » Multiple Categories |
Installing and Using the Vim Text Editor on a Cloud Server |
Article Number: 203 | Rating: Unrated | Last Updated: Thu, Jan 16, 2014 at 8:16 PM
|
IntroductionOne of the most powerful text editors accessible from the command line is the vim editor. Built on the foundation of "vi", an editor dating back to 1976, vim adds additional functionality and power, while maintaining the editing style of its predecessor.InstallationDue to vim's wide-spread use on the Linux command line, it is available in almost every distribution's default repositories.On Ubuntu and Debian, use apt-get to install: sudo apt-get install vimOn Fedora and CentOS, install with yum: sudo yum install vimOn Arch Linux, vim can be install through pacman: sudo pacman -S vimVim should now be installed correctly. Opening VimBy default, when vim is called without any arguments, it opens with a blank document. Depending on your distribution, there may be an introduction and licensing message. This will disappear when you begin using the editor.However, we are not going to open vim with a blank document. We will create a sample document called "newfile" to showcase vim's features. echo "This is a new file. Here is the second line And here is the third line. Some more text is on this line. We will edit this file in vim. It will be great fun." >> newfileNow, we will open the file we just created with vim. vim newfile Modal EditingThe main difference between vim and most other editors is that vim is a "modal" editor. Most other editors have only one mode. In these editors, special editing functions, like copying text, are performed by holding one or more modifier keys and then hitting a regular key. Vim uses distinct modes to separate these functions from the task of normal text input.Normal ModeUsed for editing operations. Copying, pasting, moving, deleting, and changing text is accomplished from within this mode.In vim, editing functions are performed by putting vim into "normal" mode. Normal mode is the mode that vim is in upon opening the program. This mode is used to navigate a text document quickly and to perform editing. It is not used for entering text.
Insert ModeUsed for inserting new text in the document. It is possible to enter insert mode in a number of ways.To enter text, vim must transition into "insert" mode. Insert mode is analogous to the typing interface of most other text entry programs. What you type appears on the screen in the document. All normal keys will produce the corresponding character at the current cursor position.
Visual ModeUsed for visual selection. Many commands available in normal mode can be applied to a specific highlighted portion of the text.A third mode that vim uses is "visual" mode. This is used for visual selection and manipulation of text. Areas of text are highlighted as a target of subsequent editing or formatting commands.
Command ModeUsed for issuing vim commands. Enter this mode with the colon key.An additional mode that is used for complex edits, changing settings, and controlling vim itself is "command" mode. This mode is used for saving documents, quitting the program, performing complex searches and many other things.
NavigationBasic NavigationIt is always possible to navigate text with the arrow keys, but vim provides faster ways of moving around a document. In normal mode, you can use the h,j,k, and l keys to move left, down, up, and right, respectively.
Advanced NavigationThere are also other navigation shortcuts. Here are a few of the most useful ones:
EditingEditing text in vim is accomplished by issuing commands in normal mode.It is important to realize that editing commands in vim are very powerful when combined with motion commands. Anything from the navigation section can be used as a direction. For instance, you can perform an editing command on a word following it with "w". Here are a few of the different actions you can choose from: Removing text
Changing Text
Copying and Pasting
Miscellaneous Editing
Managing DocumentsVim manages documents mainly through its command mode. Commands are issued by typing a ":" before each command.
Putting It All TogetherAs mentioned earlier, vim's power comes from its ability to chain different commands together. The easiest way to grasp this concept is to consider vim commands a language. Keys in normal mode can represent adjectives, verbs, and objects.For instance, to yank (copy) 4 words, simply translate that phrase into commands that vim recognizes. In this case, it would be: y4wTo delete from the current line until the end of the file, type: dGIt's also helpful to realize some of the conventions that vim uses for its editing commands. For instance, a doubled letter is usually applied to the entire line. We can copy an entire line with: yyOn the other hand, a capitalized version of an editing command often targets from the current cursor position to the end of the line. For instance, to change the text from here until the end of the line, you would use: CTo do the same motion on more than one line, just add a numbered prefix to the command. This changes the text from the current position to the end of the following line: 2CThere are many other powerful techniques to use with vim that are outside of the scope of this guide. If you would like to learn more, a good start is with vim's built in tutorial interface. It will not cover advanced topics, but it will give you a good idea of how to work with vim to do basic editing. You can start it with this: vimtutor |
Attachments
There are no attachments for this article.
|
How To Install Wordpress on Ubuntu 12.04
Viewed 2610 times since Tue, Dec 24, 2013
How To Set Up Master Slave Replication in MySQL
Viewed 3331 times since Thu, Dec 26, 2013
How To Change Themes and Adjust Settings in Ghost
Viewed 4142 times since Thu, Dec 26, 2013
How To Manage Packages In Ubuntu and Debian With Apt-Get & Apt-Cache
Viewed 6766 times since Fri, Dec 27, 2013
How To Create and Manage Databases in MySQL and MariaDB on a Cloud Server
Viewed 2815 times since Thu, Dec 26, 2013
How To Use WP-CLI to Manage your WordPress Site from the Command Line
Viewed 10067 times since Sat, Jan 4, 2014
How to Setup and Configure an OpenVPN Server on Debian 6
Viewed 2374 times since Thu, Dec 26, 2013
How To Install Z Shell (zsh) on a Cloud Server
Viewed 2675 times since Fri, Dec 27, 2013
How To Use SuExec in Apache to run CGI Scripts on an Ubuntu
Viewed 3569 times since Mon, Dec 30, 2013
How To Launch Your Site on a New Ubuntu 12.04 Server with LAMP, SFTP, and DNS
Viewed 2561 times since Thu, Dec 26, 2013
|