Search code examples
vimfolding

vim - :loadview from a specific file


I've recently started to use vim and want to learn how to save views into files (most importantly for saving folds).

Let's say I'm editing a file called int_array.c and I've finished adding lots of useful folds.

When I execute the following command:

:mkview int_array.v

A file called int_array.v gets created that seems to contain the data for all the folds and such. Here's an example of the code in the folder:

12,44fold
48,56fold
63,90fold
...

Which corresponds to the start/end lines of my folds.

However, when I close and reopen int_array.c, obviously my folds are gone, so I run:

:loadview int_array.v

But nothing happens. No folds are in the document at all: I ran the two commands:

:%foldc

and

:%foldo

which close/open all the folds respectively, but nothing happened, so I conclude that the folds didn't load. (I tested the commands on a file with folds, and they are the correct commands).

Note: Just using :mkview and :loadview to use vim's internal buffer works great, but I'd love to be able to move the view files across machines, so this won't do.

I tried this process on both my local computer and on the instructional machines available to me through ssh, but neither worked. I also tried saving the view to many different file names, but to no avail.

Any idea on what I'm doing wrong? Thanks!

edit: if needed, I can show the contents of int_array.v.


Solution

  • Create views just like you have done:

    :mkview %.v
    

    However :loadview only accepts a number, not a file path. View files are just a bunch of vim commands so you just :source it.

    :source %.v