![]() |
![]() |
![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
![]() |
![]() |
To access the contents, click the chapter and section titles.
Complete Idiot's Guide to Linux
Vim BasicsIf you just want to get the hang of it, heres a bare-bones tutorial. Vim is a modal editor. All this means is that when you are using vim, the program will behave differently depending on whether you are in command mode or editing mode. Lets go. Create and edit a file with vim. On your command line, issue the following: [alberto@digital alberto]$ vim tutorial ~ ~ ~ ~ "tutorial" [New File] A graphical version of vim can be started from within KDE by issuing the command gvim (graphical vim). On issuing the command, the editor will take over your terminal. Empty lines are marked by a tilde (~) character. Vim is currently in its command mode. It is waiting for you to tell it what to do. When in command mode, you can move around the document (assuming theres some text to navigate, which wont be the case in a new document) and issue commands. Table 13.1 is a list of all the cursor moving commands. (As you can see, some are mapped to special keys on your keyboard.)
In general, you move your cursor by using the arrow keys (or its hjkl counterpartsI rarely can remember these). To scroll the document, you use the Page Up and Page Down. The cursor will not wrap or move beyond the beginning or end of a line. When you reach the end, the computer will beep. To go to the next or previous line, use the down or up arrow keys, respectively. When you begin a new, blank document, you dont have much to do; theres no text to edit or navigate. To add text, you need to get into the insert mode. This mode will allow you to enter text as you normally do in other programs; you are still able to use the arrow keys to move around. (The hjkl keys type a letter when you are in insert mode.) Type i to get into the insert mode. Table 13.2 lists a number of editing commands that you can use while in command mode.
To return to the command mode, hold down the Esc key until vim beeps at you. Then you can type a :+command. Commands are issued by pressing the colon (:) followed by the name of the command. Table 13.3 lists the basic ones to get you out of vim.
Vim has some editing commandsand the all-important undo. These editing commands work while vim is in command mode. Command Multipliers: Repeating the Action More Than Once Commands such as delete can specify a multiplier. If you type a number before the command, the command will be repeated that number of times. Consider the following text: This is one line of text. This is another line of text. To delete the words This and is, move the cursor under the T. Make sure you are in command mode by pressing Esc until vim beeps; then type 2dw. To delete both lines of text, put the cursor anywhere on the first line and type 2dd. Multipliers also work for moving around in the document. To move down five lines, you can type 5, followed by the down arrow. Accessing the Shell from VimYou can execute shell commands by preceding them with the exclamation point (!): :!shellcommand When the command finishes executing, you are prompted to hit Enter to return to the editor. To get an interactive shell, enter the name of the shell as the shellcommand (bash). When finished working with the shell, type exit on the shell prompt, and youll return to the editor. Other StuffVim is fairly powerful. It supports multiple documentsor buffers, as they are knownand many other features. The commands covered here are just the bare minimum you need to know to edit files using a terminal. I encourage you to go through the tutorial and to visit vims home page at http://www.vim.org. Youll be happy you did.
|
![]() |
Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement. |