Skip to content
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

Search results leak into terminal #18

Closed
jerodsanto opened this issue May 7, 2011 · 33 comments · May be fixed by #278
Closed

Search results leak into terminal #18

jerodsanto opened this issue May 7, 2011 · 33 comments · May be fixed by #278

Comments

@jerodsanto
Copy link

When I run vim from OS X's (10.6.7) Terminal or iTerm apps and use the Ack command it works as expected, but upon closing vim all of the search results have been printed in the terminal window.

This does not occur when using MacVim even if it is launched via the mvim command.

@osaris
Copy link

osaris commented Nov 24, 2011

Same here (on debian lenny) but no problem with MVim.

@chriskempson
Copy link

Happens to me also when running in a terminal. My entire screen flashes the output of Ack then back to Vim again. Rather distracting.

@owenthereal
Copy link

Happen to me on terminal vim, is there any fix for this?

@adamcooper
Copy link

+1 on this issue too. Only in vim not MacVim.

@8bitDesigner
Copy link

Just ran into this too; on iTerm2 with vim 7.3

@reicheltd
Copy link

+1 same problem here. Output is something like: [2] + 29217 suspended (tty output)

@stephenmckinney
Copy link

+1 same here. vim 7.3 in iTerm2.

@xnzac
Copy link

xnzac commented May 9, 2012

+1, also on iTerm2 with Vim 7.3.

@ticviking
Copy link

I'm experiencing the same issue, any idea what is causing that?

@rogeliog
Copy link

rogeliog commented Sep 5, 2012

+1, also on iTerm2 with Vim 7.3.

@FreekKalter
Copy link

+1 Same issue here.
OSX 10.7.5, iTerm2, Vim 7.3

@mileszs
Copy link
Owner

mileszs commented Oct 15, 2012

I'm seeing it as well. I will look into it as soon as I can. If someone else has code that fixes it immediately, please note it here.

@rvega
Copy link

rvega commented Nov 9, 2012

+1 I'm on Ubuntu 12.04, gnome terminal and vim 7.3

@rvega
Copy link

rvega commented Nov 10, 2012

This fixed it for me. Thanks to ZyX in stack overflow: http://stackoverflow.com/questions/13322161/ack-in-terminal-vim-is-flashing-its-output-before-presenting-search-results-ho/13322352#13322352

let grepprg_bak=&grepprg
let grepformat_bak=&grepformat
let shellpipe_bak=&shellpipe
try
    let &shellpipe="&>"
    let &grepprg=g:ackprg
    let &grepformat=g:ackformat
    silent execute a:cmd . " " . escape(l:grepargs, '|')
finally
    let &shellpipe=shellpipe_bak
    let &grepprg=grepprg_bak
    let &grepformat=grepformat_bak
endtry

Pull request: #52

@ZyX-I
Copy link

ZyX-I commented Nov 10, 2012

@rvega It is bad idea to unconditionally use this fix: it is non-crossplatform, even on linux it may be wrong depending on value of the &shell option.

@mileszs
Copy link
Owner

mileszs commented Nov 11, 2012

We should definitely try to find a cross-platform solution.

@mileszs
Copy link
Owner

mileszs commented Nov 11, 2012

ZyX-I, do you know in what instances specifically this will fail? What is the result of a failure? For instance, will one simply continue seeing the current odd behavior, or does it crash hard?

@ZyX-I
Copy link

ZyX-I commented Nov 11, 2012

do you know in what instances specifically this will fail?

With cmd.exe, tcsh and dash definitely. csh should fail as well, but I have not tested.

What is the result of a failure?

cmd.exe: unknown command (& is the same as ; in bash AFAIK).

dash: ack is launched in the background and output is not get redirected appearing only in terminal (no support for stdout+stderr redirection with &>, hence ampersand has its usual meaning: launch in background).

tcsh: “invalid null command” error, nothing seems to be actually executed (different syntax).

For instance, will one simply continue seeing the current odd behavior, or does it crash hard?

It does not crash. Nor it does work, none of the variants result in target file being written to.


This is a thing that is supposed to be fixed in vimrc, if you are absolutely sure nobody needs viewing command output temporary before ack finishes you should switch to system(), manual parsing of ack output and setqflist/setloclist. Writing to terminal is not a requirement for &shellpipe (does not do so for cmd.exe), just somebody thought it would be convenient for long-running commands (I guess). Setting it in the vimrc won’t break anything.

I definitely have no idea how such &shellpipe overriding works in powershell, fish, ksh, ash, psh (is it useful as default shell in vim at all?) and a number of shells I don’t even know about. And I am absolutely sure if you want to fix this by overriding &shellpipe then you end up with a big if..elsif..else..endif block.

@tim-vfiles
Copy link

On Kubuntu 12.04 I see the flashing regardless of whether I'm using vim in the terminal or start gvim from krunner, and after flashing my top buffer has already been changed to show the top result.

@solidcell
Copy link

In OSX 10.6 I've been having the same problems. In the terminal it will background vim while running the ack command. In MacVim it will just freeze until I quit (MacVim, not the command). Different terminals and shells make no difference.

@Kagami
Copy link

Kagami commented Jul 27, 2013

On my system (Linux, zsh) simple setting set shellpipe=> in .vimrc solved the problem.

@solidcell
Copy link

Thanks for the advice @Kagami. However, it didn't work for me (on OSX 10.8.2 using zsh).

@kassio
Copy link
Contributor

kassio commented Mar 12, 2014

It's a default behaviour on vim use the same terminal session where vim was open to run system commands, with that when you closes vim the output of ran commands will be on terminal. To change this vim's default behaviour use: set t_ti= t_te=

@kassio kassio closed this as completed Mar 12, 2014
@lesguillemets
Copy link

In that case, does preserving the values &t_ti and &t_te just before called, then set t_ti= t_te=, call ack, and restoring initial values (let &t_ti = saved_value_for_t_ti) work as a fix?

This just occurred to me and I haven't dig into the possibility, so I'm sorry if I'm just showing stupidity.

@ekouters
Copy link

ekouters commented Aug 2, 2016

This is still an issue for me.
@kassio suggests changing vim's default behavior, but this is no option for me.
@lesguillemets links to an issue which was solved with a commit that worked for me. Thanks!

@sfahlberg
Copy link

@Kagami that worked for me- thanks!

@skamsie
Copy link

skamsie commented Feb 14, 2017

I just installed the plugin and I notice I actually have this problem. Using vim on mac

VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Feb  6 2017 06:58:22)
MacOS X (unix) version
Included patches: 1-311
Compiled by Homebrew

Can someone confirm this and maybe reopen the issue?

@mcadam
Copy link

mcadam commented Feb 21, 2017

Same issue for me with vim 8 on mac

@mcadam
Copy link

mcadam commented Feb 21, 2017

@skamsie Just added that set shellpipe=> to my .vimrc and fixed it in the meantime.

@yevhen-m
Copy link

yevhen-m commented Apr 26, 2017

I have this issue as well, output is printed on the screen and distracts a lot. set shellpipe=> fixes this indeed. Is it the best way to solve this issue?

neovim, osx, iterm

@jonathankau
Copy link

jonathankau commented May 24, 2017

Adding set shellpipe=> does fix the issue, but it also blocks shell output from other plugins (like fugitive).

I ended up writing a Vimscript function that takes in the search param and makes sure to set/unset shellpipe properly:

function! Search(string)
  set shellpipe=>
  execute "Ack! \"" . a:string . "\""
  set shellpipe=2>&1\|tee
endfunction

nnoremap <C-F> :call Search("")<left><left>

EDIT: Looks like @ZyX-I pointed out a couple issues with my implementation. I'm not very well-versed in Vimscript, so thanks for the help! 😄

@ZyX-I
Copy link

ZyX-I commented May 24, 2017

@jonathankau This can hardly be considered “properly”. Correct variant is using 1. original &shellpipe value and not anything hardcoded, 2. finally and 3. shelleescape():

function Search(string) abort
  let saved_shellpipe = &shellpipe
  let &shellpipe = '>'
  try
    execute 'Ack!' shellescape(a:string, 1)
  finally
    let &shellpipe = saved_shellpipe
  endtry
endfunction

. Note though that I may be incorrect regarding escaping here though: it is definitely correct variant for ag.vim, but I am no longer using ack.vim.

@soraliu
Copy link

soraliu commented Dec 25, 2017

@jonathankau Thank you! It works.

barn added a commit to barn/ack.vim that referenced this issue Oct 23, 2021
I wouldn't say it fixes mileszs#18 and mileszs#52, but it builds on them. It avoids
the compatibility woes, but only using the shell trick if the shell is
bash or zsh. Otherwise it does the t_te/i swapping.

Both are not very neat, and make this function messier, but making 3
separate functions seemed a lot more busy work.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.