Wednesday, February 20, 2013

Re: vim script: repeat(\)

On 02/20/2013 03:12 PM, Ben Fritz wrote:
> You said your problem was that Vim would put a bunch of stuff on your command line but not actually hit enter for you.
>
> Now you are beyond that issue and ran into another problem.
>
> Strings in Vim cannot be split over multiple lines.
>
> Instead of this (which will not work):
>
> let mystring = ":
> \ abc
> \ def"
>
> You need to do this:
>
> let mystring = ":"
> \ ."abc"
> \ ."def"
it looks this is not true , at least per my test:
let me ignore the "repeat" part of the issue for now:

//with this new code
function! MyGit(commitmsg)
let commitmsg=a:commitmsg
let GitCmd=":
\!git add -A .;
\git commit -m \" .
\commitmsg . \";" . "
\git push origin master"

echo GitCmd
endf
command! -nargs=? MyGit :call MyGit(<q-args>)
nn ,gg :call MyGit("new post:")<CR>


so If I test with echo in the code, I got:

:!git add -A .;git commit -m " .commitmsg . ";git push origin master
Press ENTER or type command to continue

so at least the line continuation for the "let var = " looks fine.

>
> However, looking at what you are trying to do, this STILL will not work. You have at least two other conceptual problems:
>
> 1. You cannot string together commands like :!command1 !command2. No Vim command works that way, you need to separate them with |. :! is special though so that even that won't work, because it will just get passed to the shell. You need to do it like :exec "!command1" | exec "!command2".
this I agree, so I fixed it with just one "!" in the head of the whole
string and use ";" to connect multiple external shell commands.
> 2. :exec will not leave the cursor somewhere for input.
I understand,thanks!
> You can't use a function in this way. If you want to use <Left><Left> repeatedly to place the cursor awaiting further input, you will need to have your function RETURN a value instead of executing it,
this is how I changed my current code.

> and additionally use an expression map or abbreviation. See :help :map-<expr>
this part I don't understand...
I couldn't find a close example to my scenario ...

strangely that if I use "return GitCmd", I got just nothing...
since I already "return" the commands that I needed for the Ex command,
shouldn't I now get the whole bunch of the command strings waiting in
the vim command line?


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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment