3

I have heard that Vim has a built-in support of folding for the files written in various programming languages. Particularly I'm interested in cpp, h, hpp files. I would like to achieve such a behavior of Vim when all the function definitions are folded by default in every newly opened source file. I don't want to create every fold manually with zF.

I added the following lines to the end of ~/.vimrc file (which was inherited from spf13-vim distribution):

set foldenable
autocmd FileType c,cpp,h,hpp setlocal foldmethod=syntax

Unfortunately that did not resulted to the desired behaviour. All the files look just the same, and my attempt to hide the function with zc combo leads to error:

E490: No fold found

I would be glad if someone could explain how to enable folding by default in Vim 7.4.

UPD: The code above works good, but there is still an issue with the recently opened files. Say we work on the project called 'sc-client-server' and we've just appended those two lines to ~/.vimrc and now ready to get back to the last edited file:

$ vim ~/.vimrc                                   //Modify config
$ reboot
$ vim ~/progs/sc-client-server/src/st.cpp        //No fold found. BUT: 
$ cp ~/progs/sc-client-server/src/st.cpp  /tmp
$ vim /tmp/st.cpp                                //Auto fold works fine. OR:
$ cd ~/progs/sc-client-server/src/ && mv src source
$ vim ~/progs/sc-client-server/source/st.cpp     //Auto fold works fine. 

Is there any kind of cache or memory inside of Vim that prevents the desired file representation?

Answer Remove all (or specific for you) files from ~/.vimviews folder.

To the off-topic voters https://meta.stackexchange.com/questions/25925/vim-questions-do-they-belong-to-stack-overflow-or-super-user/25930#25930?newreg=00a4918bba924cfa8b1d6a3e82061672

Community
  • 1
  • 1
Vitaly Isaev
  • 5,392
  • 6
  • 45
  • 64
  • I recommend you the [YouCompleteMe](http://valloric.github.io/YouCompleteMe/) plugin. Its a code-completion system based on the Clang analysis engine. – Manu343726 Mar 17 '14 at 08:49
  • This is a question solely about Vim configuration. Not programming related, off-topic on SO. @Manu343726: He's asking about folding, not code completion. – DevSolar Mar 17 '14 at 08:59
  • @Manu343726, unfortunately I am forced to use quite old Linux distribution (RHEL 6.4) which does not provide actual Clang version. – Vitaly Isaev Mar 17 '14 at 09:03
  • @VitalyIsaev: I don't know about the spf13-vim distribution, but the `.vimrc` settings you posted work perfectly for me (Vim7.3). Which version of Vim are we talking about? Have you tried those settings on a vanilla Vim setup (i.e. backing up the spf13 `.vimrc` and trying those settings in a clean one)? – DevSolar Mar 17 '14 at 09:09
  • @VitalyIsaev: ...and while not exactly an answer to your question, I found having a tag list (taglist plugin, http://vim-taglist.sourceforge.net) to be much more comfortable than folding. YMMV. – DevSolar Mar 17 '14 at 09:11
  • @DevSolar, the version is 7.4. I found it very strange that some cpp files are opened with the desired "folded" representation while the others are still lacking folds. Have no idea how to deal with it. – Vitaly Isaev Mar 17 '14 at 09:58
  • So they are **not** looking all the same? Which ones are folded? Which ones are not? What does either group have in common? – DevSolar Mar 17 '14 at 10:24
  • @DevSolar, please look through the update of the topic. – Vitaly Isaev Mar 17 '14 at 10:45
  • @VitalyIsaev: There are various possibilities where and how folds could be cached, especially when you've been folding before and after you installed that spf13 distribution. Look for `~/.vim*` files and directories. That's about as much as I could help you. – DevSolar Mar 17 '14 at 12:09
  • So, what is the question now? – Jacobo de Vera May 06 '14 at 06:59
  • @Jacobo de Vera, everything is clear now – Vitaly Isaev May 06 '14 at 07:04
  • @VitalyIsaev please don't add an answer as an edit to your question. The proper way to do it is to post an actual answer. You are allowed (even encouraged) to answer your own question, but not as an edit to the question. – Keith Pinson Oct 29 '14 at 18:26

0 Answers0