-1

I normally use VIM but have to fiddle with files in VI. Does the vi on Solaris 2.5 have history I can recall to re-use commands? It's a pain to retype complete lines sometimes. In VIM I can go ESC, ESC, Up-Arrow.

4

No, there is unfortunately no history support in the SVR4 release of vi.

Note it is not vi version 4 but "Version SVR4.0, Solaris 2.5.0". This version string is hardcoded and reported even in recent releases (Solaris 2.5 is something like 18 years old).

Starting from Solaris 11, vim is bundled with the OS.

0

It's possible to replay keystrokes in vi as a macro, if this is sufficient for your needs. This can be done in two ways.

In both cases, I'll lead with similar content for vim and then differentiate for vi.

1. Register Macros

These are captured and replayed interactively.

1.1 vim

Recall that in vim, a macro is created by recording a series of keystrokes to a register in recording mode (reached from command mode). Then the macro is executed by executing the contents of the register.

qa                # 1. Enter recording mode, will save to register "a.
  ihello<esc>     #    Type key strokes to insert string "hello".
             q    #    Return to command mode.

@a                # 2. Execute contents of register "a (insert "hello").

@@                # 3. Repeat last macro execution (insert "hello").

As the question is asked, these steps wouldn't be utilised in vim, rather you'd use the application's command histories.

1.2 vi

In vi, step 1. above is performed in a different way: the macro contents must be typed in a buffer in insert mode and then yanked/copied/etc into a register.

i                            # 1a. Enter insert mode.
 ihello<ctrl-v><esc>         #     Type key strokes to insert string "hello", escaping necessary keys.
                    <esc>    #     Return to command mode.

"aY                          # 1b. Yank entire line to register "a (macro text should appear on a line by itself).

@a                           # 2. Execute contents of register "a (insert "hello").

@@                           # 3. Repeat last macro execution (insert "hello").

2. Key Mappings

These can be captured interactively or in the appropriate *rc file.

When executing a mapping, both vim and vi wait 1 sec (default) to accept all keystrokes that constitute the mapped word.

2.1 vim

:cmap lhs rhs<enter>    # Map rhs-words to lhs-word for command-mode mappings.
:imap lhs rhs<enter>    #                           for insert-mode mappings.
:map! lhs rhs<enter>    #                           for command- and insert-mode mappings.
:map  lhs rhs<enter>    #                           for normal-mode mappings.
:nmap lhs rhs<enter>    #                           for strict normal-mode mappings.
                        # Escape necessary keys in lhs and rhs.
                        # lhs "#n" means function key "n"
                        # Use vim's extensive symbolic key names.

:vmap                   # Other variants
:xmap
:smap
:omap
:lmap

:unmap lhs              # Remove map
:nunmap                 # Other variants
:vunmap
:xunmap
:sunmap
:ounmap
:unmap!
:iunmap
:lunmap
:cunmap

2.1.1 Example

Make the q key write and exit the editor, exploiting vim's symbolic key names.

:nmap q :wq<CR><enter>     # <CR> is typed as 4 chars, <enter> as 1.

2.2 vi

:map  lhs rhs<enter>    # Map rhs-words to lhs-word for command-mode mappings.
:map! lhs rhs<enter>    #                           for insert-mode mappings.
                        # Escape necessary keys in lhs and rhs.
                        # lhs "#n" means function key "n"

:unmap lhs              # Remove map

2.2.1 Example

Make the q key write and exit the editor.

:map q :wq<ctrl-v><enter><enter>

References

  1. The vim documentation, eg: here.
  2. An Introduction to Display Editing with Vi, by the authors of vi, eg: this PDF.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.