Execute external command in the same screen - linux

When executing :silent !command (followed by :redraw!) the screen goes to the terminal, then it come back to vim.
How can I make it execute in the same screen, without this "blink"?

If I understand you correctly you want to just execute some command, but don't want to see the output. If so, then just use the function system
:call system("g++ myfile.cpp -o output")
or whatever command you want to do. However, I would recommend just putting the output in a seperate window, you can use the QuickRun Plugin and the just run:
:QuickRun bash -src "g++ myfile.cpp -o output"
and the result will be in a separate window.

Related

Vim, custom tab and vertical split organization on open

Say the files in my working directory are src/example.c src/second.c src/third.c include/example.h include/second.h include/third.h.
I want to open vim in a way that automatically opens three tabs (example, second and third), where each tab contains a vertical split screen between a .c and corresponding .h file. Like the following commands would.
:tabnew include/example.h | vs src/example.c
:tabnew include/second.h | vs src/second.c
:tabnew include/third.h | vs src/third.c
Is there a way I can make a special script that will do this when I open vim?
It is safe to assume files will have the same name.
Ideally, this would happen from a shell script rather than modifying my .vimrc, if that is possible.
well if you want to do that, you clearly need a way to execute vim commands from your shell. Lets see if the vim application supplies that, by using the help command which we should ask first for every shell command:
?> vim --help | grep cmd
--cmd <cmd> Execute <cmd> before any config
+<cmd>, -c <cmd> Execute <cmd> after config and first file
So all that is needed is to chain these commands:
vim -c 'tabnew include/example.h' -c 'vs src/example.c' -c 'tabnew include/second.h' -c 'vs src/second.c' -c 'tabnew include/third.h' -c 'vs src/third.c'
as #Enlico pointed out in the comment, you should use edit or e instead of tabnew in the first command, else you will get 4 tabs. But I used your commands so you can see how easily you would have been able to solve this by reading the --help output.

How can I run a normal command after scripts load?

I'm trying to start vim from command line and have it jump to a certain place in the file and run <c-c>g to trigger goto_definition in python-mode.
So far running vim filename "+call cursor(x, y)" does at least get me to the position I want, but now how do I run <c-c>g afterwards?
If I try vim % "+call cursor(x, y)" -c "normal! <c-c>g" I get a "not an editor command" error
Try
vim FILENAME -c "call cursor(x, y)" -c "call pymode#rope#goto_definition()"
<c-c>g is actually bind to function pymode#rope#goto_definition().
You can look up in :map to see the mapping.
Refer to here if you're interested in why not an editor command error occured.

gnome-terminal executes commands from file

I need an example of gnome-terminal command to read lines of text from a file and executes them one by one in different terminal or a tab.
So this would be the process. I would run gnome terminal command and it would read 10 commands from a file. Then it would execute those 10 commands in 10 different tabs/terminals. And of course those tabs/terminals would remain opened. I found this question Avoid gnome-terminal close after script execution?
The third answer from the top is very helpful. I managed to open 1 command from a file. But I need 1 file with 10 command lines to be opened like I wrote above.
Thanks.
I recommend to use screen for this, if that can be acceptable to you.
You could create a commands.screenrc file like this:
screen bash -c 'command1; echo press any key; read'
screen bash -c 'command2; bash'
screen mutt
screen emacs
screen
You can define as many programs as you want. Start screen with:
screen -c commands.screenrc
I don't know what kind of commands you want to run. If you want to see their output, then write like the first example above: execute the command in a bash shell, which will "pause" after the command was executed. Or the second line, which, after running the command will start another bash shell. Otherwise the screen window would exit automatically.
If you are not familiar with screen, you will need to learn some basic key strokes to get around, and to be able to switch between windows. The first few pages of this presentation should be enough to get you started.

Calling command from `-c` command line argument doesn't work in Vim

I'm using the Fugitive plugin.
It has a command(?) Git! which executes a command and opens the result in a new buffer.
Example:
:Git! diff --cached
I have a function which calls this, and does some other things after that.
And I have this command declaration:
command! Hello execute ":Git! diff"
If I run :Hello from within vim, it works as it should. But when I run vim -c Hello, it throws this error:
Not an editor command :Git! diff
How can I do this?
(PS: How can I make this error message to stay until I press ? It appears for about a second and disappears.)
The reason is that Fugitive only defines its commands for buffers whose files are under Git version control. Precisely, the code in plugin/fugitive.vim only sets up autocmds that detect files under Git control, and only then defines buffer-local commands.
So at least you need to pass a Git-controlled file to your Vim invocation. If that still doesn't work, try explicitly triggering the detection via
:doautocmd User Fugitive

Can I run current script or a script in ViM?

I am developing a php application using ViM. Is there a shortcut for me to run the currentEditing.php? Alternatively, is there a shortcut for running main.php?
It depends on your platform, certainly, but when I'm developing python I often run the current script just by executing :!%. The colon for a command (obviously), the bang for shell execute, and the percent for the current filename.
You can execute shell commands in ViM using the following syntax:
:!command -options arguments
Therefore, you need to save your file first, and then run whatever command you need for executing php.
I don't know php, so let me give you an example with compiling a C file:
... editing text
:w main.c # save to file
:!gcc -Wall main.c # compile the code
:!./a.out # execute the executable
Note that :! commands are run by shell and ViM has no understanding of it. Therefore, you can execute any command. This also means that the command cannot run on a modified, unsaved buffer.

Resources