Previous Next

vi and Vim Editors Pocket Reference Support for every text editing task (Arnold Robbins) (z-library.sk, 1lib.sk, z-lib.sk)

Author: Arnold Robbins

代码

Many Unix, Linux, and Mac OS X geeks enjoy using the powerful, platform-agnostic text editors vi and Vim, but there are far too many commands for anyone to remember. Author Arnold Robbins has chosen the most valuable commands for vi, Vim, and vi's main clones—vile, elvis, and nvi—and packed them into this easy-to-browse pocket reference. You'll find commands for all kinds of editing tasks, such as programming, modifying system files, and writing and marking up articles. This second edition includes:Command-line options vi commands and set options Input mode shortcuts Substitution and regular expressions ex commands and options Initialization and recovery Enhanced tags and tag stacks A greatly expanded section on Vim commands and options Additional features in vile, elvis, and nvi Internet resources for vi A full index

📄 File Format: PDF
💾 File Size: 2.6 MB
9
Views
0
Downloads
0.00
Total Donations

📄 Text Preview (First 20 pages)

ℹ️

Registered users can read the full content for free

Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.

📄 Page 1
(This page has no text content)
📄 Page 2
(This page has no text content)
📄 Page 3
vi and Vim Editors Pocket Reference
📄 Page 4
(This page has no text content)
📄 Page 5
SECOND EDITION vi and Vim Editors Pocket Reference Arnold Robbins Beijing • Cambridge • Farnham • Köln • Sebastopol • Tokyo
📄 Page 6
vi and Vim Editors Pocket Reference, Second Edition by Arnold Robbins Copyright © 2011 Arnold Robbins. All rights reserved. Printed in Canada. Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472. O’Reilly books may be purchased for educational, business, or sales promo- tional use. Online editions are also available for most titles (http://my.safari booksonline.com). For more information, contact our corporate/institutional sales department: (800) 998-9938 or corporate@oreilly.com. Editor: Andy Oram Copyeditor: Amy Thomson Production Editor: Adam Zaremba Proofreader: Sada Preisch Indexer: John Bickelhaupt Cover Designer: Karen Montgomery Interior Designer: David Futato Illustrator: Robert Romano Printing History: January 1999: First Edition. January 2011: Second Edition. Nutshell Handbook, the Nutshell Handbook logo, and the O’Reilly logo are registered trademarks of O’Reilly Media, Inc. vi and Vim Editors Pocket Reference, the image of a tarsier, and related trade dress are trademarks of O’Reilly Media, Inc. Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and O’Reilly Media, Inc., was aware of a trademark claim, the designations have been printed in caps or initial caps. While every precaution has been taken in the preparation of this book, the publisher and author assume no responsibility for errors or omissions, or for damages resulting from the use of the information contained herein. ISBN: 978-1-449-39217-8 [TM] 1294430582
📄 Page 7
Contents vi and Vim Editors Pocket Reference 1 Introduction 1 Conventions 1 Acknowledgments 2 Command-Line Options 2 vi Commands 3 Input Mode Shortcuts 9 Substitution and Regular Expressions 11 ex Commands 16 Initialization 21 Recovery 21 vi set Options 21 Nothing like the Original 23 Enhanced Tags and Tag Stacks 23 Vim—vi Improved 25 nvi—New vi 59 elvis 63 vile—vi like Emacs 71 Internet Resources for vi 80 Program Source and Contact Information 81 Index 83 v
📄 Page 8
(This page has no text content)
📄 Page 9
vi and Vim Editors Pocket Reference Introduction This pocket reference is a companion to Learning the vi and Vim Editors, by Arnold Robbins et al. It describes the vi com- mand-line options, command-mode commands, ex com- mands and options, regular expressions and the use of the substitute (s) command, and other pertinent information for using vi. While retaining coverage of the vi clones, nvi, elvis, and vile, this edition offers expanded coverage of the Vim editor, which has become the de facto standard version of vi in the GNU/Linux world. The Solaris version of vi served as the “reference” version of the original vi for this pocket reference. Conventions The following font conventions are used in this book: Courier Used for filenames, command names, options, and every- thing to be typed literally. 1
📄 Page 10
Courier Italic Used for replaceable text within commands. Italic Used for replaceable text within regular text, Internet URLs, for emphasis, and for new terms when first defined. [ ... ] Identifies optional text; the brackets are not typed. CTRL-G Indicates a keystroke. Acknowledgments Thanks to Robert P.J. Day and Elbert Hannah, who reviewed this edition. The production team at O’Reilly Media did a great job helping me make the book look the way I wanted. A special thanks to my editor, Andy Oram, for keeping the project mov- ing with continual gentle encouragement. Command-Line Options Command Action vi file Invoke vi on file vi file1 file2 Invoke vi on files sequentially view file Invoke vi on file in read-only mode vi -R file Invoke vi on file in read-only mode vi -r file Recover file and recent edits after a crash vi -t tag Look up tag and start editing at its definition vi -w n Set the window size to n; useful over a slow connection vi + file Open file at last line vi +n file Open file directly at line number n 2 | vi and Vim Editors Pocket Reference
📄 Page 11
Command Action vi -c command file Open file, execute command, which is usually a search command or line num- ber (POSIX) vi +/pattern file Open file directly at pattern ex file Invoke ex on file ex - file < script Invoke ex on file, taking commands from script; suppress informative mes- sages and prompts ex -s file < script Invoke ex on file, taking commands from script; suppress informative mes- sages and prompts (POSIX) vi Commands vi commands are used in “screen” mode (the default), where you use the commands to move around the screen and to per- form operations on the text. Most vi commands follow a general pattern: [command][number]textobject or the equivalent form: [number][command]textobject Movement Commands vi movement commands distinguish between two kinds of “words.” The lowercase commands define a word as a contig- uous sequence of underscores, letters, and digits. The upper- case commands define a word as a contiguous sequence of nonwhitespace characters. vi Commands | 3
📄 Page 12
Command Meaning Character h, j, k, l Left, down, up, right (←, ↓, ↑, →) Text w, W, b, B Forward, backward by word e, E End of word ), ( Beginning of next, previous sentence }, { Beginning of next, previous paragraph ] ], [ [ Beginning of next, previous section Lines ENTER First nonblank character of next line 0, $ First, last position of current line ^ First nonblank character of current line +, - First nonblank character of next, previous line n | Column n of current line H, M, L Top, middle, last line of screen n H n (number) of lines after top line n L n (number) of lines before last line Scrolling CTRL-F , CTRL-B Scroll forward, backward one screen CTRL-D , CTRL-U Scroll down, up one half-screen CTRL-E , CTRL-Y Show one more line at bottom, top of window z ENTER Reposition line with cursor: to top of screen z . Reposition line with cursor: to middle of screen z – Reposition line with cursor: to bottom of screen CTRL-L Redraw screen (without scrolling) 4 | vi and Vim Editors Pocket Reference
📄 Page 13
Command Meaning Searches /pattern Search forward for pattern ?pattern Search backward for pattern n, N Repeat last search in same, opposite direction /, ? Repeat previous search forward, backward f x Search forward for character x in current line F x Search backward for character x in current line t x Search forward to character before x in cur- rent line T x Search backward to character after x in current line ; Repeat previous current-line search , Repeat previous current-line search in op- posite direction Line number CTRL-G Display current line number n G Move to line number n G Move to last line in file : n Move to line n in file Marking position m x Mark current position as x ‘ x Move cursor to mark x (grave accent) ‘ ‘ Return to previous mark or context (two grave accents) ’ x Move to beginning of line containing mark x (single quote) ’ ’ Return to beginning of line containing pre- vious mark (two single quotes) vi Commands | 5
📄 Page 14
Editing Commands Command Action Insert i, a Insert text before, after cursor I, A Insert text before beginning, after end of line o, O Open new line for text below, above cursor Change cw Change word cc Change current line c motion Change text between the cursor and the tar- get of motion C Change to end of line r Replace single character R Type over (overwrite) characters s Substitute: delete character and insert new text S Substitute: delete current line and insert new text Delete, move x Delete character under cursor X Delete character before cursor dw Delete word dd Delete current line d motion Delete text between the cursor and the target of motion D Delete to end of line p, P Put deleted text after, before cursor " n p Put text from delete buffer number n after cursor (for last nine deletions) Yank yw Yank (copy) word 6 | vi and Vim Editors Pocket Reference
📄 Page 15
Command Action yy Yank current line " a yy Yank current line into named buffer a (a–z); uppercase names append text y motion Yank text between the cursor and the target of motion p, P Put yanked text after, before cursor " a P Put text from buffer a before cursor (a–z) Other commands . Repeat last edit command u, U Undo last edit; restore current line J Join two lines ex edit commands :d Delete lines :m Move lines :co or :t Copy lines :.,$d Delete from current line to end of file :30,60m0 Move lines 30 through 60 to top of file :.,/pattern/co$ Copy from current line through line contain- ing pattern to end of file Exit Commands Command Meaning :w Write (save) file :w! Write (save) file, overriding protection :wq Write (save) and quit file :x Write (save) and quit file ZZ Write (save) and quit file :30,60w newfile Write from line 30 through line 60 as newfile :30,60w>> file Write from line 30 through line 60 and append to file vi Commands | 7
📄 Page 16
Command Meaning :w %.new Write current buffer named file as file.new :q Quit file :q! Quit file, overriding protection Q Quit vi and invoke ex :e file2 Edit file2 without leaving vi :n Edit next file :e! Return to version of current file as of time of last write (save) :e # Edit alternate file :vi Invoke vi editor from ex : Invoke one ex command from vi editor % Current filename (substitutes into ex com- mand line) # Alternate filename (substitutes into ex com- mand line) Solaris vi Command-Mode Tag Commands Command Action ^] Look up the location of the identifier under the cursor in the tags file and move to that location; if tag stack- ing is enabled, the current location is automatically pushed onto the tag stack ^T Return to the previous location in the tag stack, i.e., pop off one element Buffer Names Buffer names Buffer use 1–9 The last nine deletions, from most to least recent a–z Named buffers to use as needed; uppercase letters append to the respective buffers 8 | vi and Vim Editors Pocket Reference
📄 Page 17
Buffer and Marking Commands Command Meaning " b command Do command with buffer b m x Mark current position with x ‘ x Move cursor to character marked by x (grave accent) ‘ ‘ Return to exact position of previous mark or context (two grave accents) ’ x Move cursor to first character of line marked by x (single quote) ’ ’ Return to beginning of the line of previous mark or context (two single quotes) Input Mode Shortcuts vi provides two ways to decrease the amount of typing you have to do: abbreviations and maps. Word Abbreviation :ab abbr phrase Define abbr as an abbreviation for phrase. :ab List all defined abbreviations. :unab abbr Remove definition of abbr. Command and Input Mode Maps :map x sequence Define character(s) x as a sequence of editing commands. :unmap x Disable the sequence defined for x. :map List the characters that are currently mapped. Input Mode Shortcuts | 9
📄 Page 18
:map! x sequence Define character(s) x as a sequence of editing commands or text that will be recognized in insert mode. :unmap! x Disable the sequence defined for the insert mode map x. :map! List the characters that are currently mapped for interpre- tation in insert mode. For both command and insert mode maps, the map name x can take several forms: One character When you type the character, vi executes the associated sequence of commands. Multiple characters All the characters must be typed within one second. The value of notimeout changes the behavior. # n Function key notation: a # followed by a digit n represents the sequence of characters sent by the keyboard’s function key number n. To enter characters such as Escape (^[) or carriage return (^M), first type CTRL-V (^V). Executable Buffers Named buffers provide yet another way to create “macros”— complex command sequences you can repeat with a few key- strokes. Here’s how it’s done: 1. Type a vi command sequence or an ex command preceded by a colon; return to command mode. 2. Delete the text into a named buffer. 3. Execute the buffer with the @ command followed by the buffer letter. The ex command :@buf-name works similarly. 10 | vi and Vim Editors Pocket Reference
📄 Page 19
Some versions of vi treat * identically to @ when used from the ex command line. In addition, if the buffer character supplied after the @ or * commands is *, the command is taken from the default (unnamed) buffer. Automatic Indentation Enable automatic indentation with the following command: :set autoindent Four special input sequences affect automatic indentation: ^T Add one level of indentation; typed in insert mode ^D Remove one level of indentation; typed in insert mode ^ ^D Shift the cursor back to the beginning of the line, but only for the current line* 0 ^D Shift the cursor back to the beginning of the line and reset the current auto-indent level to zero† Two commands can be used for shifting source code: << Shift a line left eight spaces >> Shift a line right eight spaces The default shift is the value of shiftwidth, usually eight spaces. Substitution and Regular Expressions Regular expressions, and their use with the substitute com- mand, are what give vi most of its significant editing power. * ^ ^D and 0 ^D are not in elvis. † The nvi 1.79 documentation has these two commands switched, but the program actually behaves as described here. Substitution and Regular Expressions | 11
📄 Page 20
The Substitute Command The general form of the substitute command is: :[addr1[,addr2]]s/old/new/[flags] Omitting the search pattern (:s//replacement/) uses the last search or substitution regular expression. An empty replacement part (:s/pattern//) “replaces” the matched text with nothing, effectively deleting it from the line. Substitution flags Flag Meaning c Confirm each substitution g Change all occurrences of old to new on each line (globally) p Print the line after the change is made It’s often useful to combine the substitute command with the ex global command, :g: :g/Object Oriented/s//Buzzword compliant/g vi Regular Expressions . (period) Matches any single character except a newline. Remember that spaces are treated as characters. * Matches zero or more (as many as there are) of the single character that immediately precedes it. The * can follow a metacharacter, such as ., or a range in brackets. ^ When used at the start of a regular expression, ^ requires that the following regular expression be found at the be- ginning of the line. When not at the beginning of a regular expression, ^ stands for itself. $ When used at the end of a regular expression, $ requires that the preceding regular expression be found at the end 12 | vi and Vim Editors Pocket Reference
The above is a preview of the first 20 pages. Register to read the complete e-book.

💝 Support Author

0.00
Total Amount (¥)
0
Donation Count

Login to support the author

Login Now

Recommended for You

Loading recommended books...
Failed to load, please try again later
Back to List