News for hackers. Stuff that matters.
Re:Vim After 11 Years by brown9-2 on Tuesday February 19, 2013 @11:57AM (#5245370)
One of Vim’s strengths is that it starts lightning fast, so starting Vim from the terminal is trivial. With a modern, 256-color terminal like iTerm2 or Gnome Terminal, it will even look like gVim. But the best part is that you can drop into the command line at any time with Ctrl-Z, which suspends Vim, and your working directory is where you left off.

Is there any reason to do this instead of !sh within Vim to drop into a shell?

Re:Vim After 11 Years by johncoltrane on Tuesday February 19, 2013 @12:37PM (#5245683)
You can do `:sh` instead of `:!sh`.

Ctrl+z suspends Vim so that you are back to where you were when you started Vim.

:sh starts a new shell in Vim's current directory.

Both options have their use.

Re:Vim After 11 Years by niggler on Tuesday February 19, 2013 @12:06PM (#5245440)
You end up creating a new session each time when you do !sh. backgrounding Vim lets you use the same shell instance.

The other issue I have in general with the ! form is that some applications mess up osx vim. For example, try dropping into a node session (!node) and then quitting.

Re:Vim After 11 Years by slurgfest on Tuesday February 19, 2013 @12:07PM (#5245450)
have your terminal map Ctrl-Z to fg, and you can cycle in and out of the shell almost instantly from vim with that key.
Re:Vim After 11 Years by tomp on Wednesday February 20, 2013 @03:48AM (#5249527)
How can you do that? For me, this just doesn't work...

  bind '"\C-z":"fg\n"'
  bind -x '"\C-z":"fg"'
  echo 'Control-z: "fg\n"' >> ~/.inputrc
If I replace "z" with "a", it works.

C-z works otherwise, e.g. C-v C-z prints ^Z in shell, and C-z suspends programs (e.g. vim). Is it a bash thing or a terminal thing (I'm using iTerm2)?

Re:Vim After 11 Years by ordinary on Wednesday February 20, 2013 @10:04AM (#5250769)
Try:

  set bind-tty-special-chars Off
in your .inputrc, before you do the bind on C-z.

The readline man page is a little misleading:

  bind-tty-special-chars (On)
    If set to On, readline attempts to bind the control characters treated 
    specially by the kernel's terminal driver to their readline equivalents.
Disabling it doesn't actually stop readline from binding those control characters. It just enables you to override those default readline binds. If the variable is set to On (the default), that's not possible.
Re:Vim After 11 Years by tomp on Wednesday February 20, 2013 @10:26AM (#5250896)
This does not work for me, unfortunately...

Also, another thing I have noticed, is that I cannot catch the SIGTSTP (Control-Z) signal with the `trap` command. I can catch other standard signals, e.g. SIGINT (Control-C), but not SIGTSTP (along with SIGSTOP and SIGKILL, obviously).

Re:Vim After 11 Years by bsg75 on Tuesday February 19, 2013 @12:31PM (#5245633)
As in Ctrl-z to background, and Ctrl-Z to fg back into vim from the shell?
Re:Vim After 11 Years by danneu on Tuesday February 19, 2013 @12:58PM (#5245839)
I'm sure they mean `map fg <c-z>` in Vim so that `fg` from Vim lines up with `fg` from shell and you can repeat the same stroke to easily "toggle" Vim.
Re:Vim After 11 Years by slurgfest on Tuesday February 19, 2013 @04:14PM (#5247076)
Yes.
Re:Vim After 11 Years by statico on Tuesday February 19, 2013 @10:17PM (#5248754)
:!sh will work, but it puts you in an entirely new context (environment and CWD). :sh is just plain awful and doesn't emulate anything correctly.

I recommended ^Z/fg/bg because it's the fastest, easiest way to get to a good, functional shell if you're not using a multiplexer (tmux/iTerm2). If you map ^Z in your shell to "fg\n" then switching is lightning fast.

Re:Vim After 11 Years by dhimes on Tuesday February 19, 2013 @12:01PM (#5245414)
IIRC, !sh starts a new shell- so it depends on your context I suppose.
Re:Vim After 11 Years by brown9-2 on Tuesday February 19, 2013 @12:18PM (#5245528)
I think this is the explanation, I usually only find myself wanting to temporarily "stop" Vim and do something on the shell for quick one-off commands that are fine in a subshell - not to keep a backgrounded Vim instance around for longer than that. The blog author seems to have a different use in mind.
Re:Vim After 11 Years by statico on Tuesday February 19, 2013 @10:17PM (#5248755)
That's pretty much it. See above comments regarding context.