19 Ekim 2010 Salı

VI quick reference

Avleen's quick reference card for vi(m)



If you learn the first 3 paragraphs you shouldn't have any problems in vi.



The rest are 'nice' and show the true power of the vi editor.



I'm sure Emacs has similar power, and those comfortable with using it



are probably going to continue to use it.



This card is for those who are new to vi, forced to use vi, or just anyone



who wants to learn about vi.







I would highly recommend learning the first 2 paragraphs at learn, so you



can do the simplest editing on any unix box you're sat at.



vi is very easy to use, really! Once you realise what you're doing.



Here's a quick breakdown:



i) When you open vi, or press 'esc', you go into 'command mode'



This mode lets you enter a key to preform one of the fuctions



that are listed below



ii)A lot of the rest of the time, you'll be in text editing



/ inserting mode



As a point of reference, commands which begin with a colon (':'), are not



native vi commands, but ed commands.







Key Command







Esc Escape back to command mode where you can enter



another key-combo, or quit







INSERTING TEXT:



i Enter text before the char that is higlighted



I Enter text before the first character on the line



a Enter text after the char that is highlighted



A Enter text after the last character on the line



o Insert a new line after the line you're currently on



O Insert a new line before the line you're currently on



:r Insert all the text from at the cursor







SAVING, NOT SAVING, EXITING AND PRINTING:



ZZ Save and exit



:wq Save and exit



:q! Don't save, but exit anyway



:wq! Force the save and exit (eg, if the file is read only)



:!lp % Print the current file







MOVING AROUND:



$ Move to the end of the current line



^ Move to the start of the current line



h Move left one character



j Move down one one



k Move up one line



l Move right one character



w Move to the start of the next word



e Move the the end of the next word



b Move to the start of the last word



G Move to the end of the file



H Move to the top of the visible screen



L Move to the bottom of the visible screen



: Jump to line







SEARCHING:



/ Search forwards for '' (This is case sensetive!)



? Search backwards for '' (This is case sensetive!)







TEXT MANIPULATION:



u Undo the last command



. Redo the last command



J Join the next line with text, to the end of the current line



All newline characters are replaced by a single space



:%s/foo/bar/g Replace all instances of 'foo' in the file with 'bar'



:^,$s/foo/bar/g Replace all instances of 'foo' on the current line with 'bar'



:1,^s/foo/bar/g Replace all instances of 'foo' from line 1 of the file to the



start of this line with 'bar'



dd Delete the current line



cc Clear the current line



yy Copy the current line to the buffer



p Paste the buffer to this location



x Delete the character under the cursor



Perform the action specified by the key, of times



Eg, the command '3d' deletes the next 3 lines







Spell checking:



If you have aspell installed:



map ^T :w!:!aspell check %:e! %



The '^T' is a literal control+T.



To get this, first press CTRL+v, then press CTRL+T



If you have ispell installed:



map ^T :w!:!ispell %:e! %



The '^T' is a literal control+T.



To get this, first press CTRL+v, then press CTRL+T







VIM commands:



These commands a useful if you have VIM (Vi IMproved). This is the default 'vi'



on Linux:



:map Map a key to a set of keystrokes



:syntax on/off Turn on/off syntax highlighting. Useful for editing code.



:set tw= Set the linewrapping to characters



:set ai/noai Turn on autoindenting/Turn off autoindenting (paragraph editing)

Hiç yorum yok:

Yorum Gönder