1

I need to do lots of search and replace commands, and I might re-use these commands soon. I know I could use q: to select the previous commands but there are some other dummy commands inside and I need to search the wanted commands again. That's not efficient.

Are there ways or plugins that I could save those frequently-used commands into a specific buffer and I can choose one of them quickly?

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Ted Huang
  • 15
  • 4
  • 1
    Using vim "recording" could be an alternative way to do this. However, it better shows the full list of each recording command and I can choose them fast. – Ted Huang Dec 07 '19 at 07:57
  • Does this answer your question? [Vim: How to execute selected text as vim commands](https://stackoverflow.com/questions/4268532/vim-how-to-execute-selected-text-as-vim-commands) – mkrieger1 Dec 07 '19 at 11:03
  • 1
    Generally thats what mappings/registers are for... – D. Ben Knoble Dec 07 '19 at 14:20

1 Answers1

1

This looks like a fair job for a whole plugin, as Vim does not track commmands' "frequency usage".

However, you can make some sort of a "poor man" solution instantly:

  1. Create a temporary buffer (or use some sort of a "scratch" plugin).

  2. Whenever a "useful" command was issued, go to your "scratch" buffer and add the content of a register : into it. For example, ":P.

  3. To execute a "useful" command you'll need a mapping:

    nnoremap <buffer><CR> 0y$<C-W>p:<C-R>0
    

    I.e.: copy current line; switch to previous window; open cmdline and put yanked text there.

Now go to your "scratch" buffer and press Enter to compose a command-line.

To develop this stuff into "production-ready" form consider the following changes:

  1. Design some sort of cool UI instead (buffer-based or popup-based).

  2. Trap CmdlineLeave to automate command list tracking.

  3. Add buffer-mappings automatically.

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Matt
  • 13,674
  • 1
  • 18
  • 27