3

Inside vim, I often use conque plugin, so I can run a bash shell inside a vim buffer. I also may try out VimShell soon.

In conque, lets say I start typing some bash command, and before I enter it, I realize I have a typo. Since this is vim, naturally I want to go to normal mode, navigate to the typo, and modify it using some vim command. But when I try that it either says 'change mode disabled within shell' or it does look like it changed, but when I try to run the command, it runs it with the original typo in tact.

Is this possible to do in conque? If not, is there an alternative that allows this?

I understand that it would not make sense to change text from the shell that has already been entered as a command or that is output from some program, but I would still like to change a command that is partially typed out, before I enter it.

What about VimShell, does that allow this?

Further thoughts

After further thought, I take back something I said here. I think it does make sense to be able to edit the output of another program and edit commands I previously entered. Mind you I don't think editing them should do anything other than change what I see in front of me, but this is a Vim buffer, so I don't see any reason why I can't do that.

I also have some thoughts on how I would like commands I am currently typing out to be truly editable before entering them. The plugin should just do whatever it takes to make the command that is eventually entered match what I see on the screen after the prompt. After each edit of the not yet entered command, it could translate those into keystrokes that would result in the same output and current cursor position thus far. Such an approach should also preserve the ability to use tab completion, up and down arrows, and other things that the prompt interprets in a special way.

Is there anything out there that allows something like this?

  • 1
    Conque and VimShell are horrible hacks that work well enough for simple stuff like $ ls or $ grep but fall apart in a multitude of ways once you start to use them as if you were in an actual terminal emulator. You should use a real terminal emulator instead. – romainl Mar 19 '15 at 21:10
  • 2
    Sounds like you might be interested in xiki.org – Rich Mar 20 '15 at 10:07
  • @romainl Actually VimShell is a "real" shell. It is a complete shell written in VimScript. It also does what I was asking about. I can't say if I recommend it or not as I have just started using it. – still_dreaming_1 Feb 20 '16 at 2:45
4

Actually VimShell does what you want and allows to edit both command line and the text generated by previous commands. Other vim shells I tried do not allow this.

Nvim's terminal also doesn't allow terminal buffer editing, you can't even edit the current command line in normal mode.

Also works in emacs shell (checked in spacemacs), term and eshell both allow edit only the command line, but in shell you can also edit the buffer.

Vim with VimShell on the left, spacemacs with shell on the right

  • I didn't actually notice the question was posted almost year ago, the answer describes the current situation (Jan 2016) – Boris Serebrov Jan 21 '16 at 19:44
  • Finally got around to trying this. Works great! So much for all the naysayers that claimed it couldn't be done. As described in this answer, this works even better than the Neovim terminal emulator, which was supposed be better because it is built in. Neovim does not allow jumping around in normal mode on the current line and then editing it from there, but VimShell does! The terminal in Neovim is kind of ridiculous. When you go into normal mode, the cursor jumps to the bottom of the screen! Also, when you use gf from the terminal output to try to jump to a file, it looks in the wrong place. – still_dreaming_1 Feb 20 '16 at 1:49
  • As a side note, from reading through some of the documentation, it becomes clear that VimShell is a complete shell, implemented in Vimscript. It is not a wrapper around another shell. It even works under Windows, somewhat, not that I want to use Windows... It does not read in your .bashrc or .zshrc because it has nothing to do with bash or zsh. It has its own configuration file, .vimshrc. – still_dreaming_1 Feb 20 '16 at 2:57
  • Also just a side note, but the more I look into VimShell, the more promising it looks. It has been under active development by the main developer since 2009, and continues to have regular commits. Seems as if they recently added Neovim support, which is very good since some people may want to use plugins designed exclusively for Neovim, but prefer VimShell over Neovim's terminal emulator. – still_dreaming_1 Feb 20 '16 at 3:07
1

Not quite the solution to your shell-within-vim issue, but if you ever find yourself in a shell (outside vim) wishing you could use vim-style navigation or edits on the shell command you just typed out (or pulled up via the history), you might be interested in the shell's "vi mode":

"When you enter a line in vi mode, you are already placed in 'insertion' mode, as if you had typed an 'i'. Pressing ESC switches you into 'command' mode, where you can edit the text of the line with the standard vi movement keys, move to previous history lines with 'k' and subsequent lines with 'j', and so forth." [GNU's bash reference]

Enable this mode by typing set -o vi in Bash, or sticking that line into .bashrc. It starts you off in Insert mode, but Esc and you can navigate and edit like you're in vi.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.