neovim / neovim

Vim-fork focused on extensibility and usability
https://neovim.io
Other
82.21k stars 5.62k forks source link

"shellcmdflag=-ic" causes numerous problems (WAS: bash: no job control in this shell) #1756

Closed xanderdunn closed 9 years ago

xanderdunn commented 9 years ago

Mac OSX 10.10.1. I installed NeoVim using Homebrew exactly as described in the Wiki.

When I copy text from the Mac's Messages app and paste it into NeoVim by pressing p, it goes from looking like this: screen shot 2014-12-29 at 00 43 54

To this: screen shot 2014-12-29 at 00 39 19

I don't expect to see that bash error, or to have the new lines turned into ^M.

I'm using Terminal.app that comes with Mac OSX.

NeoVim :version

NVIM 0.0.0-alpha+201412282305 (compiled Dec 28 2014 23:33:40)
Commit: b64b5372fb62b0fddd1533fd845e47266151d103
Build type: RelWithDebInfo
Compilation: /usr/local/Library/ENV/4.3/clang -Wconversion -O2 -g -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -DINCLUDE_GENERATED_DECLARATIONS -DHAVE_CONFIG_H -I/tmp/neovi
m-8K2quU/build/config -I/tmp/neovim-8K2quU/src -I/tmp/neovim-8K2quU/.deps/usr/include -I/tmp/neovim-8K2quU/.deps/usr/include -I/tmp/neovim-8K2quU/.deps/usr/include/luajit-2.0 -I/usr/local/opt/gettext/incl
ude -I/usr/include -I/tmp/neovim-8K2quU/build/src/nvim/auto -I/tmp/neovim-8K2quU/build/include
Compiled by admin@Alex-Dunns-MacBook-Pro.local  Features included (+) or not (-):
+acl             +cmdline_hist    +diff            +farsi           +iconv           +listcmds        -mouse_gpm       +path_extra      +scrollbind      -tag_any_white   +virtualedit     +writebackup
+arabic          +cmdline_info    +digraphs        +file_in_path    +insert_expand   +localmap        +mouse_netterm   +persistent_undo +signs           +terminfo        +visual          -X11
+autocmd         +comments        -dnd             +find_in_path    +jumplist        +menu            +mouse_sgr       +postscript      +smartindent     +termresponse    +visualextra     -xfontset
-browse          +conceal         -ebcdic          +float           +keymap          +mksession       -mouse_sysmouse  +printer         +startuptime     +textobjects     +viminfo         -xsmp
+byte_offset     +cscope          -emacs_tags      +folding         +langmap         +modify_fname    +mouse_urxvt     +profile         +statusline      +title           +vreplace        -xterm_clipboard
+cindent         +cursorbind      +eval            -footer          +libcall         +mouse           +mouse_xterm     +quickfix        +syntax          -toolbar         +wildignore
-clipboard       +cursorshape     +ex_extra        +fork()          +linebreak       -mouseshape      +multi_byte      +reltime         +tag_binary      +user_commands   +wildmenu
+cmdline_compl   +dialog_con      +extra_search    +gettext         +lispindent      +mouse_dec       +multi_lang      +rightleft       +tag_old_static  +vertsplit       +windows
   system vimrc file: "$VIM/nvimrc"
     user vimrc file: "$HOME/.nvimrc"
 2nd user vimrc file: "~/.nvim/nvimrc"
      user exrc file: "$HOME/.exrc"
  fall-back for $VIM: "/usr/local/Cellar/neovim/HEAD/share/nvim"

My .nvimrc

justinmk commented 9 years ago

Are you using clipboard=unnamedplus? There's a known issue with clipboard, at the moment.

justinmk commented 9 years ago

Oh, but the job control message is weird, haven't seen that before. I assume it's a terminal control sequence that is getting wrongly interpreted.

xanderdunn commented 9 years ago

It looks like I'm using clipboard=unnamed

justinmk commented 9 years ago

Ok, try without that. See #1690

Does the same problem occur if you use CMD+V? Any different results if you :set paste before pasting?

xanderdunn commented 9 years ago

Without clipboard=unnamed,

Pressing p inserts the same bash error text, without any of my copied text: screen shot 2014-12-29 at 01 12 35

Command+V sucessfully pastes my text with no bash error, but it cuts off the beginning of it: screen shot 2014-12-29 at 01 11 58 However, I notice the same cutting off behavior in vim, so this is not NeoVim-specific bug.

Being in :set paste mode has no effect on either's behavior.

Thanks!

justinmk commented 9 years ago

I noticed set shellcmdflag=-ic in your vimrc, that can be a problem. Try removing that line and restarting nvim.

Interactive shell is definitely a test case I don't think we have bothered with yet. It would be great to support it though (aliases and stuff). It has a history of problems on Vim, I don't know if it is for technical reasons or just historical.

justinmk commented 9 years ago

I don't know why that would cause your issue though, I should go to bed...

jamessan commented 9 years ago

Interactive shell is definitely a test case I don't think we have bothered with yet. ... It has a history of problems on Vim, I don't know if it is for technical reasons or just historical.

I don't think this is unique to Vim. The shell is being told to run interactively, so it expects to be running interactively. I wager you'd see similar behavior from any other program that let's you execute commands through a non-interactive shell but lets you tell the shell it should be interactive.

justinmk commented 9 years ago

@jamessan You are right. I was thinking about this some more, and reviewed some other threads. The only way to robustly support "interactive" shell is to actually open a shell (in a terminal emulator or tmux pane).

Incidentally it would be nice to have good support for this in n/vim, because making the user's aliases etc. available is part of the "unix as IDE" philosophy.

The only way to achieve this is either with (1) a "strategy" collection like gtfo.vim or dispatch.vim, or (2) by actually hosting a terminal emulator in a Neovim window. The thought of hacking together support for all the various terminals makes (2) actually look somewhat appealing...

jamessan commented 9 years ago

or (2) by actually hosting a terminal emulator in a Neovim window. The thought of hacking together support for all the various terminals makes (2) actually look somewhat appealing...

Do you mean running a terminal emulator or implementing one? If the latter, then I strongly suggest otherwise. Vim (:shell in gvim) and Emacs have both done this (with more success in Emacs) but they're both awful.

Incidentally it would be nice to have good support for this in n/vim, because making the user's aliases etc. available is part of the "unix as IDE" philosophy.

Isn't that better served by actually using the tool for what it's designed for? If the command isn't being run for the benefit of Vim, then do it from an actual terminal. If it is, then either type out what you mean (for one-offs) or script it.

I guess I'm a bit of a luddite in that regard, though. I never got into aliases, so don't have the issue that so many other people seem to run into.

justinmk commented 9 years ago

Vim (:shell in gvim) and Emacs have both done this (with more success in Emacs) but they're both awful.

The idea has been floated and although I have not much interest in working on it, I'll be happy to see how close others can get. I agree though, eshell, ansiterm, in emacs are unbearable. Maybe it would be better to work on improving integration with tmux.

I guess I'm a bit of a luddite in that regard, though. I never got into aliases,

It's not that aliases are so important but that the user is able to use the shell as an extension in harmony with the editor. I am most interested in enabling acme-like workflows where the editor is used to craft commands and there's a feedback loop. The shell should be a REPL for your OS.

tarruda commented 9 years ago

Vim (:shell in gvim) and Emacs have both done this (with more success in Emacs) but they're both awful. The idea has been floated and although I have not much interest in working on it, I'll be happy to see how close others can get. I agree though, eshell, ansiterm, in emacs are unbearable. Maybe it would be better to work on improving integration with tmux.

While implementing a terminal emulator from the scratch would be a bad idea, libvterm implements the most complicated parts of a full featured terminal emulator while exposing a pluggable input/output system. That fits perfectly with Neovim job control system(though it still needs to be enhanced to allow spawning jobs with pty).

When I'm done fiddling with the UI, integrating libvterm will be my next task, I will use to create an experience similar to vimshell

xanderdunn commented 9 years ago

Yes, it was my desire to run shell commands (including all my many aliases) while in vim that lead me down the path of:

set shell=bash\ --login
set shellcmdflag=-ic    " :! commands will now occur in interactive shell (bash)

I just updated NeoVim to: NVIM 0.0.0-alpha+201501021831 (compiled Jan 3 2015 09:48:55) Commit: d61111530541f74df89c010e5edfb633a412dc72

and I had to remove the above two lines from my .vimrc. I was seeing all kinds of weird problems that made nvim unusable. On first executing nvim, it would be stopped by bash. Then I would start the process with fg 1, and it would seem fine. But, I would open a file :e ~/Desktop/test.shit and it would stop drawing properly: key strokes would appear written in the bash prompt rather than take visual affect in nvim. All of these problems went away when I removed these two lines from my .vimrc.

As for this paste problem, I no longer see the bash control flow error text inserted into my buffer with the interactive shell disabled. However, I have the same ^M character insertion problem with I use p instead of Command-V: screen shot 2015-01-03 at 10 41 13

justinmk commented 9 years ago

Resolved by :terminal :)

Note that shellcmdflag=-ic is still unsupported. Use :terminal where interactive shell is needed.

calbertts commented 4 years ago

After set shellcmdflag=-ic, fugitive plugin stopped working, just saying.

justinmk commented 4 years ago

After set shellcmdflag=-ic, fugitive plugin stopped working, just saying.

Only -i should be removed. Or rather, remove shellcmdflag=-ic from your config, because -c is the default.