All Projects → vim-scripts → Cmdalias.vim

vim-scripts / Cmdalias.vim

Create aliases for Vim commands.

Labels

Projects that are alternatives of or similar to Cmdalias.vim

Vim Fenced Code Blocks
Edit fenced code blocks inside a GitHub Flavor Markdown in a better way.
Stars: ✭ 13 (-51.85%)
Mutual labels:  viml
Morrowind
ports of the tango-based gedit "Oblivion" theme to other editors/ides
Stars: ✭ 14 (-48.15%)
Mutual labels:  viml
Vim Jade
Vim syntax highlighting for the Jade templating engine.
Stars: ✭ 21 (-22.22%)
Mutual labels:  viml
Dotfiles
All my bash / vim / ... stuff
Stars: ✭ 13 (-51.85%)
Mutual labels:  viml
Vim Americanize
Auto-"correct" British spellings to their American equivalent.
Stars: ✭ 14 (-48.15%)
Mutual labels:  viml
Maven Ide
maven-ide plugin
Stars: ✭ 15 (-44.44%)
Mutual labels:  viml
Vim Unite Watson.vim
vim-unite-watson.vim is the unite source for watson.
Stars: ✭ 13 (-51.85%)
Mutual labels:  viml
Vim Monokai Refined
Port of Monokai Refined for TextMate/Sublime Text, using sickill's Coloration converter
Stars: ✭ 27 (+0%)
Mutual labels:  viml
Hl matchit.vim
highlighting match of matchit.vim
Stars: ✭ 14 (-48.15%)
Mutual labels:  viml
Vim Notebook
Vim plugin to annotate text, source code, etc
Stars: ✭ 21 (-22.22%)
Mutual labels:  viml
Pyscratch
Makes Vim into a "scratchpad" tool for Python, Ruby, Perl, and/or Lua
Stars: ✭ 13 (-51.85%)
Mutual labels:  viml
Dotfiles Vim
My ultimate vim productivity suite!
Stars: ✭ 14 (-48.15%)
Mutual labels:  viml
Doxygentoolkit.vim
Doxygen plugin for vim
Stars: ✭ 20 (-25.93%)
Mutual labels:  viml
Toby.vim
My personal VIM setup
Stars: ✭ 13 (-51.85%)
Mutual labels:  viml
Vim Refact
Some refactoring stuff for Vim
Stars: ✭ 21 (-22.22%)
Mutual labels:  viml
Ctrlp.vim
Fuzzy file, buffer, mru, tag, etc finder.
Stars: ✭ 7,070 (+26085.19%)
Mutual labels:  viml
Vimgitlog
Git log and diff plugin for vim.
Stars: ✭ 15 (-44.44%)
Mutual labels:  viml
Vimrc
vgod's vimrc
Stars: ✭ 944 (+3396.3%)
Mutual labels:  viml
Vim Sol
On the Path of Illumination ! :)
Stars: ✭ 27 (+0%)
Mutual labels:  viml
Vim Composer
Composer in Vim
Stars: ✭ 21 (-22.22%)
Mutual labels:  viml

This is a mirror of http://www.vim.org/scripts/script.php?script_id=746

Sometimes we want to to change the behavior of a built-in command so end up creating a custom command, and we wish to reuse the built-in command name for it. E.g., :Runtime to replace :runtime, :Find to replace :find. I myself wanted to replace :qa with :QA (see http://vim.wikia.com/wiki/Tabclose_instead_of_quit-all), but it is hard to remember to type :QA instead of :qa everytime, that is why I created this plugin.

This plugin is just a wrapper on top of command-line abbreviations (:cabbr), to work around the big disadvantages of :cabbr. With plain :cabbr, the expansion happens anywhere the abbreviation appears while typing command-line. E.g., if you create abbreviation from runtime->Runtime, then the following will not work as you expect:

:cnoreabbr runtime Runtime :%s/runtime/runduration/g

What would actually execute is:

:%s/Runtime/runduration/g

Which is not the same. The other problem is cabbr's trigger not only at the command-line, but also at search prompt, at the input prompt and any other prompts (see :help getcmdtype()). To avoid those unexpected expansions, cmdalias utilizes a light-weight wrapper function that expands the abbreviation only when it is typed as the first word of the ex command (":" prompt). So, instead of the below:

:cnoreabbr runtime Runtime

You would use this:

:call CmdAlias('runtime', 'Runtime')

or simply,

:Alias runtime Runtime

These aliases pretty much work like the bash aliases. If you don't want the expansion to temporarily happen even at the beginning of a command, you have two options:

  • After entering the command and before typing the next command press (e.g., )
  • Start the command-line with a space and then enter the command.

The CmdAlias() function takes a 3rd optional argument called "flags" for which you can pass options such as "" to make the alias local to the current buffer.

Here is the description from file header for more details: Usage: :call CmdAlias('', '', [flags]) or :Alias [flags]

:UnAlias <lhs> ...
:Aliases [<lhs> ...]

Ex: :Alias runtime Runtime :Alias find Find :Aliases :UnAlias find

Description:

  • Vim doesn't allow us to create user-defined commands unless they start with an uppercase letter. I find this annoying and constrained when it comes to overriding built-in commands with my own. To override built-in commands, we often have to create a new command that has the same name as the built-in but starting with an uppercase letter (e.g., "Cd" instead of "cd"), and remember to use that everytime (besides the fact that typing uppercase letters take more effort). An alternative is to use the :cabbr to create an abbreviation for the built-in command (:cmap is not good) to the user-defined command (e.g., "cabbr cd Cd"). But this would generally cause more inconvenience because the abbreviation gets expanded no matter where in the command-line you use it. This is where the plugin comes to your rescue by arranging the cabbr to expand only if typed as the first word in the command-line, in a sense working like the aliases in csh or bash.
  • The plugin provides a function to define command-line abbreviations such a way that they are expanded only if they are typed as the first word of a command (at ":" prompt). The same rules that apply to creating a :cabbr apply to the second argument of CmdAlias() function too. You can pass in optional flags (such as ) to the :cabbr command through the third argument.
  • The :cabbr's created this way, work like the bash aliases, except that in this case, the alias is substituted in-place followed by the rules mentioned in the |abbreviations|, and no arguments can be defined. Drawbacks:
  • If the is not of the same size as , the in-place expansion feels odd.
  • Since the expansion is in-place, Vim command-line history saves the , not the . This means, you can't retrieve a command from history by partially typing the (you have to instead type the for this purpose).

Search_key_words: cmdalias Hari Krishna Dara cmap alias cmdalias.vim

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].