marvim

MAcro Repository for VIM
"Freeze? I'm a robot, not a refrigerator" - Marvin the Paranoid Android

 Version 0.4 Beta

Subscribe, send bugs or patches:

chamindra [at] gmail.com

Please also share your macro repositories with me so that I can share them :-)  

Acknowledgements

  • Bram Moolenaar and the VIM community for a fantastic editor
  • Anuradha Weeraman for the namespace idea

 "Give your most complex macros a name and store it for future recall and use"

New in 0.4/0.3:

  • New auto (tab) complete functionality on searching for macros
  • Supports namespaces with the default taken from the type of file you are editing

Problem statement(s):

  • Can't remember those complex VIM macro sequences you use frequently?
  • Wish you could save those macros beyond your immediate session? 
  • Wish you could share your VIM macros with each other? 
  • Why not templates as well in the same script?

Features:

  • Recording of VIM macros and templates into persistent storage for future use
  •  Auto-complete based recursive search and load of stored VIM macros
  • Visually select and save templates into persistent storage
  • Macro namespaces, to permit organization of macros 
  • Support for a default namespace based on filetype
  • Supports a shared macro repository for a team on a shared directory
  • Macro menu items in GVIM version for all main actions

Hotkeys: 

  • <F2> - Find and execute a macro or insert template from repository
  • Visual <F2> - Replays last macro for each line selected
  • <F3> - Save default macro register by name to the macro repository 
  • Visual <F3> - Save selection as template by name to the macro repository 
  • <Tab> - On the Macro command line for cycling through autocomplete
  • <Control>+D - On the Macro command line for listing autocomplete options

Usage with Default Hotkeys:

 o Store a new macro to the repository

  1. Record macro as usual into q registe
    (i.e. qq..<macro keystrokes>..q)
  2. Press save macro key <F3> (default) in normal mode
  3. Enter the macro name when prompted after the prefix
    (a prefix will be provided based on the filetype)
  4. Macro is now store in the repository

o Save template into repository

  1. Select area you want to save in visual mode
  2. Press the macro save button <F3> (default) in visual mode
  3. Enter the template name when prompted
    (a prefix will be provided based on the filetype)
  4. Template is now saved in repository

o Recall macro/template through a search

  1. Press the macro find key <F2> (default) in normal mode
  2. Enter a search string when prompted
    (a prefix will be put by default, which can be deleted)
  3. Press <Tab> or <Control-D> to auto-complete until you find the macro
  4. Macro is now run and also loaded for further use into the q register

o Replay last loaded macro on multiple lines for each line

  1. Select the area you want the macro to run on in visual mode
  2. Press the macro find key <F3> (default) in visual mode
  3. Macro in q register is replayed for every line

Note: Recommend customize <Space> to be you find macro key. This then become very efficient. See how to do this below. 

Macro Namespace:
You can organize the macros by a namespace. To save a macro in the name space X, simply us X:macro_name when saving the macro. This will create a subdirectory called X in your mavim repository as save this macro there. You can also create namespaces by putting a collection of macros in a subdirectory of the mavim repository. This will permit you to organize your macros accordingly

Changing the default hotkeys, repository and macro register
Optionally place the following lines in your vimrc before the location you source the marvim.vim script (don't worry about location if the script is in the vim plugin directory).  Below is an example:     

  let marvim_store = '/usr/local/share/marvim/'
  let marvim_find_key = '<Space>'

  let marvim_store_key = 'ms'
  let marvim_register = 'c'
  source $HOME/marvim.vim  

Tips

  • <Space> can be very effective as the macro find key
  • use a naming convention for your macros to make it easy to find. e.g.:

   php:if-block
   php:strip-tags
   php:mysql-select-block
   php:mysql-update-block

  • If multiple people are working on the same project, consider a shared marvim store to share templates and macros to improve team 
  • Share your marvim marco stores with each other


If you like it please send patches, template/macro repositories and improvements to the script :-)