|
Hi Ben and others, I need help correctly writing a user command.
Others have suggested how I can do it, but I have not gotten the suggestions that work. I want to write a user command that executes this command: :abbreviate <exrc> ihs somefunction(ihs,irs) <CR> where ihs and irs are strings How do I write such a user command? I've tried different combinations of exe and quotes and <f-args>, but can not seem to get it correct. I would appreciate someone writing out the exact user command that would result in the above command being executed. Thanks -- 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 |
|
howardb21 wrote:
> I want to write a user command that executes this command: > > :abbreviate <exrc> ihs somefunction(ihs,irs) <CR> > > where ihs and irs are strings I expect you mean <expr> and not <exrc>? I must have missed the original thread, but I think it would be good to start again with a statement of what problem needs to be solved. I'm wondering why 'ihs' appears twice, and what would you want the user command to be? How about a simple example showing what you would like to enter and what it should do. John -- 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 |
|
On Wednesday, May 16, 2012 8:39:58 PM UTC-5, JohnBeckett wrote:
> howardb21 wrote: > > I want to write a user command that executes this command: > > > > :abbreviate <exrc> ihs somefunction(ihs,irs) <CR> > > > > where ihs and irs are strings > > I expect you mean <expr> and not <exrc>? > > I must have missed the original thread, but I think it would be > good to start again with a statement of what problem needs to be > solved. I'm wondering why 'ihs' appears twice, and what would > you want the user command to be? > > How about a simple example showing what you would like to enter > and what it should do. > It's been a while, but I have a vague memory. I think he's trying to set up an abbreviation the same way in a loop or function or something, with different left side and right side. I think he wants something like: exec 'abbreviate <expr> '.lhs.' somefunction('.lhs.','.rhs.')' But I'd need to dig up the old thread to be sure. Or howardb21, you could post the actual problem again. -- 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 |
|
Hi Ben!
On Do, 17 Mai 2012, Ben Fritz wrote: > On Wednesday, May 16, 2012 8:39:58 PM UTC-5, JohnBeckett wrote: > > howardb21 wrote: > > > I want to write a user command that executes this command: > > > > > > :abbreviate <exrc> ihs somefunction(ihs,irs) <CR> > > > > > > where ihs and irs are strings > > > > I expect you mean <expr> and not <exrc>? > > > > I must have missed the original thread, but I think it would be > > good to start again with a statement of what problem needs to be > > solved. I'm wondering why 'ihs' appears twice, and what would > > you want the user command to be? > > > > How about a simple example showing what you would like to enter > > and what it should do. > > > > It's been a while, but I have a vague memory. I think he's trying to set up an abbreviation the same way in a loop or function or something, with different left side and right side. > > I think he wants something like: > > exec 'abbreviate <expr> '.lhs.' somefunction('.lhs.','.rhs.')' > > But I'd need to dig up the old thread to be sure. > > Or howardb21, you could post the actual problem again. I think it started here: http://groups.google.com/group/vim_use/msg/5d2c72f422a76745 regards, Christian -- -- 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 |
|
In reply to this post by John Beckett-2
On May 16, 6:39 pm, "John Beckett" <[hidden email]> wrote:
> I think it would be good to start again with a statement of what problem > needs to be solved. I'm wondering why 'ihs' appears twice, and what would > you want the user command to be? > > How about a simple example showing what you would like to enter > and what it should do. OK There is a form of the abbreviation command like this: ab <expr> string expression For this purpose I want to use this function for the expression: function! ABB(lhs, rhs) if getcmdtype() == ':' return a:lhs else return a:rhs endif endfunction So after I execute the command, ab <expr> howard ABB("howard","schwartz") each time I type howard it will be replaced by schwartz, except when I am on the : command line. In that case, howard will not be replaced by schwartz. I want to write a user defined command that does the same thing as the above, ab, command. Let's call the user command Ab. Then, Ab howard schwartz will have the same effect as executing the command, ab <expr> howard ABB(howard,schwartz) The string, 'howard', must occur twice in the ordinary abbreviation command above - once as the initial string, and again as the first argument of the function ABB(). So I must, extract `howard' from the expressions <args> or <f-args> that evaluate to all arguments of a user command. I know this will not work, but here is a sample command that might do the trick: command! =nargs=2 ab <expr> matchstr(<args>,"^.* ") ABB(<f- args>) if <args> evaulated to "howard Schwartz" than the matchstr function might return the first characters followed by a blank (which would be "howard ") I want to define a user command like that that will really work! Why? Because, Ab howard schwartz is a lot simpler than, ab <expr> howard ABB(howard,schwartz) -- 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 |
|
On Friday, May 18, 2012 2:10:05 PM UTC-5, howardb21 wrote:
> On May 16, 6:39 pm, "John Beckett" <[hidden email]> wrote: > > > I think it would be good to start again with a statement of what problem > > needs to be solved. I'm wondering why 'ihs' appears twice, and what would > > you want the user command to be? > > > > How about a simple example showing what you would like to enter > > and what it should do. > > OK There is a form of the abbreviation command like this: > > ab <expr> string expression > > For this purpose I want to use this function for the expression: > > function! ABB(lhs, rhs) > if getcmdtype() == ':' > return a:lhs > else > return a:rhs > endif > endfunction > > So after I execute the command, > > ab <expr> howard ABB("howard","schwartz") > > each time I type howard it will be replaced by schwartz, except when > I am on the : command line. In that case, howard will not be replaced > by > schwartz. > > I want to write a user defined command that does the same > thing as the above, ab, command. Let's call the user command Ab. Then, > > Ab howard schwartz > > will have the same effect as executing the command, > > ab <expr> howard ABB(howard,schwartz) > > The string, 'howard', must occur twice in the ordinary abbreviation > command > above - once as the initial string, and again as the first argument of > the > function ABB(). > > So I must, extract `howard' from the expressions <args> or <f-args> > that > evaluate to all arguments of a user command. > Have you tried the command Christian created to do exactly this in your original thread? https://groups.google.com/d/topic/vim_use/46_Na5k0Ku8/discussion Note his solution uses <q-args> and the split() function to get the individual pieces. You could also probably use <f-args> and just use the arguments separately. -- 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 |
|
On May 18, 12:55 pm, Ben Fritz <[hidden email]> wrote: > Have you tried the command Christian created to do exactly this in your original thread? > > https://groups.google.com/d/topic/vim_use/46_Na5k0Ku8/discussion > > Note his solution uses <q-args> and the split() function to get the individual pieces. > You could also probably use <f-args> and just use the arguments separately. I tried it and it did not seem to work. Personal taste wise - the split function and printf seemed like overkill - I thought there should be a simpler way. And the special form of ab <expr> string expression seems made to order for what I was after. That is why I wanted to just use this command, but in a simpler form. -- 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 |
|
On Saturday, May 19, 2012 4:54:40 PM UTC-5, howardb21 wrote:
> > I tried it and it did not seem to work. Personal taste wise - the > split function and printf seemed like overkill - I thought there > should be a simpler way. And the > special form of ab <expr> string expression seems made to order for > what I was after. That is why I wanted to just use this command, but > in a simpler form. What do mean by "it doesn't work"? What did it do instead of creating the desired abbreviation? As for a simpler way, did you try using the same approach but using <f-args> instead of all the split stuff? If so, what EXACT commands did you use? We cannot help without more detail about what went wrong. -- 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 |
| Powered by Nabble | Edit this page |
