VI Editing Commands For Linux YASH PAL, 4 June 202328 May 2024 In this post, we are going to see the commands for the vi editor. Word and Character Searching The vi editor has two kinds of searches: string and character. For a string search, the/and? commands are used. When we start these commands, the command just typed will be shown on the bottom line, where we type the particular string to look for. These two commands differ only in the direction where the search takes place. /command: The command searches forwards (downwards) in the file. ? command: The? command searches backward (upwards) in the file. Then and commands repeat the previous search command in the same or opposite direction, respectively.(a) The n Command: The n Command Repeats the last search for the text specified by the Pattern parameter in the same direction.(b) The N Command: The N Command Repeats the last search for the text specified by the Pattern parameter in the opposite direction. Some characters have special meanings to vi, so they must be preceded by a backslash (\) to be included as part of the search expression. Special Characters: ^Beginning of the line. (At the beginning of a search expression.).Matches a single character.*Matches zero or more of the previous character.$End of the line (At the end of the search expression.)[Starts a set of matching, or non-matching expressions… For example: /f[iae]t matches either of these: fit fat fet In this form, it matches anything except these: /a[^bcd] will not match any of these, but anything with an a and another letter: ab ac ad<Put in an expression escaped with the backslash to find the ending or beginning of a word. For example: /\<the\> should find only word “the”, but not words like these: there and other.>See the character description above..% Finds the parenthesis or brace that matches the one at current cursor positionFSearch the current line backwards for the character specified after the ‘F’ command. If found, move the cursor to the position.TSearch the current line backwards for the character specified after the T command, and move to the column after the if it’s found.fSearch the current line for the character specified after the ‘f’ command. If found, move the cursor to the position.tSearch the current line for the character specified after the ‘t’ command, and move to the column before the character if it’s found.,Repeat the last f, F, t or T command in the reverse direction.;Repeat the last f, F. t or T. The character search searches within one line to find a character entered after the command. The and F commands search for a character on the current line only. searches forwards and F searches backwards and the cursor moves to the position of the found character. The t and T commands search for a character on the current line only, but for t the cursor moves to the position before the character, and T searches the line backwards to the position after the character. These two sets of commands can be repeated using the or, command, where ; repeats the last character search command in the same direction, while, repeats the command in the reverse direction. Substitution Operation Suppose you want to change just a few characters, and not a whole word. The substitute command (s), by itself, replaces a single character. With a preceding count, you can replace that many characters. As with the change command (c), the last character of the text will be marked with a $ so that you can see how much text will be changed. The S command, as is usually the case with uppercase commands, lets you change whole lines. In contrast to the C command, which changes the rest of the line from the current cursor position, the S command deletes the entire line, no matter where the cursor is. vi puts you in insert mode at the beginning of the line. A preceding count replaces that many lines. Both s and S put you in insert mode; when you are finished entering new text, press ESC. The R command, like its lowercase counterpart, replaces text. The difference is that it simply enters overstrike mode. The characters you type, replace what’s on the screen character by character, until you type ESC. You can only overstrike a maximum of one line, as you type RETURN, vi will open a new line, effectively putting you into insert mode. C – Change to the end of the line from the current cursor position.R – Replace characters on the screen with a set of characters entered, ending with the Escape key.S – Change an entire line.c – Change until “cc” changes the current line. A count changes that many lines.r – Replace one character under the cursor. Specify a count to replace a number of characterss – Substitute one character under the cursor, and go into insert mode. Specify a count to substitute a number of characters. A dollar sign ($) will be put at the last character to be substituted. Replace Operation Global replacement really uses two ex commands: :g (global) and s (substitute).Since the syntax of global replacement commands can get fairly complex, let’s look at it in stages. The substitute command has the syntax::s/old/new/ This changes the first occurrence of the pattern old to new on the current line. The/(slash) is the delimiter between the various parts of the command. (The slash is optional when it is the last character on the line.)A substitute command with the syntax::s/old/new/g changes every occurrence of old to new on the current line, not just the first occurrence. The is command allows options following the substitution string. The g option in the syntax above stands for global. (The g option affects each pattern on a line ; don’t confuse it with the g command, which affects each line of a file.) The various commands are: Submitting Operations or Find/Replace :%s/seca/secb/ – For all lines in a file, find string “seca” and replace with string “secb” for the first instance on a line. :%s/fff/rrrrr/g – For all lines in a file, find string “fff” and replace with string “rrrrr” for each instance on a line. :%s/fff/rrrrr/gc – For all lines in a file, find string “fff” and replace with string “rrr” for each instance on a line. Ask for confirmation for replace the “fff” into “rrrrr”. %s/ff/rrrrr/gi – For all lines in a file, find string “f” and replace with string “rrrrr” for each instance on a line. It is Case Insensitive. :’a,’bs/fff/rrrrr/gi – For all lines between line marked “a” (ma) and line marked “b” (mb), find string “f” and replace with string “rrrrr” for each instance on a line. It is Case Insensitive. :%s/*$/– For all lines in a file, delete blank spaces at end of line. :%s/\(.*\):\(.*\)/\2:\1/g – For all lines in a file, move last field delimited by “:” to the first field. Swap fields if only two. Yank Command The vi yank command is similar to the copy command in many editors. It copies the specified line from the current file using various command and put these command to another location of the file. S. No.CommandAction1.yCopy current characters2.yy(yank yank) copy the current line or single line (defined by the current cursor position) into the buffer.3.ytUsed for multiple lines. Yanks from current cursor position to the line marked “t”4.5yyCopy (without cutting) 5 lines.5.ywYank (copy) word from cursor position.6.ymotionYank text between the cursor and the target of motion.7.Y0Copy the beginning to current position8.y$Copy the current cursor position to the end.9.5ybYank five words back Put Command The vi put command is similar to the paste command in many other editors. It will paste whatever is in the buffer from the previous yank command. If you yanked a whole line (or group of lines) p and P paste the text before or after the current line, respectively, otherwise, they paste the text before or after the cursor. respectively, on the current line. CommandActionpPaste the specified buffer before the current position or line. If no buffer is specified (with the “command”) the ‘P’ uses the general buffer.pPaste the specified buffer after the current position or line. If no buffer as specified (with the “command”) then ‘p’ uses the general buffer. Delete Commands The commonly used command for cutting is d. This command deletes text from the file. The command is preceded by an optional count and followed by a movement specification. $vi . filename ~~~~~~~~~~~~~“filename” [new file] At the bottom of the screen the filename is display and tilde (~) character appear at the beginning of file. After pressing i we write India is great nation showing in next screen. India is great nationhere’s each and every oneIndia is my countryWe are the manpower of~~~~~~~“filename” [new file] dd command When the cursor is, on the first line and we press dd command, then output become shown below. here’s each and every oneIndia is my countrywe are the manpower of~~~ In this screen first line is deleted. If we want to delete 4 line then press 4dd. In which current line is deleted with three below line. dw command Now cursor is on “h” of “here’s” word in first line in above details. We want to delete a word using dw command. Press dw command and output become shown next. ‘s each and everyoneIndia is my countryWe are the manpower of~~~~~~~ dW command Delete the word from cursor position to the end of word and ignore punctuation while de stops at any punctuation. If press dW instead of dw it also delete ‘s in here’s and output become. each and everyoneIndia is my countryWe are the manpower of~~~~~~~ x commandLet assume cursor at position e on “each” word to delete a single character at the cursor position, press x command. The “e” of “each” show below. ach and everyoneIndia is my countryWe are the manpower of~~~~~~~~~ d$ command Now move the cursor to the “e” of “everyone” and delete the rest of line from current cursor position press the d$ command and output shown below. ach and everyoneIndia is my countryWe are the manpower of~~~~~~~~~ ach andIndia is my countryWe are the manpower of~~~~~~~~~ d0 command And now cursor on the “d” of “and” we want to delete current line from the start of line to the current cursor position then we have to press d0 command. India is my countryWe are the manpower of~~~~~~~~ Here are some combinations of these commands:d – Delete until where”dd”deletes the current line. A count deletes that many lines Whatever is deleted is placed into the buffer specified with the”command. If no buffer is specified, then the general buffer is usedld$ – deletes from current cursor position to the end of the line.dw – deletes from current cursor position to the end of the word.3dd – deletes three lines from current cursor position downwards.d0 – deletes from beginning to the current cursor position.d$ – delete from current cursor position to the end of line.X – Delete the character before the cursor position e.g., a b c d Press “X” a c d.x – Delete character under the cursor. A count tells how many characters to delete. The characters will be deleted after the cursor e.g., cnoio.h Press “x” coio.h Press “p” conio.h. There is also the y command, which operates similarly to the d command which take text from the file without deleting the text. Reading and Writing File The vi editor reads disk file into the work buffer when you specify a filename on the command line you used to call vi. This section discuss the ways of reading text into the work buffer and writing it to a file. The Read Command The read command: r, will read the contents of a disk file and insert it into the work buffer following the current line. The new file does not overwrite any text in the work buffer but rather is positioned following the single address you specify (or the current line if you do not specify an address). You can use an address of O to read the file into the beginning of the work buffer. The read command has the following syntax::[address] r [file_name] As with other commands that begin with a colon when you enter the colon it appears on the status line. The filename is the pathname of the file that you want to read and must be determinated by RETURN. The Write Command The write command: w will write all or part of the work Buffer to a file You can specify an address to write part of the work Buffer and a filename to specify a file to receive the text.The write command has two formats:: [address] w [!] [Filename ]: [address] w >> filename If we do not use an address or a filename, the entire work buffer is written to the file we are editing, hence it gives us a way of permanently saving the changes we have made to our file without actually exiting from “vi” with the [Z] [Z] command. The address is specified in the same way in the substitute command and specifies the portions of the work Buffer to be written or it specifies the range of line of the work Buffer to be written If no address is included the entire work Buffer is written. The exclamation point is necessary unless we are writing out the entire contents of the work Buffer to the current file being edited. It forces “vi” to perform the command. The second format appends text to an existing file. Example: Write content from current file from first line to last line to file 1.: 1, $w! file1 Setting up vi with the .exrc File You can store commands and settings that you want to be executed any time, you start the vi or ex editors in a file called .exrc in your home directory. You can modify the .exrc file with the vi editor, just as you can modify any other text file. If you don’t yet have an .exrc file, simply use vi to create one. Enter into this file the set , ab and map commands that you want to have in effect whenever you use vi or ex. A sample .exrc file looks like this:set nowrapscan wrapmargin=7set sections=SeAhBhChDh nomesgmap q:w^M:n^M“To swap two words, put cursor at start of first word and type v:map v dwElpab ABCD YSGD & Associates, Inc. The ^M characters are RETURNs. Make them by pressing CTRL-v. then RETURN. Lines that start with a double quote (“) are comments. Since the file is actually read ex before it enters vi, commands in .exrc should not have a preceding colon. In addition to reading the exre file in your home directory, vi will read a file called .exrc in the current directory. This allows you to set options that are appropriate to a particular project. If your exre file doesn’t seem to be working, watch carefully for error messages just as vi starts, before it clears your screen. If you can’t read them quickly enough, start ex instead of vi. The q! command quits ex:%ex No tail recursion:q! Advanced Editing Techniques Marking a LineAny line can be “Book Marked” for a quick cursor return.(a) Type the letter “m” and any other letter to identify the line.(b) This “marked” line can be referenced by the keystroke sequence “‘” and the identifying letter. Example: “mt” will mark a line by the identifier “t”. “t” will return the cursor to this line at any time. A block of text may be referred to by its marked lines. i.e.’t,’b. 2. vi Line Buffers (yank Command)To capture lines into the buffer:(a) Single line: “yy” – yanks a single line (defined by current cursor position) into the buffer(b) Multiple lines: “y’t” – yanks from current cursor position to the line marked “t”(c) Multiple lines: “3yy” – yank 3 lines, current line and two lines below it. Copy from buffer to editing session: position.(d) “p” – place contents of buffer after current line defined by current cursor 3. Command LineCommand OptionsThe vi command line interface is available by typing “:”. Terminate with a carriage return. Example commands: :help topic – If the exact name is unknown, TAB completion will cycle through the various options given the first few letters. Ctrl-d will print the complete list of possibilities. :set all – display all settings of our session. :set ic – Change default to ignore case for text searches Default is changed from non – ignorecase to ignorecase. (ic is a short form otherwise type set ignorecase) Common Options to Set: autoindent (ai) – Indents automatically in text input mode to the indentation of the previous line by using the spacing between tab stops specified by the shiftwidth option. The default is noai. This option is not in effect for global commands. autoprin (ap) – Prints the current line after any command that changes the editing buffer. The default is ap. This option applies only to the last command in a sequence of commands on a single line and is not in effect for global commands. autowrite (aw) – Writes the editing buffer to the file automatically before the :n subcommand, the :ta subcommand. The default is noaw. backtags (bt) – Allows the Ctrl-T subcommand to return the file editing position to the location where the previous Ctrl-] subcommand was issued. If nobacktags is set, then Ctrl-T is the same as Ctrl-]. The default is backtags. beautifying text (bf) – Prevents the user from entering control characters in the editing buffer during text entry (except for tab, new – line). The default is nobf. This option applies to command input. closepunct (cp=) – Handles a list of closing punctuation, especially when wrapping text (wraptype option). Precedes multicharacter punctuation with the number of characters ; for example, cp=3..;)). The vi command does not split closing punctuation when wrapping directory (dir=) – Displays the directory that contains the editing buffer The default is dir =/var/tmp. edcompatible (ed) – Retains g (global) and c (confirm) subcommand suffixes during multiple substitutions and causes the r (read) suffix to work like the r subcommand, The default is noed. exrc (exrc) – If not set, ignores any .exre file in the current directory during initialization, unless the current directory is that named by the HOME environment variable. The default is noexre. hardtabs (ht=) – Tells the vi editor the distance between the hardware tab stops on your display screen. The default is ht=8. history (hist=) – Sets the limit on last line mode history commands. The initial value is hist=32. The history size is zero (h ist=0) for the tvi command. ignorecase(ic) – Ignores distinction between uppercase and lowercase while searching for regular expressions. The default is noic. linelimit(ll=) – Sets the maximum number of lines, as per the -y command – line option. This option is effective only if used with the .exrc file or the EXINIT environment variable. lisp(lisp) – Removes the special meaning of (), { }, [[, and ]] and enables the (formatted print) operator for s- expressions, so that edit list processing (LISP) programs. The default is nolisp. list (list) – Displays text with tabs (^I) and the marked end of lines ($). The default is nolist. magic(magic) – Treats the (period), [ (left bracket), and * (asterisk) characters as special characters when searching for a pattern. In off mode, only the () (parentheses) and $ (dollar sign) retain special meanings. However, we can evoke special meaning in other characters by preceding them with a (backslash). The default is magic. mesg(mesg) – Turns on write pemission to the terminal if set while in visual mode. This option only is effective if used with .exrc file or the EXINIT environment variable. The default is on. modeline(modeline) – Runs a vi editor command line if found in the first five or the last five lines of the file. A vi editor command line can be anywhere in a line. For the vi editor to recognize a command line, the line must contain a space or a tab followed by the ex: or vi: string. The command line is ended by a second: (colon). The vi editor tries to interpret any data between the first and nom odeline. novice – second colon as vi editor commands. The default is Indicates whether we are in novice mode. We can not change the value by using the set command. number (n u) – Displays lines prefixed with their line numbers. The default is nonu. optimize (opt) – Speeds the operation of terminals that lack cursor addressing. The default is noopt. partial char (pc=) – Appears in the last display column where a double wide character would not be displayed completely. The default character is – (minus sign). prompt – Prompts for a new vi editor command when in command mode by printing a : (colon). The default is on. readonly (ro) – Sets permanent read – only mode. The default is noreadonly. redraw – Simulates a smart workstation on a dumb workstation. The default is nore. remap – Allows defining macros in terms of other macros. The default is on. scroll (scr=) – Sets the number of lines to be scrolled when the user scrolls up or down. The default is 1/2 of the window size, rounded down. shell (sh=) – Defines the shell for the subcommand or the :! subcommand. The default is the login shell. Shiftwidth (sw=) – Sets the distance for the software tab stops used by the autoindent option, the shift commands and the text input commands. This vi option only affects the indentation at the beginning of a line. The default is Sw=8. showmode (smd) – Displays a message to indicate when the vi editor is in input mode. The default is nosmd. slow open (slow) – Postpones updating the display screen during inserts. The default is noslow. tabstop (ts=) – Sets the distance between tab stops in a displayed file The default is ts=8. tags (tags=) – Defines the search path for the database file of function names created using the ctags command. The default is tags=tags/usr/lib/tags. term (term=) – Sets the type of workstation you are using. The default is term=$TERM, where $TERM is the value of the TERM shell variable. terse (terse) – Allows the vi editor to display the short form of message. The default is noterse. timeout (to) – Sets a time limit of two seconds on an entry of characters. This limit allows the characters in a macro to be entered and processed as separate characters when the timeout option is set. ttytype – Indicates the tty type for the terminal being used. We cannot change this value from the vi editor. warn (warn) – Displays a warning message before the ! subcommand executes a shell command. The default is warn. window (wi=) – Sets the number of lines displayed in one window of text. wrapmargin(wm=) – Sets the margin for automatic word wrapping from one line to the next. The default is wm=0. A value of 0 turns off word wrapping. wrapscan (ws) – Allows string searches to wrap from the end of the editing buffer to the beginning. The default is ws. wraptype (wt=) – Indicates the method used to wrap words at the end of a line. We can specify one of the following four values:generalAllows wraps on word breaks as white space between two characters.wordAllows wraps on words.rigidAllows wraps on columns and before closing punctuation.flexibleAllows wraps on columns, but one character of punctuation can extend past the margin. writeany (wa) – Turns off the checks usually made before a write subcommand. The default is nowa. 4. Executing Unix commands in viAny UNIX command can be executed from the vi command line by typing an “!” before the UNIX command. Examples: “:!pwd”: shows our current working directory. “:r !date”: reads the results from the date command into a new line following the cursor. “:r !ls -l”: Place after the cursor, the current directory listing displayed as a single column. 5. Line NumbersLines may be referenced by their line numbers. The last line in the file can be referenced by the “$” sign. The entire file may be referenced by the block “1,$”or “%”. The current line is referred to as “.” A block of text may be referred to by its marked lines. i.e. 5,38 means block of line from line 5 to line 38. 6. SortingExample: Mark a block of text at the top line and bottom line of the block of text. i.e. “mt” and “mb” on two separate lines. This text block is then referenced as “t,’b. :’t,’b !sort 7. Moving columns, manipulating fields and awk:’t. !awk ‘{print $3 ” ” $2 ” ” $1}’ – This will reverse the order of the columns in the block of text. The block of text is defined here as from the line marked with the keystroke “bt” and the current line (“.”). This text block is referenced as “t,.” aaa bbb ccc ccc bbb aaaxxx yyy zzz becomes-> zzz yyy xxx111 222 333 333 222 111 8. Source Code Formatting: C++/Java Use vim visual text selection to mark the lines to format (beautify):eg. Whole file:Go to first line in file: shift-vGo to last line in file: shift-gSelect the key equals: = 9. Text Formatting: Mark a block of text at the top line and bottom line of the block. i.e. “mt” and “mb” on two separate lines. Example: “:’t,’b !nroff” We can insert nroff commands i.e.: .ce 3Center the next three lines.fiFill text – left and right justify (default).nfNo Fill.ls 2Double line spacing.spSingle line space.sv 1.0iVertical space at top of page space.nsTurn of spacing mode.rsRestore spacing mode.ll 6.0iLine length = 6 inches.in 1.0iIndent one inch.ti 1.0iTemporarily one tie only indent one inch.pl 8.0iPage length = 8 inches.bpPage break 10. Spell Checking Mark a block of text by marking the top line and bottom line of the block. i.i.“mt” and “mb” on two separate lines. :’t,’b !spell will cause the block to be replaced with misspelled words. Press “u” to undo. Proceed to correct words misspelled. 11. Macros:map letter commands_strung_together:map – lists current key mappingsExample – :map g n cwNEW_WORD{ctrl-v}{esc}i{ctrl-v}{CR} This example would find the next search occurrence, change the word and insert a line feed after the word. The macro is invoked by typing the letter “g”. Control/Escape/Carriage control characters must be prefixed with ctrl – V. Choose a letter which is not used or important. (i.e. a poor choice would be “i” as this is used for insert) 12. Double spacing:%s/S/{ctrl-V}{CR}/gThis command applies an extra carriage return at the end of all lines 13. Delete all lines beginning with or matching a pattern :1.$ /^#/dDelete all (first to last line: 1,$ or g) comment lines in file. Delete all lines beginning (^) with “#” (specify text pattern). :g/#/dDelete all lines (g) containing comments (comment follow”#”) in file. Delete all lines containing “#”. :g!/^#/dDelete all lines except (g! or v) comment lines beginning (^) with “#”. 14. Editing multiple files vi file1 file2 file3 :n Edit next file (file2) :n Edit next file (file3) :rew Rewind to the first file (file1) 15. Hyper – Linking to include files Place cursor over the file name (i.e. #include “file1.h”) Enter the letter combination: gf (go to file)This will load file file1.h into vim. Use the following entry in our ~/.vimrc file to define file paths. 16. Batch execution of vi from a command fileCommand file to change HTML file to lower case and XHTML Execute: vi e file name.html vim [vi Improved] vim is an advanced text editor that seeks to provide the power of the Unix editor ‘vi’, with a more complete feature set. It is useful whether we’re already using vi or using a different editor. Users of vim 5 and 6 should consider upgrading to vim 7. vim is a highly configurable text editor built, to enable efficient text editing. It is an improved version of the vi editor distributed with most UNIX systems. vim is often called a”Programmer’s editor,”and so useful for programming that many consider it an entire IDE. It is not just for programmers, though, is perfect for all kinds of text editing, from composing email to editing configuration files. As well as vim is a very powerful editor that has many commands, vim can be configured to work in a very simple (Notepad – like) way, called evim or Easy vim. vim is vi improved and has many advantages over standard vi. vim has been described by some as the Emacs of vi’s. We might want to refer to vim – Why? Because of vim features which include, comprehensive internal documentation, completion, multi undo, multi – buffer, split – screen and scripting support. vim also has a lot of support for programming, such as, macros for compiling and locating compilation errors, auto – indentation features and more. vim supports colours and can optionally provide a Graphical User Interface. There are many other clones of vi that may be of interest. These include nvi, elvis and viper – mode (vi – emulation mode in Emacs). vim is Not an Editorvim is not an editor designed to hold its user’s hands. It is a tool, the use of which must be learned. vim is not a word processor. Although it can display text with various forms of highlighting and formatting, it is not there to provide WYSIWYG editing of typeset documents. vim’s Licensevim is charityware. Its license is GPL – compatible, so it is distributed freely, but we ask that if we find it useful, we make a donation to help children in Uganda through the ICCF The full license text can be found in the documentation. vim in Six KilobytesIf all of this information is overwhelming, try a smaller dose. We can expound the wonders of vim in just six kilobytes and in more languages than we can shake a stick at ! vim is generally started with: -vim [option] [filelist] if the file list is missing, the editor will start with an empty buffer. Useful vim Features Support for Session :mksessionmySessionStore a session into the file mySession, so It can be used the next day.:so mySessionLoad (source) yesterday’s session.vim -s mySessionAlternative way to source mySession:setsessionoptionsWhat needs to be stored with :mksession and what doesn’t 2. Support for Views :mkview myViewStore the current view into file mySession:mkviewHave view determine the file (use :loadview when file re-opened):mkview 4Store up to 9 configurations per file:so myViewGet the view stored with :mkview myView Editing Technique (a) MapsMaps are a powerful features that recognizes specific sequences of keys and does something that would require more key presses. For example, I might define a map that is just mn and whenever type m, it is expanded to my email address.hasmapto Check if a specific map already exists. (b) Tabulators expandtabFills spaces when using the tabulator:set listchars=tab:<-Shows tabs as <- when using :list (c) Setting OptionsMore detailed help with :help options.txt. Get a table with a quick explanation on each option with help Q_op. :help cmdline-ranges 4. Globally(a) Per File Type BasisWhenever a new file is edited, see autocommands. :augroupTell me what autocommmand groups exist:filetype onEnables file type detection, by reading $VIMRUNTIME/filetype.viw. This file defines many, many autocommands, for exmple au BufNewFile, BufRead*.pl setf perl (b) Setting Options for a Particular FileIt is possible to set options for a specific file by including a line at the beginning of that file like this: // vim: shiftwidth: 44. When the file containing such a line is opened, the shiftwidth for that file is set to 44. Note that only set commands are allowed in order to prevent trojan horses. :set modelineEnable the feature, don’t forget :set modelines=xxx:set modelines=5Check the first five lines in a file for vim: 5. Searching:set incsearch Search incrementally 6. Initializationgvim -u NONE -U NONE bhu.txt Do not read no stinky vimrc, gvimrc, and plugin files 7. Scripts function! Name()Defines a function, functions’s first letter must be capitalized, end function with endfunctionexe “normal iString”Prepend typing in Normal Modeexe “%s/X/Y/”Substituting in a function 8. Variableslet i = input (‘bhu’) Ask for foo, assign to i 9. Miscallany :set ff=unix, dosFileformat (end of line):set ffs=unixfile formats:set lazyredrawUseful for macros: the screen will not be redrawn if a macro is runningctrl-fIf pressed in command mode: pops up a window to edit the history Computer Science Tutorials Linux computer scienceLinux