ex/vi/nvi editor: .exrc file (config file) advanced topics (undocumented?): Adding comments, escaping the pipe, mapping key combinations

This config file is usually located in your home directory: /home/user_name/.exrc

Let's use my actual .exrc file for reference:

exrc.png

Comments: Any line that begins with a double quote (or blank spaces + double quote) is treated as a comment.

Escaping command separators (pipes '|'): The command separator is the pipe ('|'). You can write several commands in the same line separating them with pipes. To include the pipe as part of one or your commands, as is the case with my third and fourth macros, you have to escape it by pressing Ctrl+V twice and then the pipe character. You can only do this using the very vi/nvi.

Mapping key combinations: To assign a macro to a key combination like Ctrl+End, you have to press Ctrl+V once and then the key combination, in this case Ctrl+End.

I've bumped into what seems a very advanced .exrc file here:
http://urbanjost.altervista.org/LIBRARY/public_html/VI/exrc_files/exrc_ADVANCED.html
 
Dumb suggestion: Add comments!
In my .*rc files I add comments (even for the obvious ones). The reason why is because in 6 months when I am fixing a stupid thing, I will just open my .*rc file which contains a thousand lines I just do a search for what I think is the problem. -e.g. "I want to turn off wrapping." Open my rc file and "/wrapping". or "/wrap". Having a comment gives me twice as many chances of finding what I want (you will not find "set nu" with "/nu", you will search for "/numbers").

Code:
set wrap
" turns text wrapping on

set linebreak
" turns line breaking on

set nu
" shows line numbers
 
Just for fun:

Vi macros that emulate old WordStar block commands

Content of the file:
Code:
" ---------------
" WordStar Blocks v2
" ---------------
set keytime=10
" Ctrl+b = Mark beginning of block
map ^Kb i·BB·^[
" Ctrl+K k = Mark end of block
map ^Kk i·EE·^[
" Ctrl+K c = Copy block to the cursor position
map ^Kc /·BB·^M4x"wy/·EE·^Mi·BB·^[``"wP
" Ctrl+K y = Delete marked block
map ^Ky /·BB·^M4xd/·EE·^M4x``
" Ctrl+K v = Move block to th^S^Se cursor position
map ^Kv /·BB·^M4x"wd/·EE·^M4x``i·BB··EE·^[3h"wP
" Ctrl+K h = Unmark block
map ^Kh :%s/·EE·//g^M:%s/·BB·//g^M

To include them in your own .exrc you cannot copy-paste!!! the previous code because vi saves binary codes in the file.

To use them at your own risk, you must:
  1. Download the attached file .uuexws.zip
  2. From it. extract the file .uuexws
  3. In the terminal, execute the command: uudecode .uuexws
  4. The file .exws will be generated automatically. You can edit this one using vi to copy the commands to your own .exrc file.
What you MUST know about the macros:
  • They use the named buffer w to do their stuff, so don't use it.
  • They mark the current block using the groups of characters ·BB· and ·EE· so don't use them.
Known limitations:
  • Any operation done incompletely or in an incorrect order will result in who knows what.
  • Therefore, for the macros to work, you must mark the beginning of a block, then the end, then copy it many times, or move it many times, or delete it one time, or unmark it.
  • The beginning of the block must appear in your file before the end of the block.
  • If the block includes complete lines, and you move it, the movement will be done fine, but the new marks (that move with the block) will appear both after the block.
Use at your own risk! ?

Better yet: use them as a learning material and make your own macros. ?
 

Attachments

Back
Top