.nr HM 0.7i .nr FM 0.5i .if n \{\ . ds CH " . ds CF " . nr HM 0 . nr FM 0 .\} .TL Vi for nano users .AU markus schnalke (Inspired and motivated by Toni Mueller) .AE .if t .2C .SH Motivation .LP Vi is a powerful editor and hence frequently used by professionals. Novices often use nano which is known to be a ``small and friendly'' text editor. This document wants to show that learning the basics of vi is not much harder than learning nano, especially if vim is used. .SH The modal interface .LP Learning vi means understanding its modal interface which is its basic concept. It makes vi ``strange'' but powerful. Once having understood the modal interface the rest will be easy. .PP When you startup vi you'll always find yourself in the \fBcommand mode\fP, the central mode. Hitting the `\f(CWEscape\fP' key brings you always back to the command mode. .PP To insert text you need to switch to \fBinsert mode\fP. You can do this by hitting `\f(CWi\fP' (insert before cursor) or `\f(CWA\fP' (append to end of line). When you have finished editing, `\f(CWEscape\fP' to command mode. .PP The \fBex mode\fP covers administrative operations. You enter it by typing `\f(CW:\fP'. See the colon appearing on the last terminal line. `\f(CW:w\fP' writes the file out, `\f(CW:wq\fP' writes and quits, `\f(CW:q!\fP' quits without saving. `\f(CWEnter\fP' executes the operation, `\f(CWEscape\fP' aborts it. In both cases you return to command mode (or to the shell in case of quit). .if n .ig @@ .PS .ft CW .ps -2 [ boxwid=0.9*boxwid boxht=0.9*boxht INS: box "\fRinsert\fP" "\fRmode\fP" move down from INS.s CMD: box wid boxwid+0.04 ht boxht+0.04 "\fRcommand\fP" "\fRmode\fP" move down EX: box "\fRex\fP" "\fRmode\fP" line <- left from CMD.w box "\fRSTART\fP" invis wid 0.6*boxwid line -> up from 1/3 "i " rjust "A " rjust line <- up from 2/3 " Escape" ljust line -> down from 1/3 ": " rjust "/ " rjust line <- down from 2/3 " Escape" ljust " Enter" ljust box invis wid 0.1 with .w at CMD.e "n N" ljust "u G" ljust box invis wid 0.1 with .w at EX.e ":w :wq" ljust ":q!" ljust box wid boxwid ht boxht with .c at CMD.c ] .PE .@@ .if t .ig @@ .DS +----------+ | insert | | mode | +----------+ ^ | i | | Escape A | | | v ############ START -----> # command # n N # mode # u G ############ | ^ : | | Escape / | | Enter v | +----------+ | ex | :w :wq | mode | :q! +----------+ .DE .@@ .SH Cursor movement .LP This is easy if you use vim: The cursor keys and PgUp/PgDn work both in command and insert mode. With vi you can only move the cursor in command mode with: `\f(CWh\fP' (left), `\f(CWj\fP' (down), `\f(CWk\fP' (up), `\f(CWl\fP' (right), `\f(CWCtrl-f\fP' (page forward), and `\f(CWCtrl-b\fP' (page backward). .if n .ig @@ .RS .PS .ft CW .ps -2 [ boxwid = 0.2 boxht = 0.2 linewid = 0.15 lineht = 0.15 arrowhead = 2 arrowwid = 0.1 H: box "h" move 0.1 J: box "j" move 0.1 K: box "k" move 0.1 L: box "l" arrow left from H.w arrow down from J.s arrow up from K.n arrow right from L.e ] .PE .RE .@@ .if t .ig @@ .DS ^ +---+ +---+ +---+ +---+ <-| h | | j | | k | | l |-> +---+ +---+ +---+ +---+ v .DE .@@ .SH Additional important functions .LP To search for text (regular expressions, actually) hit `\f(CW/\fP' in command mode, insert a pattern, then hit `\f(CWEnter\fP'. This moves the cursor to the next match. You can jump from match to match with `\f(CWn\fP' (forward) and `\f(CWN\fP' (backward). .PP To jump to a specific line type the line number (it's not printed anywhere) and `\f(CWG\fP' in command mode. `\f(CW1G\fP' means the first line, `\f(CWG\fP' without number means the last line. .PP To undo the last change hit `\f(CWu\fP'. It depends on your implementation if you have multiple undo steps or just one. .SH Why vi and not simply nano? .LP .I "Because vi is omnipresent and because vi scales well when you advance. .PP Edit files more efficient! With vi you can incrementally learn further functions and shortcuts that improve your productivity. .PP This document shows only how to access the vi features that typical nano users usually use. Using vi on this level is hardly better than using nano, but it is the basis for mastering vi. .PP The command mode offers a lot of functions you'll never want to miss once you've learnt them. Professional users are able to do really impressive operations in ex mode, too. Actually, vi is two powerful editors in one: ex and vi. .LP .B "Learn vi, you won't regret it!