I'm trying to set up neovim as a python IDE and I'm having some trouble making folding work like I want it to.
My setup:
NVIM 0.4.3
Plug 'Konfekt/FastFold'
Plug 'tmhedberg/SimpylFold'
nnoremap <space> za to toggle a fold with spacebar
My issue is that SimpylFold does not seem to recalculate folds as I edit a file in insert mode. So any function or class I add to a file with insert mode will just say E490: No fold found. Curiously, if I select the lines I've added, delete them and undo, the folds are then correctly recognized. Pasting in a function in normal mode also correctly detects the new fold. So the issue seems to only appear when adding lines in insert mode.
Here's what I know so far:
I've tried :set foldmethod=indent but it falls short of the functionality I'm looking for.
zx forces recalculate on folds. This does work, but the problem is it reapplies foldlevel to the whole buffer, which will undo all the manual fold toggles I've done with space. Couldn't find anything in the documentation about recalculating folds without reapplying foldlevel
From what I can gather, each line in vim has a foldlevel which determines what fold level that line belongs to.. for example all unindented lines in python would have foldlevel=0, Then the entire buffer also has a foldlevel, which determines which levels are actually folded.. so if the buffer's foldlevel is set to 1, then all lines with foldlevel of 1 or more would be folded.
the za command which im using to toggle a specific fold manually seems to operate on a layer separate from all this foldlevel stuff, and when zx is used to recalculate folds, all manual folds/unfolds from za are lost
Anyways, please correct me if I'm wrong, I just switched to linux (and with it, vim) a couple weeks ago, so I'm far from what you'd consider an expert.
Related
I'm using vim for LaTeX and I'm using latex-suite. It gives me nice syntax highlighting and folding, but in large files syntax highlighting gets "confused". If I open all folds, the syntax highlighting turns OK. I would like it to "just work" all the time though.
I seem to recall an option that would increase the number of lines that is used as basis for determining syntax highlighting but I cant find it.
I don't edit LaTeX, but perhaps you want ":syn sync fromstart"? Just be warned that this can significantly slow down Vim since it forces Vim to do syntax highlighting parsing for the whole file rather than a section of the file. See ::help :syn-sync".
Ctrl+L in normal mode forces a redraw and often fixes syntax colour problems.
zRzMzx (i.e., expand all folds, contract all folds, fold to show current line) sometimes fixes syntax highlighting problems related to folds
10 years later, this is still somehow an issue. Similarly as Jeromy, I suggest pressing zRzMzzza which stands for
open all folds
close all folds
open (toggle) the fold I'm on
center buffer on this line
It looks like we need to learn to live with this
I'm trying out code folding in vim but noticed it doesn't seem to mirror across pane splits when using scrollbind to achieve a "2-up" view of a long text/code file with relatively narrow lines (set up as per this guidance).
Is it possible to ensure a fold created in one pane is also created on the other?
I'm just getting familiar with the commands, but it'd probably be z+c (close a fold at the cursor, i.e. 'fold up') and z+o (open a fold at the cursor, i.e. 'unfold')
It strikes me that one use of code folding would be to let one of the split views be an "outline view" (fully folded up, and just used to give an indication of how far through the file the other pane is), but it'd be nice if I could get them fully synced for scrollbind.
nnoremap <Space> za<C-W><C-W>za<C-W><C-W>
in .vimrc allows you to toggle a folding simultaneously in two splits by pressing the space bar.
I'm new to vim and I'm using gVim on Windows. I have two windows open in the same gvim instance and I'm just trying to copy some code from one to another. For some reason when it pastes it replaces the contents of some code with literally this:
list.forEach(function(name){...}------------------------------------------
Obviously, my real code does not have ... or a ton of dashes. What the hell is happening?
The dashes (----------) give it away: The block of code has been folded. (You probably also see the line with different colors (depending on your colorscheme).) Depending on the filetype, folding can be manual or automatic. For your (JavaScript?) code, it's the latter. So when you paste a block of code, Vim automatically detects the block and folds it.
There's a whole lot of commands and options around folding. Read more about it at :help folding. If you find this too confusing (for now), turn it off via
:set nofoldenable
Just press zo on the dashes(-----)
Aside: Use zf on selected (v) lines to fold lines.
zo - Open
zo - Fold
I opened a large javascript file in gvim and am trying to use folding, but I cannot get it to work
Im trying
zo - opens folds
zc - closes fold
zm - increases auto fold depth
zr - reduces auto fold depth
but it says folding does not exist?
Do I have to turn the folding mechanism on?
Why wont this work? Is it a new install of gvim?
The folding behavior depends on the values of a bunch of options. The most important is foldmethod which dictates how folds are calculated. You can see its value with :set foldmethod? which should tell you which of these methods, manual, indent, expr, marker, syntax, diff, is currently in use. Refer to :help 'foldmethod' and the linked help sections for details.
manual is the default method where folds have to be created manually with zf before being opened or closed.
With indent, folds are automatically calculated for you based on indenting, with syntax they are calculated based on the filetype-specific syntax rules.
Sometimes when I'm working on a project I want to play around with some data. Often times the data is on one line and is huge (>25k characters). I understand I could set nowrap and have this line just run off the screen, but I tend to like set wrap for other reasons. So, as a workaround I want to hide these long lines in a marker fold (e.g. {{{ long line }}}). This works fine but I run into a problem with synmaxcol for some reason. If the folded line exceeds synmaxcol then when I open the file, the syntax highlighting runs over. For example:
However, as soon as I open the fold the syntax corrects itself:
Having to open the fold every time is annoying though. As you can see in this example the line is not actually all that long -- it just exceeds synmaxcol. Since synmaxcol is exceeded at a "string" element, the rest of the file is highlighted as a string (so nothing but a singular double quote will stop it).
Why is this happening and how can I fix it? I've tried this with different syntax files and filetypes and it still occurs. I've also tried it with no plugins, a minimal vimrc (containing only syn on) and a modeline to set fdm=marker:synmaxcol=60 and it still happens.
You can manually enter :syntax sync fromstart to force Vim to rescan the syntax from the beginning of the opened file.
I would suggest defining a hotkey for convenience:
noremap <F5> <Esc>:syntax sync fromstart<CR>
inoremap <F5> <C-o>:syntax sync fromstart<CR>
Now you can press F5 to clean up most syntax highlighting problems.
Also, have a look at Vim's fixing syntax highlighting - wiki page
Moreover reading :help :syn-sync-first might shed some more light on the issue.
UPDATE:
I was able to reproduce this behavior on my machine (I'm running Vim 7.3.429).
However, when I wrapped the fold markers {{{ and }}} in block comments, vim correctly rendered the syntax. You can create appropriately wrapped fold-markers using the zf command. See Vim tips: Folding fun.
Normally Vim picks the correct blockcomment string based on the currently active syntax. However, my Vim is pretty vanilla and didn't recognize Ruby syntax. I could specify autocmd FileType ruby set commentstring==begin%s=end in my .vimrc file to set the proper block comment. See :fold-create-marker for more details.
Another solution is to set synmaxcol=0, which will effectively set it to infinity. This causes Vim to check the syntax of the entire line, no matter how long it is. However, I'm not sure what kind of performance penalty you'll have to pay for that.