Skip to main content

Vim for irb

Ever used irb and wished you had safed your commands or could edit them using Vi? Ever tried something new in irb, and then had to painfully copy and paste it to the .rb file? Slime.vim from Jonathan Palardy will be your new best friend.

Slime.vim lets you send highlighted text to a different terminal. This means you can write a few commands, send them to a terminal running irb, notice you want to change something in your first command, modify that line in Vi and resend it to irb, and so on.

Put slime.vim into ~/.vim/plugins

In one terminal:

1. start a named screen

2. name the window

You'll be prompted for the window's name, "Set window's title to:"
irb_window
3. start irb

In a different terminal, start vi and type irb commands, highlight one or multiple commands (ESC V to highlight the current line, ESC vip to highlight a paragraph), type C-c C-c to execute the highlighted text in the other terminal. The first time you'll be prompted for session and window, enter irb_session and irb_window (or whatever name you gave it).



This works for anything in your terminal, I like it for very long commands (using files in some crazy far away subdirectory), Singular, Macaulay2, mysql, and of course irb.

Comments

  1. This looks great. Is there any way to use it with GVIM? You might also be interested in a gem called Sketches with a different approach to essentially the same workflow.

    http://sketches.rubyforge.org/

    ReplyDelete

Post a Comment

Popular posts from this blog

Latex: Centering table larger than textwidth

Usually, you can center tables with \center. But when the table is longer than the \textwidth, it will be align with the left side margin. You can temporarily adjust the textwidth.

% allows for temporary adjustment of side margins
\usepackage{chngpage}

\begin{table}
    \begin{adjustwidth}{-.5in}{-.5in} 
        \begin{center}
        \begin{tabular}{|c|}
            \hline
And here comes a very long line. And here comes a very long line. And here comes a very long line.  \\
            \hline
        \end{tabular}

        \caption{This Table is longer than the text width. And its caption is really long, too. This Table is longer than the text width. And its caption is really long, too. This Table is longer than the text width. And its caption is really long, too. This Table is longer than the text width. }
        \label{myTable}
        \end{center}
    \end{adjustwidth}
\end{table}

Uploading a file with JQuery

You can easily submit data in an html form via jQuery's $.post. But you need to do a little more to upload a file. I suggest the jQuery Form Plugin.

Here is the HTML form:
<html> <head> <title>Title</title> </head> <body> <form action="/test.cgi" enctype="multipart/form-data" method="post"> <input name="myFile" type="file" /> <div id="results"> </div> </form> </body> </html>
This is the Javascript file myFrom.js:
$(document).ready(function() { $('form').ajaxForm( { beforeSubmit: function() { $('#results').html('Submitting...'); }, success: function(data) { var $out = $('#results'); $out.html('Your results:'); $out.append('<div><pre>'+ data +'</pre></div>'); } …

Highlighting paragraphs in Latex

When revising a document, I often want to highlight my changes, so my collaborators can easily see what I changed.

\underline works for single words, but it puts everything in a horizontal box and long text isn't wrapped anymore.

Instead, I use the package soul and \ul to underline.
\usepackage{soul}
Or you can highlight text using \hl. This will underline the text unless you use the color package, then it turns into typical marker-highlight.
\usepackage{color}