GVIM: How to pass in multiple arguments via a file under windows - windows

Is anyone aware of a command line option or a way to pass in a file to gvim which will use the contents of that file as a list of arguments?
Achieving this without having to populate argv with a list of files.
The problem is that vim is a unix tool which by default assumes that a list of files would be piped in, if there are say 1000 files that need to be opened, however in the windows world there is a limit to how many arguments you can have on the command line. The way to do this on a windows command line is to have a file which contains all the arguments you wish to pass onto the program. I am wondering if gvim provides such an option.
Note: This is to invoke gvim in a windows compatible way i.e. avoid using extremely long argument lists

A simple solution:
list your files in files,
file1
file2
file3
open Vim with the command below,
$ vim -c next `cat files`

Related

Is there a way to save output from bash commands to a "file/variable" in bash without creating a file in your directory

I'm writing commands that do something like ./script > output.txt so that I can use the files in later scripts like ./script2 output.txt otherFile.txt > output2.txt. I remove them all at the end of the script, but when I'm testing certain things or debugging it's tricky to search through all my sub directories and files which have been created in the script.
Is the best option just to create a hidden file?
As always, there are numerous ways to do so. If you want to avoid files altogether, you can save the output (STDOUT) of a command in a variable and pass it to the next command as a file using the <() operator:
output=$(cat /usr/include/stdio.h)
cat <(echo "$output")
Alternatively, you can do so in a single command line:
cat <(cat /usr/include/stdio.h)
This assumes that the next command strictly requires a file for input.
I tend to avoid temporary files whenever possible to eliminate the need for a cleanup step that gets executed in all cases unless large amounts of data have to be processed.

edit/save a file within shell script

I think this question fall under pipes, am bad at it.
Using one of my shell script, a file is generated with millions of rows.
Before I can use it with another command, I need to edit this file. I need to add a text e.g 'txt' in front of every line.
What i am currently doing now is,
-exit the shell script after file is generated
-open it in vim
-use command :g/^/s//txt/g to add txt at start of each line
-save file
-use it in remaining shell script
I am sure there would be a more efficient way, which i am not aware of. thanks for the help.
As some people said in the comments, you can use GNU sed to do that:
sed -i 's/^/txt/' yourfile.txt
The -i stands for --in-place and edit your file instead of printing to stdout.

How to execute command inside vim?

I want to run shell script inside Vim editor.
I heard it is possible but do not know.
Command:./shell.sh inside vim.
There are multiple ways to do it. A primary question is "Do you want the output from the script in the file?"
If you want the output in the file:
:r!./shell.sh
If you don't want the output in the file:
:!./shell.sh
If you have the line ./shell.sh in the file, you can include the output in the file with:
!!sh
If you've done it before, you have more options.
If you save the command in a named buffer you have still more options.
If you want the script to have a portion of the file (edit buffer) as its standard input, you have an enormous number of options you can use in conjunction with either of these mechanisms.
Prefix the command with a !. For example, open Vim and write:
:!ls
This will execute the shell ls command.
Note that you'll have to be in the correct directory within Vim for this to work.

Using VIM command on all open files

I have a list of files i've opened in VIM using this command:
vim `cat list.txt`
I'm looking to run this command on all open files:
:99,104 norm i#
(from lines 99 to 104, insert a comment "#") <--simple, works
When I run the above command to insert it works as expected on the current file. How do I get VIM to run the exact same command on all open files? I tried :argdo, :windo, :bufdo but didn't have any luck.
Any suggestions?
I guess bufdo would work, if you have set hidden (to allow bufdo to change buffers without saving) before:
:set hidden
:bufdo 99,104 norm i#
Then save all files with :bufdo! w or :wa.
(Note: set hidden could be replaced with set autowrite as well.)
I think sed would be a better option if you can use it. sed is a command line editor rather than an interactive editor like vim.
sed -i '99,104s/^/#/' list of files
Because you've supplied all files as arguments, :argdo is the correct command. (Unless you open other files, :bufdo would work, too.) If you don't want to :set hidden (as indicated in the other answer), you have to immediately persist the buffer via :update. Because you're using a :normal command, you have to enclose it in :execute to be able to concatenate another Ex command:
:argdo 99,104 execute 'norm i#' | update

How do I jump to the first line of shell output? (shell equivalent of emacs comint-show-output)

I recently discovered 'comint-show-output' in emacs shell mode, which jumps to the first line of shell output, which I find incredibly handy when looking at shell output that exceeds a screen length. The advantages of this command over scrolling with 'page up' are A) you don't have to scan with your eyes for the first line of the output B) you only have to hit the key combo once (instead of 'page up' a number of times which probably is not known beforehand).
I thought about ending all my commands with '| more' but actually this is not what I want since most of the time, I want to retain all output in the terminal buffer, and I usually want to see the end of the shell output first.
I use OSX. Is there a terminal app (on os x) and shell (on remote linux) combination equivalent (so I can do something similar without using emacs all the time - I know, crazy talk)? I normally use bash, but would be fine with switching shells just for this feature.
The way I do this sort of thing is by sending my output to a file and then watching the file as it is written. You still get the results of the command dumped to terminal history in real time and can still inspect the output's actual contents further after the fact (or in another terminal, etc...)
command > output &
tail -f output
head output
You could always do something in bash like this:
alias foo='!! | more'
which would make foo run the previous command with more. I'm not sure of any way to do exactly what you are suggesting.
If you're expecting a lot of output and don't want to run your command twice, you can use tee(1) to fork the output:
my-command | tee /tmp/my-command.log | less
This will pipe the output to a paginator (less), while simultaneously logging the output to a file (in this case, a file named /tmp/my-command.log). If you need to review the output after you've quit from less, you can just cat the log file instead of re-running the command.

Resources