Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using vim from the terminal: too many command arguments #2002

Closed
MilesCranmer opened this issue Aug 22, 2017 · 5 comments
Closed

Using vim from the terminal: too many command arguments #2002

MilesCranmer opened this issue Aug 22, 2017 · 5 comments

Comments

@MilesCranmer
Copy link

I wrote this tiny wrapper called "vims" (https://github.com/MilesCranmer/vim-stream) which makes it easier to use vim movement commands from the terminal, in a sed-like fashion.

Basically, running:

git status | vims -r 'modified' 'dd' -l 'df:'

(-r = run a normal-mode command on every line not matching regexp)
(-l = run a normal-mode command on every line)

Gets translated into

git status | vim - -nes -c '%v/modified/exe "norm dd"' -c ':%g/.*/exe "norm df:"' -c :%p -c ':q!'

Which will delete all lines without "modified" (using dd), then on each line (-l), it will delete from char 0 to the first : character.

Some people think I should just use sed/awk, but I've found this little wrapper VERY useful, and have started using it everywhere.

Now, I am writing a script that does the following: when given an integer x, it deletes all lines with integers < x. It does this using vims:

for x in $(seq 0 $1); do                                                      
    NUMS_TO_AVOID+=("%g/\<$x\>/d_")                                             
done                                                                     
vims "${NUMS_TO_AVOID[@]}" | less

However, when I get to a certain integer (I think 8?), I am told that I have hit some limit of commands:

VIM - Vi IMproved 7.3 (2010 Aug 15, compiled Jul  9 2015 23:58:42)
Too many "+command", "-c command" or "--cmd command" arguments
More info with: "vim -h"

I've never entered so many commands into vims/vim before, but I don't see a reason there should be a limit. Of course, I could also just change this to be something like "%g/1\|2\|3\|4...", but that just fixes this single test case.

Is there any way I can release this limit?

@vim-ml
Copy link

vim-ml commented Aug 22, 2017 via email

@MilesCranmer
Copy link
Author

Thanks, Tony! I will re-implement my wrapper with the -S command and a tmp file to hold commands.

Out of curiosity, why does the limit of 10 -c or --cmd's exist?

Best regards,
Miles

@MilesCranmer
Copy link
Author

Ah, so I just need to change:

vim/src/structs.h

Line 3300 in 97bd5e6

#define MAX_ARG_CMDS 10
, correct?

Is this limit of 10 to save memory/startup performance (as the vast majority of people will never use this many -c's in their life)?

@vim-ml
Copy link

vim-ml commented Aug 22, 2017 via email

@caleb-allen
Copy link

@MilesCranmer Fancy running into you here! I see that you've been getting vim into new places for quite a long time!

Anyways, your command examples in your original post have been very helpful for me writing for writing an integration test for VimBindings.jl. Thanks for the detailed post! This saved me quite a lot of time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants