How do I open a shell but still have access to vim - windows

I am running gvim on Windows 7.
I use this mapping to execute the current file with powershell:
nnoremap <C-q> :! & '%:p'<cr>
It works great except I can't access vim until I close the powershell window. Sometimes I want the shell to remain open so I can run additional commands or I want to access vim with the shell still open so I can check the lines where errors were generated.
Ideally (don't know if this is possible) I want to have an already open shell execute the command. So I always have vim and a shell open (on separate monitors) and I can execute the script in that same shell.
How can I achieve this?

GVIM on Windows has a special :!start command to execute the external command asynchronously; i.e. Vim doesn't wait for its return. Just replace the :! with it. See :help :!start for more information.
On Unix, such special isn't necessary; you can just append & (a shell feature) to execute the command asynchronously.

Related

In ConEmu I can't change the PROMPT when using cygwin bash

In conemu using cmd I can edit the prompt nice and easy in the CmdInit.cmd file - I do this because I don't like the prompt spread over two lines.
However I can't seem to do the same trick when I select the startup in settings to be bash::Cygwin.
I see that the CmdInit.cmd is dos commands, so I could create a startup.sh? not sure how I invoke it.
Also the PROMT variable does not seem to exist in the bash mode - even though there is a very long two-line prompt. How can I change it? Where are the defaults even taken from?

vim shell key mapping to execute shell commands

i am using vimshell to execute commands inside vim
nnoremap <leader>vs :VimShellPop<CR>
with this key mapping i can open vim shell and execute commands like 'bundle install' and then
type exit to exit VimShellPop window but i want set a key mapping
nnoremap <leader>bi :
to open up vimshellpop execute the bundle install command and exit once i get completed..is it possible in vimshell?
The vimshell plugin provides an interactive shell inside a Vim buffer. Apparently, you don't need the interactivity (because you intend to immediately exit after issuing the shell command). For that, you don't need the plugin itself; the built-in :! command already allows you to launch external commands:
:nnoremap <leader>bi :!bundle install<CR>
If you want to keep the output visible, you can read it into a scratch buffer:
:nnoremap <leader>bi :new<Bar>0r!bundle install<CR>
Having an interactive shell in Vim is one of Vim's stated non-goals (cp. :help design-not), so the plugin has to jump through several hoops to make this possible. Those hacks are causing these problems (of defining a proper mapping, as evidenced by the attempts in the question's comments); lack of automation (like through mappings) is a limitation of this approach.
You may contact vimshell's author (via email or GitHub issue); he's usually very open and responsive! He's in the best position to make such mapping work.

Suppress command window when running console application on Windows

Is there a way to suppress showing the command window when running a console application on Windows XP?
Details: I am calling a (console-based) program from Vim. I would like to avoid the command window being shown every time I do this.
Try start /B <program name> to start the program without a new window.
Did you try shell.vim?
The xolox#shell#execute() function
This function enables other Vim
plug-ins to execute external commands
in the background (i.e.
asynchronously) without opening a
command prompt window on Windows.
i can't believe no one has suggested simply using :silent
for example, I have the following in my .vimrc (gvim on Win7)
"open windows explorer to the directory of the current file
:map <leader>ex :silent !Explorer %:p:h<CR>
When I didn’t want to see the output of external commands called from the Vim command line, I would prepend them with :silent. However, this results in a command window momentarily flashing on screen when running GVim under MS Windows. After a short while, I got annoyed by this behaviour so I researched alternative solutions (which is how I came across this question).
The best solution I came up with was to use Vim’s inbuilt system function which runs shell commands without opening an external command window. While the output of the shell command is not printed, its exit status is conveniently available via v:shell_error. It also has the advantage that it’s portable across (all) platforms.
Example (the echo statement should print 0 if C:\Windows exists):
call system("dir c:\windows")
echo v:shell_error
You could maybe use some autohotkey script of this kind:
Loop {
WinWait, my command window title
WinHide
}
I was trying to use git-bash as my shell from vim on Windows but having the command prompt open whenever a command was run, as you described. My eventual solution was to install the plugin xolox/vim-shell and add the following snippet to .vimrc:
if has('win32')
set shell=bash\ -c
set shellcmdflag=
set shellxquote='
set shellquote=
set shellredir=>
set noshelltemp "This prevents an external window from opening.
endif
This utility will also do the job:
http://www.ntwind.com/software/utilities/hstart.html

Shell commands from vim

What is the best approach of using shell commands from vim? I know about the possibility of !shell_command. But this doesn't know all commands e.g.
export OSTYPE; make install So I have to run it outside vim. Is there better approach?
I know this is a bit late, but my preferred approach is suspending the vim process (Ctrl+z). You return to your shell/bash command prompt.
Then execute whatever command(s) you like.
Return to vim by typing fg
You can start a shell from Vim using the :sh command. When the shell exits
(after the exit command or Ctrl+D) you return to Vim. The name for the shell command comes from the shell option.
For terminal Vim (on unix-like systems) you can also use Ctrl+Z to suspend Vim and get back to the shell from which it was run. To resume the Vim process, use the fg command.

New Application Process from Bash Shell

I'm relearning UNIX commands to use git on windows using MINGW32.
When I launch a program, for example "$ notepad hello.txt" I can't use the shell again until I close the notepad file or CTRL-C in the shell.
How do I essentially fork a new process so I can use both programs?
Add a & to the end of the command:
notepad hello.txt &
Put an ampersand (&) at the end of the command line. That tells the shell to run the program in the background.
In UNIX, you can hit CTRL-z to suspend the currently running program (Instead of CTRL-c to kill it). Once it's suspended, you can use the 'bg' command to put it in the background. I don't think that will work on Windows, but you can try.
You can also create an alias in your .rc file so you don't have to add the ampersands each time.
I had some trouble doing this in bash on Cygwin though.
I ended up having to create a separate script file and add an alias to point to it.
Script file contents (filename is "dtextpad"):
#!/bin/bash.exe
C:/Program\ Files/TextPad\ 5/TextPad.exe $# &
Alias in my .bashrc:
alias tp='~/include/bin/dtextpad'
Now if I want to open a file in textpad, I can type tp filename

Resources