------------------------------------------------------------------------------- Escaping Control Characters The first results are in on my question about character quoting in ex/vi. The table below shows what I've learned from e-mail, and a few tests. Please check it out, and let me know of any errors or omissions. ex vi .exrc characters to quoted \ \ ^V The | command separator \ ^V n.a. Special control characters on any command line ^V ^V^V ^V Whitespace in a :map or :unmap command \ \ \ Whitespace in a :set command \ \ \ Meta-characters in a regexp or substitution text \ \ \ The %, #, and ! characters in a shell escape/filename The "ex" column refers to command lines that are interactively typed into ex, or for ex macros executed via ":@x". The "vi" column refers to ex command lines that are interactively typed using vi's ":" command. It also works for vi macros/maps which use ":". Please note that when you're defining the macro, though, you'll need to quote any ^Vs to delay their effect until the macro is applied. Also, to quote a whitespace character in a :map command, you need to actually insert a ^V into the command line, which is done by hitting ^V twice. The ".exrc" column refers to commands in the .exrc file, or a file which is executed via the ":so" command, or for the value of EXINIT. The quoting character for special control characters is different, but this is probably due to the serial line discipline, and not so much ex/vi itself. This also explains why ^V must be typed twice in vi but only once in ex, to quote whitespace in a :map. Bearing this in mind, the quoting character is consistent in all contexts except when the '|' command separator is to be quoted in .exrc files. ------------------------------------------------------------------------------- VI Bugs NOTE: ^M are really CTRL-M inserted using CTRL-V * visual put fails after buffer exec, delete to buffer sequence. After using a execute buffer (EG: @x) and a delete to buffer (EG: "add or :d a^M) the visual put command (EG: "ap) will just `beep'. It does not give the normal error of `nothing in register a' so it is a bug. Using the ex put command (AFTER the current macro is finished) however will work, and will unlock the bug. (See the next error) * Ex put command will not undo correctly. While the ex put works, the undo seems to leave the last line of the putted text. Undo again will then only make matters even worse. Visual put seems to work correctly, except after the above bug. Solution: create a paste macro with unlocks the above error then performs a visual put of the wanted text. Example: put from buffer a :map #V mz"xdd:-put x^M"ap`z * A macro can not consist of just a single macro call Example This (a paste shortcut) WILL NOT WORK. :map V #V But this will. :map V #V`z ------------------------------------------------------------------------------- Do not EVER nmap any of the following characters as they are commonly used for internal macros or for other macros airuhjkl :0_$"`' SPACE ESC and maybe \ while these are too usful to be mapped dfwx ADGIRXY .%!{}<>~ ^S ^Q ^M ^J ^L also don't map any other character you use in your own macros The following characters are recommended as macro prefix characters #* Z These characters are also commonly used for maps especially temporary macros for special purposes gq ABCMNQTVWXZ -=+|/ ------------------------------------------------------------------------------- Unusal Mapping errors (like Y not working) This is caused by the | character being not being escaped by a ^V This character is the command separator. example :map A :'a,'b s/^/| / ------------------------------------------------------------------------------- mapping space or tab keys for macros The space and tab keys can be mapped by escaping them example ,--more than one space :map  space_macro :map ^I tab_macro NOTE on some systems you have to double escape these characters (SVR3.1) :map  space_macro FUTHER some systems us space in some of its internal mappings for example s is mapped to `c ', so watch it. In vim you can use key names (which may actually be multiple keys) :map <space> space_macro ------------------------------------------------------------------------------- Deleting 'd' command Vi distinguishes "line" moves and "character" moves. If you apply the 'd' operator to a line move, vi deletes the starting line, the target line and all intervening lines. If you apply the 'd' operator to a character move that ends on a different line, then parts of the starting and target line not moved over are not deleted. The '/' operator usually produces character moves, but the "+0" suffix makes it a line move. :d/foo/0 You can replace the "0" by an other line count, :d/foo/+3 deletes line up to and including the third line following the next occurrence of "foo"; and :d/^\\/-1 deletes that line and the line before. Actually, you can save one more keystroke: the '1' is optional, so :d/^\\/- would also work. FWIW the '+' is also optional. And you can type several of these offsets, e.g. :d/foo/++ is equivalent to :d/foo/+2 Finally, there is the possibility to tack on another search: :d/foo/;/bar/ deletes up to (but not including) the first occurrence of "bar" after the next occurrence of "foo". Oh, and all trailing delimiters are optional. -------------------------------------------------------------------------------