5

i am using vimshell to execute commands inside vim

nnoremap <leader>vs :VimShellPop<CR>

with this key mapping i can open vim shell and execute commands like 'bundle install' and then type exit to exit VimShellPop window but i want set a key mapping

nnoremap <leader>bi :

to open up vimshellpop execute the bundle install command and exit once i get completed..is it possible in vimshell?

Rajanand02
  • 1,303
  • 13
  • 19
  • Interesting problem, but I don't think I fully understand it. Just to clarify - what are the commands you are trying to bundle? Could you write the "Here is the thing I would like to do but I have the syntax wrong" line of code? – Floris Dec 28 '13 at 20:18
  • 1
    I don't know the hacks employed by the plugin, but doesn't simple appending a la `nnoremap bi :VimShellPopbundle install` work?! – Ingo Karkat Dec 28 '13 at 20:28
  • i want to execute specific set of commands like 'bundle install', 'git status' etc. inside vimshell but to make it more productive and faster i want to map keys for those commands..for example 'nnoremap g gg=Ggi' with this key mapping i can make auto alignment much more faster..in the similar way if i press 'bi' i want to execute bundle install command inside VimShellPop window and it should exit after installing bundles from my Gemfile.. – Rajanand02 Dec 28 '13 at 20:32
  • @IngoKarkat: the key mapping you mentioned will open vimshellpop window and append bundle install command but you have to hit enter to execute bundle install and type exit manually after it gets completed... – Rajanand02 Dec 28 '13 at 20:41
  • Try `nmap bi :VimShellPopbundle installexit`. – Ingo Karkat Dec 28 '13 at 20:44
  • tried... it simply append exit to bundle install..bundle install commands starts executing only after i hit enter...seems not working.. – Rajanand02 Dec 28 '13 at 20:47
  • Okay one last try: `nnoremap bi :call feedkeys("bundle install\CR>exit\CR>", "t")VimShellPop` – Ingo Karkat Dec 28 '13 at 20:54
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/44072/discussion-between-rajanand02-and-ingo-karkat) – Rajanand02 Dec 28 '13 at 21:03

2 Answers2

5

The vimshell plugin provides an interactive shell inside a Vim buffer. Apparently, you don't need the interactivity (because you intend to immediately exit after issuing the shell command). For that, you don't need the plugin itself; the built-in :! command already allows you to launch external commands:

:nnoremap <leader>bi :!bundle install<CR>

If you want to keep the output visible, you can read it into a scratch buffer:

:nnoremap <leader>bi :new<Bar>0r!bundle install<CR>
Ingo Karkat
  • 167,457
  • 16
  • 250
  • 324
  • this key mapping takes me out of vim and comes back after i hit enter..i want to continue editing my code after issuing bi and at the same time i want to check out the result of my command..if it is vimshellpop i could check the result in a pop up window above my code..that i why i prefer vimshell rather than native shell commands inside vim using !... – Rajanand02 Dec 28 '13 at 21:01
  • Ah, I see, that part is missing from your question. I've added an alternative mapping with a scratch buffer inside Vim. – Ingo Karkat Dec 28 '13 at 21:07
1

Having an interactive shell in Vim is one of Vim's stated non-goals (cp. :help design-not), so the plugin has to jump through several hoops to make this possible. Those hacks are causing these problems (of defining a proper mapping, as evidenced by the attempts in the question's comments); lack of automation (like through mappings) is a limitation of this approach.

You may contact vimshell's author (via email or GitHub issue); he's usually very open and responsive! He's in the best position to make such mapping work.

Ingo Karkat
  • 167,457
  • 16
  • 250
  • 324
  • okay i will try to mail [him](https://github.com/Shougo) or create an issue in [github](https://github.com/Shougo/vimshell.vim)... – Rajanand02 Dec 28 '13 at 21:41