On 2010-04-12, Duane Johnson wrote:
> I'm a total newbie to Vim.  I'd like to map a new command-line command
> (":vimrc") to open up my vimrc file (":e ~/.vimrc").
> 
> I tried something with cmap in my vimrc but caused infinite recursion by
> mistake (I have no idea if cmap is the right command to try):
> 
> 
>     cmap vimrc e ~/.vimrc
> 
> 
> I also found this plugin [1] but I'd first assume that what I'm trying to do 
> is
> fairly basic, and probably does not require a plugin.
> 
> Any help would be appreciated.

The conventional way to define your own commands is to use :command.
See

    :help 40.2

Your command would be defined like this:

    :command Vimrc e ~/.vimrc

User-defined commands must start with an upper-case letter.  There
are ways around this limitation, but since you're a newbie, I think
it's best to stick with the basics for now.

The reason your cmap caused an infinite recursion is because the lhs
of the mapping was part of the rhs.  When Vim discovered the "vimrc"
in the rhs it knew it had a mapping with that lhs and executed it.
To avoid that problem, use cnoremap instead of cmap.  See

    :help 40.1

and search for "^REMAPPING".

Regards,
Gary

-- 
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

To unsubscribe, reply using "remove me" as the subject.

Reply via email to