I have muscle memory of the vi/vim commands. So in bash, I use the vi mode,
for example, I can easily go back to my command history and re-edit previous commands.
Are vi shortcuts available with pry or irb? If so, how do I set it up?
Thank you.
Not sure about re-editing previous commands, but you could use interactive editor gem to start vim-like editing from inside of your irb. Using that, you can start irb, edit your script in vim and let ruby shell execute it immediately. Here is a great tutorial on this: Running Vim within IRB.
Related
I want to know always enjoy the ability to open a Bash instance within Emacs. Does vim have this functionality besides the ability to run commands with :!command?
Conque and Vimshell are very limited, you might as well use :shell which is very reliable if you use Vim in a terminal.
conque
https://code.google.com/p/conque/
conque is terminal emuration.
vimshell
https://github.com/Shougo/vimshell
vimshell is shell implement in vim.
Hey is there a way or plugin to execute Code e.g. Ruby in my case, directly from my vim editor. I know this from Textmate, where you can execute Code with Cmd+R or Cmd+B in Sublime Text2. In Sublime Text it is called Build System.
Thanks for advise!
If you just want to execute the current buffer in Ruby, you could do this in normal mode:
:!ruby %
You could also map that to a shortcut with your leader key:
:map <leader>r :!ruby %<cr>
Which would let you do leader+r to run the file.
My vim has a :rubydo command, select the section of code you want to execute (or nothing to execute the whole buffer), and do
:rubydo
"'<,'>" will be added automatically after ":" if something was selected.
that should to the trick
Well, one simple thing you can use is to execute a command in your shell with :!.
# Typing typing typing...
# Oh! Gotta commit.
:!hg ci -m "Add awesome module xyz"
Or you can use :shell to drop into the shell, if you're going to be doing more complex things.
Use the :!<anything want bash or the calling shell of vim to execute>. So if you have a script named foo.rb, to execute it from within the vim editor call :!ruby foo.rb.
ruby-runner is a vim plugin that allows you to run ruby script from within vim, the good part is you can see your code output along with the your code at the same time.
https://github.com/henrik/vim-ruby-runner
IMHO the better option is to use rcodetools.
when I do rails console my git bash shell permits me to use up arrow to recall commands, and use left/right arrows to modify the text I'm entering
when I run irb the shell ignores backspace and arrow keys
I'm not sure why the arrow keys would work fine in the shell for rails console but not when running irb?
As I just wrote in the related Backspace and arrow keys aren't working in IRB(Git Bash console) on windows machine:
running irb with --noreadline solved this problem for me:
irb --noreadline
What operating system are you running? You may need install the GNU Readline Library and reinstall ruby.
Doing the following command fixed the problem for me on Windows
gem install wirble win32console
As documented here https://groups.google.com/forum/#!topic/rubyinstaller/HgswOz1T-eE, use the below command/alias:
alias irb="ruby -S irb"
i'm on a Windows 7 machine and i've installed Gvim(win32 version not MinGW or something alike), i've written in my _vimrc
set shell=powershell.exe
Now when i type :shell command it must open a new buffer with powershell in it but instead it opens powershell in a new window.
Question : Is there a way to set Gvim ( configuration or plugin ) to open PowerShell in a buffer (like bash)?
Reread documentation for :shell and design-not. Quote from design-not:
Vim is not a shell or an Operating System. You will not be able to run a
shell inside Vim or use it to control a debugger. This should work the
other way around: Use Vim as a component from a shell or in an IDE.
A satirical way to say this: "Unlike Emacs, Vim does not attempt to include
everything but the kitchen sink, but some people say that you can clean one
with it. ;-)"
Of course, somebody does not like this. There are some projects that make it possible to run shell inside vim, most known is Conque which now has windows support. Note that it does not work with unicode.
When I write a little ruby code, after a little bit, I always need to create a new terminal tab to ruby it, to see if it's correct.
Are there any ways to do it in one window? Like a vim plugin or some other tool?
The following should work in vim, after you've saved the file:
:!ruby %
Or even
:!%
This works under Linux when you have the correct "shebang" as the first line of the ruby file:
#!/usr/bin/env ruby
For extra fun, you can map this to a key in your ~/.vimrc:
map <F8> :!ruby %<CR>
Do you mean you need an interpreter to see what your code does? If so, check out irb.
The way you should check if your code works is using unit tests, not running it in the console or irb. Indeed, irb is a good solution for small fragment of code or to check for specific statements.
However, there are some solutions to your specific question.
You can write the code in a file, save it and run it from the console.
ruby filename.rb
If you use TextMate, you can press ⌘ + R to execute the current code
Do as Simone Carletti said.
And for editing and saving your file suggest you Scite.
http://www.scintilla.org/SciTEDownload.html here you can download it for many different operating systems.
You get syntax highlighting in a very lightweight editor for almost everything (html, ruby, eruby, xml,...).
But you will need to have at least a Window Manager running.
in ~/.vimrc
autocmd FileType ruby imap <F8> <C-o>:w <CR> <C-o> :!ruby % <CR>
this way you can save and execute your file at once within insertion mode
In vim:
:!ruby %
will execute ruby on the current file. Remember to save it first!
If you are the Emacs type you should check out ruby-mode (which IIRC was written by Matz) and inf-ruby. See e.g. http://lathi.net/pages/emacs-ruby
You don't say what OS you're using, so I'm assuming either Linux or Mac-OS.
When you're at a command-line and using vim (not gvim) you can do a <CNTRL>+Z to temporarily halt the editor and return to the command-line. Issue any commands you need, then use "fg" to return to the editor.
There are times I'll use :!ruby % from inside vim (or gvim) but sometimes I need the real command line and if I'm ssh'd into a machine the <CNTRL>+Z trick is nice.
Agreed with #Simone Carletti. If you are learning the language and want to make sure that methods/classes are doing what you want then you can use irb.
There is a gem called interactive_editor which enable you to run vim inside irb (side-by-side actually). Watch this Vimcast for demo.