In short, most arguments about text-editors are matters of opinion. Being rather open to opinions and able to decipher rubbish versus honest-facts, I figured that this would be an excellent topic to stretch my fingers with. Rather than going 100% off of my personal editing preferences, I am going to build a table of how to perform certain actions of editing from within a few of my favourite editors and let you decide what you prefer. Likewise, this will allow me to have an easy reference for those (rare?) times when I forget how to do things.
I attempted to put the more "standard" commands near the top; however, attempting to group like commands (like all of the different types of cut-to-memory commands) has made this a bit verbose. More is better with this type of information though, so I find being a little bit longwinded with variations here is good, as anyone looking at this page should be well smart enough to figure out how to use their browser's search function to find the portion they wish to view.
This document just doesn't do justice to folks truly trying to learn vi. You should also check out my learning vi document.
|
The formatting here is simple enough to understand (I would hope). ^ means ctrl+, so ^x is ctrl+x. M- means meta (generally left-alt or escape)+, so M-x is left-alt+x
|
| Action | ed | vi(m) | emacs | nano | joe |
| quit editor | q | :q | ^x ^c | ^x | ^c |
| quit without prompting to save changes made | Q OR qq | :q! | M-x kill-emacs | | |
| open file foo.bar | e foo.bar | :e foo.bar | ^x ^f foo.bar | | ^k e foo.bar |
| write file to disk | w | :w | ^x ^s | ^o | ^k s |
| write file copy to disk | w /path/filename | :w /path/filename | ^x ^w | | |
| write file and exit | wq | :wq OR ZZ | ^x ^s ^x ^c | ^o ^x | ^k x |
| undo previous command (that affected buffer) | u | u | ^x u OR ^_ | | ^[shift] - |
| undo last commands that affected current line | | U | | | |
| re-do an undo: | | ^R | | | |
| insert text | | i | | | |
| append text | | a | (start writing) | (start writing) | (start writing) |
| append text at end of line | | A OR $a | | | |
| insert line | i (end with . or ^d) | O | ^o | | |
| append line | a (end with . or ^d) | o | | | |
| move to beginning of line | | 0 | ^a | | ^a |
| move to first non-whitespace of line | | ^ OR _ | | | |
| move to first non-whitespace of next line | | + OR ^m | | | |
| move to first non-whitespace of prior line | | - | | | |
| move to end of line | | $ OR A | ^e | | ^b |
| force write (if read-only but owned by user) | | :w! | | | |
| print | | :hardcopy (vim) | M-x print buffer | | |
| enable syntax hilighting | | :syntax on (vim) | M-x font-lock-mode | | |
| cut a line to memory | d | :d OR dd | ^[space] at beginning of line ^e to move to end of line ^w to cut selected area OR ^a ^k | ^k | |
| visual cut to memory | | v (highlight area (hjkl etc)) d | ^[space] at beginning of area arrows to move to end of area ^w to cut selected area | ^6 to start select ^k to cut | |
| cut current character to memory | | x | | | |
| cut preceeding character to memory | | X | | | |
| cut from cursor to end of line to memory | | D OR d$ | | | |
| cut from cursor to beginning of line to memory | | d0 OR d^ | ^@ ^a ^w OR ^[space] ^a ^w | | |
| cut from cursor to end of word to memory | | dw (to include following whitespace) OR de (to cut only word) | M-d | | |
| cut from cursor to beginning of word to memory | | db | | | |
| cut # words to memory | | d#w | | | |
| cut multiple lines | | :d# OR #dd (where # is the number of lines to cut) | ^[space] at beginning of line ^n to go to next line ^e to move to end of line ^w to cut selected area OR M-1 M-2 ^k (cuts 12 lines) OR ^k (repeat for all lines to be cut) | ^k (repeat for all lines to be cut) | |
| replace current cursor letter with X | | rX | | | |
| replace word from cursor position | | ce | | | |
| replace # words from cursor position | | c#w | | | |
| replace from cursor position to end of line | | c$ | | | |
| mark a position | | mX where X is [0-9a-zA-Z] | M-x bookmark-set OR ^x r m OR M-x set-mark-command OR ^@ | | |
| move cursor to marked position | | `a | M-x bookmark-jump OR ^x r b OR ^x ^x | | |
| return to point prior to going to marked position | | | ^x ^x | | |
| move cursor to first non-whitespace on line with mark X | | 'X | | | |
| delete from marked position to cursor | | d`X | | | |
| paste a line from memory | | p OR :p (below current line - pending mode) P OR :P (above current line - pending mode) | ^y | ^u | |
| append next line to current line (join) | j | J | | | |
| search for prior text string | | $string | ^r | | |
| search for next text string | /string | /string | ^s string | ^w string | ^k f |
| move cursor to next occurrence of string | | / OR n | ^s | | |
| move cursor to prior occurrence of string | | N | | | |
| print all occurrences of string | g/string OR g/string/p | g/string | | | |
| find and replace the first occurrence of stringA with stringB on current line | s/stringA/stringB | :s/stringA/stringB | | | |
| find and replace all occurrences of stringA with stringB on current line | s/stringA/stringB/g | :s/stringA/stringB/g | | | |
| add "confirmation" to each find/replace for multiple occurrences | | append "c" after /, e.g., s/stringA/stringB/gc | done by default | | |
| find and replace all occurrences of stringA with stringB | %s/stringA/stringB/g OR ,s/stringA/stringB/g | :%s/stringA/stringB/g | M-% stringA stringB ! | ^\ stringA stringB a | |
| find and replace all occurrences of stringA with stringB from line X to line Y | X,Ys/stringA/stringB/g | :X,Ys/stringA/stringB/g | | | |
| find and replace all occurrences of stringA with stringB from line X to last line | X,$s/stringA/stringB/g | :X,$s/stringA/stringB/g | | | |
| find and replace all occurrences of stringA with stringB from current line to last line | .,$s/stringA/stringB/g | :.,$s/stringA/stringB/g | | | ^k f [stringA] r [stringB] r |
| move cursor to line # | # | :# OR #G | M-g g # OR M-x goto-line # | ^_# | ^k l# |
| print current line # | n | ^g | | | |
| move cursor to character "mate" (e.g., other closing/opening brackets - good for programming) | | % | ^M-f and ^M-b | | |
| move cursor left one character | | h | ^f | | ^b |
| move cursor right one character | | l | ^b | | ^f |
| move cursor up one line | - | k | ^p | | ^p |
| move cursor down one line | [enter] OR + | j | ^n | | ^n |
| move cursor up X lines | -X OR ----- (where number of -'s = X) | Xk | ^u X ^p | | |
| move cursor down X lines | +X OR +++++ (where number of +'s = X) | Xj | | | |
| move cursor left X characters | | Xh | | | |
| move cursor right X characters | | Xl | | | |
| move cursor right one word | | w | M-b | | |
| move cursor left one word | | b | M-f | | |
| move cursor to bottom of screen | | L | | | |
| move cursor to middle of screen | | M | | | |
| toggle case of current character | | ~ | | | |
| access help | h | :h OR :help | ^h ^h | | ^k h |
| toggle help/error message display | H | | | | |
| access tutorial | | vimtutor (vim only, separate stand-alone) | ^h t | | |
| print all lines in file | ,p | | | | |
| print from current line to line Y (any set current line to Y) | .,Yp | | | | |
| print from line X to line Y (and set current line to Y) | X,Yp | | | | |
| print from line X to last line (and set current line to last) | ;p | | | | |
| split editing window horizontally | | | ^x 2 | | |
| split editing window vertically | | | ^x 3 | | |
| remove all window splits (1 window) | | | ^x 1 | | |
| switch to next window | | | ^x o | | |
| sort file | | :sort | | | |
| go to next page | | | ^v | | |
| go to previous page | | | M-v | | |
| center screen on cursor location | | | ^l | | |
| go to beginning of document | | 1G OR :1 OR gg | M-< | M-\ or M-| | |
| go to end of document | | G | M-> | M-/ or M-? | |
| replace current buffer with output of command | | :%!command | | | |
| execute command from within editor | | :!command | | | |
| print current line (line-editor style) | p or . | | | | |
| start irc client | | | M-x irc | | |