To remember search patterns and use it in the replacement text, for example, given a list of numbers that you want to right-justify, usp001: 19 usp002: 0 usp004: 1 usp006: 45 usp007: 76 usp008: 126 usp009: 185 ... Issue these two global replacement commands, :%s/: \([0-9]\)$/: \1/ <-- Fixes the single-digit numbers :%s/: \([0-9][0-9]\)$/: \1/ <-- Fixes the double-digit numbers ---------------------------------------------------------------------------------- To remove trailing Carriage Returns (displayed as ^M) from the end of lines, try :1,$s/ctrl-vEnter$// where ctrl-v is what you think it is, followed by the enter key. The ctrl-v sequence shows you the following on the screen, for the given key. See the "Character Set" appendix 22 in the ksh book. As Displayed As Displayed on Screen on Screen The Key to Type After With nolist With list Pressing ctrl-v ASCII Character Hex ============ ============ ================================ =============== === ^A ^A ctrl-a 01 ^B ^B ctrl-b 02 ^C ^C ctrl-c 03 ... ^G ^G ctrl-g Bell 07 ^H ^H ctrl-h or backspace Backspace 08 spaces ^I ctrl-i (or tab key w/o ctrl-v) Tab 09 new line $ ctrl-j (or enter key w/o ctrl-v) Line Feed 0a ... ^M ^M ctrl-m or enter (not ctrl-enter) Carriage Return 0d ... ^Z ^Z ctrl-z 1a ^[ ^[ esc Escape 1b ---------------------------------------------------------------------------------- When using the script command, you'll get funny ^H characters where you mistyped on the command line, and backspaced back over it to clean it up. To clean that up is a little bit complicated as each time you hit backspace, you get "^H ^H^H" after the character you were trying to delete. For example, this was the word "test" followed by 4 backspaces, then the word "real". test^H ^H^H ^H^H ^H^H ^Hreal To clean that up when vi-ing the script'd file, try this vi command :1,$s/.ctrl-vBackspace ctrl-vBackspce// which will clean up just the first backspace (the one for the letter t). I can't find a way easily to do all backspaces in a single line. The command doesn't work as I'd like. What you can do is to map a function key to that string with this command :map #9 :1,s/.ctrl-vBackspace ctrl-vBackspace//ctrl-vEnter and hit PF9 repeatedly until all occurances are gone. You'll get the msg No match exists for the substitute pattern. ---------------------------------------------------------------------------------- Use the :set list option to display ^I instead of tabs (x'09') ^M instead of CR (x'0d') $ instead of LF (x'0a') Normal Unix Line Ending ^M$ instead of CR/LF (x'0d0a') Normal Windows Line Ending ---------------------------------------------------------------------------------- To convert a file from normal Unix line endings (just LF), to normal Windows line endings (CR/LF), use Carol's fixcrlf utility in /local/bin. To add trailing LF's, fixcrlf -t +r I couldn't get vi to change more than one line at a time. I could do an A, then ctrl-v, but I couldn't do multiple lines at a time with for example, :%s/$/ctrl-v/ <---- Doesn't work. or :%s/$/ctrl-v&/ <---- Doesn't work. ---------------------------------------------------------------------------------- To customize vi, putting in your own defaults, especially for PF keys, create a .exrc file in your home directory. For example, my ~/.exrc file is (yes, comments and all) " This maps the Function keys to different, useful things. :map #1 % :map #2 $ " The following isn't THAT useful, but I needed it one day. :map #3 :set number :map #4 :set nonumber " Setting shiftwidth=2 and function keys 5-7 to shift left & right, " is very useful when editing Perl scripts, for example. :set shiftwidth=2 :map #5 <<<< :map #6 << :map #7 >> :map #8 >>>> :map #9 j0. :map #10 jh0. :map #11 j. :map #12 jx " The Home key is already mapped to H (go to the top of the screen). " Here, we map the End key to its opposite, go to the bottom of the " screen and all the way to the end of the line. " The ^[[146q was entered by ctrl-v. :map  L$ " My preferred defaults. Ignorecase and don't wrap while scanning. :set ic :set nowrapscan --------------------------------------------------------------------- To edit a file that has more than 1,048,560 lines, use the -y vi option, specifying at least twice the number of lines your file has. For example, to edit a 2,000,000-line file, say vi -y4000000 name-of-your-big-file