Quantcast

cmap to use a substitute command

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

cmap to use a substitute command

David Fishburn-2
Good Morning.

Vim 7.3.1-421 Windows 7 64-bit.

I want to create a command mode mapping which will do a substitution on
what is already typed in.
I am just wondering how to get access to the command line?

My searches through the help which was based on cmap and mapmode-c
didn't reveal anything I could use.

Thanks,
Dave

--
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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: cmap to use a substitute command

Ben Fritz
On Friday, April 20, 2012 12:53:36 PM UTC-5, David Fishburn wrote:

> Good Morning.
>
> Vim 7.3.1-421 Windows 7 64-bit.
>
> I want to create a command mode mapping which will do a substitution on
> what is already typed in.
> I am just wondering how to get access to the command line?
>
> My searches through the help which was based on cmap and mapmode-c
> didn't reveal anything I could use.
>
> Thanks,
> Dave

There's the getcmdline() function, but I don't see a way to set it.

As a workaround you could enter the command window and run a simple substitute command.

--
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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: cmap to use a substitute command

Andy Wokula
In reply to this post by David Fishburn-2
Am 20.04.2012 19:53, schrieb David Fishburn:

> Good Morning.
>
> Vim 7.3.1-421 Windows 7 64-bit.
>
> I want to create a command mode mapping which will do a substitution
> on what is already typed in.
> I am just wondering how to get access to the command line?
>
> My searches through the help which was based on cmap and mapmode-c
> didn't reveal anything I could use.
>
> Thanks,
> Dave

     :h getcmdline()
     :h c_CTRL-\_e
     :h c_CTRL-R_=
     :h getcmdpos()
     :h setcmdpos()

I've used all of the above in conomode.vim:
http://vim.sf.net/scripts/script.php?script_id=2388

(maybe not very readable code, but should be enough to get some
inspiration :-)

--
Andy

--
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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: cmap to use a substitute command

Ben Fritz
On Friday, April 20, 2012 2:07:24 PM UTC-5, Andy Wokula wrote:
>
>      :h getcmdline()
>      :h c_CTRL-\_e

Awesome, I didn't know about c_CTRL-\_e, I was wondering why there wasn't a setcmdline() function. Now I know! That functionality is elsewhere.

--
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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: cmap to use a substitute command

Chris Jones-44
On Fri, Apr 20, 2012 at 04:47:04PM EDT, Ben Fritz wrote:
> On Friday, April 20, 2012 2:07:24 PM UTC-5, Andy Wokula wrote:

> >
> >      :h getcmdline()
> >      :h c_CTRL-\_e

> Awesome, I didn't know about c_CTRL-\_e, I was wondering why there
> wasn't a setcmdline() function. Now I know! That functionality is
> elsewhere.

Rather than changing one's working habits and resorting to a cmap'd key
combo, is there any way I could transparently cause a custom function to
be invoked, say.. each time I enter a ‘:!...’ command (or even any Ex
command) so that I could inspect the content of the command and fiddle
with it in certain cases.

I have not looked into it, but I'm thinking of doing :cabbrev's on
either ‘!’ or the final <CR> .. but this looks soooo ugly to start off
with that I'm a little reluctant to go down that road without making
sure that there is not a clean/standard Vim solution that I missed.

The context is that I am revisiting this iFAQ where once in a while
a *nix user complains that bash aliases and functions are not available
when invoking the shell via ‘:!’.. I have come to the conclusion that
the $BASH_ENV hack is not satisfactory.

Not sure if I'm hijacking this thread.. If so, please let me know and
I'll open a separate ticket.

Thanks,

CJ

--
ALL YOUR BASE ARE BELONG TO US!

--
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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: cmap to use a substitute command

Chris Jones-44
addendum.. more likely ‘!’ or <CR> cmap's than :cabbrev's..

CJ

--
ALL YOUR BASE ARE BELONG TO US!

--
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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: cmap to use a substitute command

David Fishburn-2
In reply to this post by Andy Wokula
On 4/20/2012 3:07 PM, Andy Wokula wrote:

> Am 20.04.2012 19:53, schrieb David Fishburn:
>> Good Morning.
>>
>> Vim 7.3.1-421 Windows 7 64-bit.
>>
>> I want to create a command mode mapping which will do a substitution
>> on what is already typed in.
>> I am just wondering how to get access to the command line?
>>
>> My searches through the help which was based on cmap and mapmode-c
>> didn't reveal anything I could use.
>>
>> Thanks,
>> Dave
>
>     :h getcmdline()
>     :h c_CTRL-\_e
>     :h c_CTRL-R_=
>     :h getcmdpos()
>     :h setcmdpos()
>
> I've used all of the above in conomode.vim:
> http://vim.sf.net/scripts/script.php?script_id=2388
>
> (maybe not very readable code, but should be enough to get some
> inspiration :-)
>

Thanks Andy.

I regularly use the MRU plugin with it's tab completion.

I will often use it to get close to a file I want to edit (absolute
path) and then need to change :MRU to :e and finish editing the command
line and edit the file.

So, this cmap will do what I want <C-e> for "e"dit:
cmap <C-e> <C-\>esubstitute(getcmdline(), '^MRU\>', 'e', '')<CR>

Dave


--
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
Loading...