-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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
Comments
On Tue, Aug 22, 2017 at 5:22 AM, Miles Cranmer ***@***.***> wrote:
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?
The documented limit is 10 -c or + or -S arguments (to be run after
reading the first file and processing its modelines if any) and 10
--cmd arguments (to be run before reading the vimrc).
If you want to run more than 10+10 ex-commands at startup in the next
Vim instance (and not every time, or they would go in the vimrc), the
way to do it is to write them into a script. You can then pass this
script as argument to an -S argument, which will count as one command
no matter how many ex-commands that script contains. Or -S not
followed by a filename (i.e. at the end of the command-line or
immediately before another dash option) will implicitly source the
file Session.vim in the current directory. That can be any Vim script,
it doesn't have to have been created by the :mksession command. It
could for instance have been written by your wrapper immediately
before invoking Vim.
See
:help -c
:help --cmd
:help -S
Best regards,
Tony.
|
Thanks, Tony! I will re-implement my wrapper with the Out of curiosity, why does the limit of 10 Best regards, |
Ah, so I just need to change: Line 3300 in 97bd5e6
Is this limit of 10 to save memory/startup performance (as the vast majority of people will never use this many |
On Tue, Aug 22, 2017 at 4:17 PM, Miles Cranmer ***@***.***> wrote:
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
I don't know, it was already there when I started to use Vim. One
possible reason is that there is an OS-dependent limit to the length
(in bytes) of a command-line.
Best regards,
Tony.
|
@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. |
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:
(
-r
= run a normal-mode command on every line not matching regexp)(
-l
= run a normal-mode command on every line)Gets translated into
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
:However, when I get to a certain integer (I think 8?), I am told that I have hit some limit of commands:
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?
The text was updated successfully, but these errors were encountered: