corvid
corvid

Reputation: 11177

"folding" or "hiding" text in vim

This is a complete shot in the dark and I am not sure of the viability of this, but this functionality would be great for me if it was available somehow.

text editors like sublimetext have an option where you can "fold up" blocks of code you are not directly using or have no concern about. For example, imagine an EJS template like so (obviously just for visuals):

<div class="container">
  <FORM name="form">
    <table>
      <tr>
        <% $.each(something, function(k,v) { %>
          <td>
            <input type="<%=v.type%>" name="<%=v.name%>"> <%=v.attribute%>
          </td>
        <% } %>
      </tr>
    </table>
  </FORM>
</div>

Now let's say I'm working with this and finished with the FORM so I don't want it to be in my HTML so I can focus more easily on other things, like layout. EG, I want it to look like this:

<div class="container">
  <FORM name="form"> ... </FORM>
</div>

would such a thing be possible in vim?

Upvotes: 1

Views: 2041

Answers (2)

Th30n
Th30n

Reputation: 303

Yes, of course.

You should type :h 'folds' to get help on folds.

In short:

zf creates a fold (you can select the text with visual mode beforehand or use a motion)
zo opens the fold under the cursor
zc closes it

Most fold commands start with z (mnemonic is Z looks like a fold of paper)

I recommend checking out these tutorials on vim: http://derekwyatt.org/vim/tutorials/

Upvotes: 4

unblevable
unblevable

Reputation: 1316

Try highlighting the block of code that you want to fold and then use za. Use za again to unfold the block of code.

See :h folding for more information on folding in Vim.

As a side note for your particular example, you can use the plugin MatchTagAlways to quickly highlight code around html tags.

Upvotes: 2

Related Questions