I am using macvim, and when I run a shell command in vim's command mode like:
:! yarn add redux
I don't get proper progress bars, instead I get the following characters:
How can I get the output to show proper progress bars?
Those characters are what gives colors and effects (such as underlining) to outputs in shell. They need escape sequences in order to take effect.
The thing is, MacVim doens't have terminal in it and it doesn't do a good job at emulating one.
It doens't have all the features that a normal terminal would have, and that is why it doesn't support ANSI escape sequence.
There is a plug-in for vim that shows the terminal output in vim itself but like the description says in that page, it is no longer supported.
So if you want that screen to be visualized as they are intended to be, I would suggest you use vim in terminal (I tried the exact same code as yours and it worked fine).
Related
When in insert mode, a list of completion candidates can be shown by pressing Ctrln (for insert mode completion), or CtrlxCtrlo (for Omni completion when omnifunc is set). However, these keybindings do not work in terminal mode (:term).
Question: how can I get a list of completion candidates when in terminal mode? I was expecting to be able to make vim display completion candidates like grep, kill, cd, python3, and file paths like /home/user/Desktop, /home/user/Documents, etc.
I am using vim 8.0.
In this case a terminal is shown in vim, so your input goes to the terminal not to vim. That means we have to use the completion your terminal offers you. tab should be working like always, for a vim style completion you could add that to your .inputrc:
# cycle forward
Control-n: menu-complete
# cycle backward
Control-p: menu-complete-backward
A :terminal is just a view into an interactive shell (or another command started by or in place of the shell). Vim offers some integration (pass on typed keys, show output), but it's the shell who's running the show.
As Vim does not know what's going on there (you could have launched a command where completions for file system paths or commands, as you've suggested, would not make any sense; you could have ssh'd into another system that does not have python3 installed), it cannot and should not offer you these things. Instead, as others have already commented, this is the job of the shell (and most of them provide completion, some (like Bash) even very powerful and extensible ones that go far beyond your suggestions) or the command that is running.
Numerous sources indicate that running a "bang" command such as :! wc % will display the results in Vim below the editor window. (For instance, this tip sheet states that as the expected behavior.)
Specifically, I'm following along with this Vimcast tutorial on Tim Pope's Fugitive plugin, and in that Drew Neil states that running the :Git command will allow the user to run any arbitrary git command from inside Vim--and the output of the command will be displayed within Vim at the bottom of the screen.
This is not the behavior I am experiencing. Instead my Vim session is in essence sent to the background, and I'm popped back to my terminal to see the output. It's all very disorienting--specifically because I lose the useful visual context provided by my Vim session including the "bang" command that generated the output.
I'd love it if Vim actually did display the externally generated output in Vim below the editor window. I found some similar types of questions, but in all of them the user wanted to output the content to a new buffer rather than just see it momentarily printed at the bottom of the editor window. In other words, I've not found anyone else describing the behavior I'm seeing.
I was able to get the desired behavior in gVim, but gVim isn't always a viable option, so I'd like to know whether there is a broader solution that will allow the expected behavior in terminal-based Vim.
I'm using Vim 8.0 on Ubuntu 16.04. My terminal is gnome-terminal with the zsh shell. I tried some other terminals on my machine and the bash shell, and I'm experiencing this behavior regardless of which combination I use.
Here are two screenshots that demonstrate the behavior I'm seeing. On the left is a terminal-based Vim, and on the right is gVim. Notice how running :! wc % has the expected/desired behavior in gVim on the right, but not in regualar Vim on the left.
Screenshot before running command:
Screenshot after running command:
Is anyone else experiencing this? Does anyone else get the desired behavior from their terminal-based Vim? (Perhaps this is all some kind of documentation oversight and terminal-based Vim was never expected to behave in the desired way?)
Thanks!
It's GVim (or MacVim) that shows the output of external command at the bottom of the window because it comes with a very minimal terminal emulator. Plain Vim is incapable of doing that.
You could emulate that behavior with tmux via any of the many Vim plugins that provide tmux integration or, since you are using Vim 8.0, the new built-in :help :terminal emulator.
For your example:
:term wc %
An alternative that I stumbled across is to use AsyncRun from this plugin. It acts as alternative to the shebang command, runs the command in the background, and sends the output to the quickfix window.
While I still think the accepted answer is the right one (i.e. that a TUI Vim always outputs to the terminal shell instead of the internal shell), someone else coming across this thread might find AsyncRun to be a better alternative to "that's just how it works".
When I enter a shell command via vim -- e.g., :!rake routes -- I'll get some output and then:
Press ENTER or type command to continue
If I press anything at that point, I am always taken back to the main vim UI. How do I stay in that shell mode for a bit longer, specifically I can scroll back to see all the output of the command?
For terminal vim scrolling is provided by terminal emulator (or terminal multiplexer like tmux/screen if you use it). I.e. if your terminal scrolls when using <S-PageUp> it must also scroll with Vim’s !. Same for mouse wheel (it works for me even if vim was configured to handle mouse on its own).
If have terminal vim and you need to view output after you pressed <CR> then you can use <C-z>/:susp. Both these capabilities will be spoiled with incorrect configuration of either vim or terminal (terminal multiplexer) (i.e. terminal configured not to support alternate screens (which is normally issue for terminal multiplexers rather then terminal emulators: screen requires altscreen on in .screenrc) or vim setting telling vim what to output to the terminal on startup/resume and shutdown/suspend was spoiled).
If you have GUI vim your options are very limited. It is better to follow link provided by #glts or #EricAndres advice in this case as I do not use GUI vim.
:r! [shell command] will read the output from the command into the buffer. So if you open a new buffer then use that command, you can search and scroll through it all you like. See Vimcasts episode 57 for more information.
When Gary Bernhardt executes a shell command from Destroy All Software, for example this:
:!ls
The command looks as if it had "spawn a new shell" - it takes the whole window, with its own theme. You can see it around 00:36 in the "One-minute demo video" of his homepage.
When I do the same in my macvim, the result is not the same; the command runs in the "bottom of the screen", inside a "small buffer" of around 1/3rd of the screen size, and conserving the theme I use in vim. Inconveniently, it also prints escape codes literally, instead using color codes (this particular bit has been asked in Stack Overflow before, but I want to know how Gary does his stuff).
What I have tried:
I have watched the 3 episodes Gary has about vim configuration: The .vimrc, Some Vim Tips and File Navigation in Vim. Sadly, none of them mention doing something special or installing a plugin relevant to the way the shell script is done.
I have studied Gary's .vimrc and .vim folder. If the relevant configuration option is there somewhere, I could not find it.
Hence, my question: how do I get macvim to display shell commands as in DAS?
Spec: I'm using MacVim, MacOsx 10.8.1, iterm2, zsh and ohmyzsh.
Well, I think I can answer myself now.
Macvim does the console thing very differently in gui mode than in console mode.
In console mode, it works as in DAS. Full screen, color codes.
In gui mode, it ... well, it basically sucks. Bottom of the screen, no color codes.
So, if you want nice shell outputs in macvim, use the non-gui mode. At least for now. (I have not investigated plugins like Conque)
I'm using Vim for editing source code, but I would also like to have a terminal embedded in vim's window (just like in Kate, you know).
Now I have seen the vimsh plugin that turns a vim buffer into an interactive terminal, but I don't like 2 things about it:
It opens automatically at startup. Can I disable it and invoke the terminal with a special command whenever I wish?
It splits the window in two and occupies the top window, but I would like it to occupy the bottom window. Can this be arranged?
PS: I'm not exactly a vim guru :)
Maybe this is what you want: Conque Shell - VIM Plugin
There's also an older patch that you can apply. It requires recompilation of the VIM source code though.
http://www.wana.at/vimshell/
Maybe I am not going to reply exactly to your question but I'll propose anyway a different approach on working with Vim and the terminal.
The first approach is to run shell commands directly from vim in command mode prepending them with a "!":
:!ls
will run the shell ls command and display you the output in a temporary window. This is useful if you just want to run a single or few commands.
If you want to mess around longer I suggest to suspend your vim session with Ctrl-z, work in the shell and issue fg as your last command to get back to vim.
Hope it helps you.
Another option you could try is using tmux/screen to split your terminal, so that you can then run vim in one pane and have your shell in another. I also liberally use ControlZ to drop into a shell from vim and then fg to get back to vim after finishing with the shell.