I set vim's foldmethod to indent which works very well when writing Python except when I have a comment line. For example, if I have this bit of code:
def myFunction():
# here is my comment
myString = "hello"
myInt = 2
If I have my cursor on the comment line and type "za" I get get an error saying "E490: No fold found." If I have the cursor on the line beginning with "myString = " I will geta fold like this:
def myFunction():
# here is my comment
+--- 2 lines: myString = "hello" -------------------------
In both cases I would like to get this fold:
def myFunction():
+--- 3 lines: # here is my comment -------------------------
Basically the comment line should be treated like anything else. I haven't come up with an answer from searching the web. Any ideas? Thanks!
You have to set foldignore to nothing.
:set foldignore=
From :help foldignore
:
'foldignore' 'fdi' string (default: "#")
Used only when 'foldmethod' is "indent". Lines starting with
characters in 'foldignore' will get their fold level from surrounding
lines. White space is skipped before checking for this character.
The default "#" works well for C programs. See |fold-indent|.
From :help fold-indent
:
Some lines are ignored and get the fold level of the line above or below it, whatever is the lowest. These are empty or white lines and lines starting with a character in 'foldignore'. White space is skipped before checking for characters in 'foldignore'. For C use "#" to ignore preprocessor lines.
At least in my vim, foldignore
is set to the character '#'. Set it to empty, with a command like
:set foldignore=
to have those lines included in the fold.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With