You are not logged in.
Howdy-ha, everyone. Here's a question: Both Geany and Kate place code folds at branching and looping statements, and I know Vim is capable of doing the same. However, the one thing these two graphical editors do that I'd like to see in Vim is to highlight the complete block of code when the mouse pointer is placed over the fold marker. Here's an example in Kate (please ignore the grotesque colors
):
The advantage of this is that it helps to catch logical errors without needing to sroll back-and-forth through an entire file, and reduces the necessity of checking line-by-line. Is such a thing possible in Vim (say, when the cursor is placed over the fold marker)? My preliminary searches make me think so, but I haven't found anything concrete; searches like "vim fold highlight" and "highlight branching" and such don't turn up much other than a) regular syntax highlighting or b) changing the colors of the fold markers themselves. Thanks for any tips or pointers.
Offline
Well, it isn't automatic on folding, but the matchit.vim plugin (which is helpfully already included with vim since 6.0 in the macros/ directory) makes % jump across matching control structures in addition to things like parentheses, so you can use that and either do v% yourself or remap % as v% to highlight blocks of code nicely. I had thought that there was a foldenter event that you could hook an autocmd up to and fire the v% whenever you entered the fold, but I can't find it anywhere in the documentation, so maybe I just imagined that it exists. Also, I have to say, thanks for asking about this, I wouldn't have gone looking for something like matchit otherwise, but I'm definitely liking it now that I know about it.
Last edited by Wibjarm (2012-06-21 18:56:07)
Offline
I think you would need a way to continuously report the current mouse position to vim? I know vim can handle mouse-clicks, but I'm not so sure about continuous mouse position.
However, thanks to recent posts about how to integrate vim with gdb, I wonder whether something could be done with python. It might take a little work, but if you can get python to continuously track the mouse, and embed that in a vim plugin, you could get some interesting results.
Offline
It should be easy to get this behavior when the cursor is over the fold marker, but I don't know about the mouse.
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
Thanks for the replies, folks, but I should have clarified: I don't care about mouse support. It's finicky enough in Vim as it is, and I only use it for selection/cursor placement (I've actually been using Kate in Vim-compatability mode, which actually isn't too bad). I meant the actual input cursor; sorry about the confusion.
I should also add that the reason I'm looking at this as a feature is because I'm as noob as they come when it comes to coding, and this feature helps me quickly find my little screw-ups (and move on to bigger, better screw-ups) rather than spend time looking for them. So digging deep into Vim's code/feature set might be beyond me at the moment. ![]()
EDIT - @ Wibjarm: Matchit may actually be helpful; I'll play around with it and see how it works. Thanks!
Last edited by ANOKNUSA (2012-06-21 22:01:48)
Offline
I should also add that the reason I'm looking at this as a feature is because I'm as noob as they come when it comes to coding, and this feature helps me quickly find my little screw-ups (and move on to bigger, better screw-ups) rather than spend time looking for them.
In your posts, you give the impression of being more knowledgeable than that. Maybe you're being modest.
Anyway, I always find vim's syntax highlighting useful for noticing errors. Big give-away: when brackets start with the red background, it tells me to look for mismatched brackets
. Also, I find this advice useful: solve errors from top to bottom (first to last). Due to cascade effects, later errors will often disappear after resolving the earlier ones.
Sorry to get off-topic, it just seems like you have an X-Y problem, you know? - maybe learning more tricks for solving compile-time errors will obviate the requirement to highlight blocks.
.
Offline
Toward the end of matchparen.vim comment lines 140 and 141 as seen below and directly following them add the one uncommented line:
" exe '3match MatchParen /\(\%' . c_lnum . 'l\%' . (c_col - before) .
" \ 'c\)\|\(\%' . m_lnum . 'l\%' . m_col . 'c\)/'
exe '3match MatchParen /\%>' . c_lnum . 'l\%<' . m_lnum . 'l/'edit: or the vanilla matchparen may be just what you want if you're content with highlighting the braces themselves, not the block of code. I actually don't like either, but with matchparen already doing most of the work, this one-line addition is pretty simple.
Last edited by Trilby (2012-06-21 22:31:24)
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
That's what I use: it doesn't colorize the folded block, but draws a line on the left side of the editor that marks the unfolded piece of code. The parameter is set in .vimrc with 'set foldcolumn=1':
set foldmethod=marker
set foldnestmax=10
set foldcolumn=1-- and the piece in the colorscheme file (again, as present in my setup):
hi FoldColumn ctermfg=14 ctermbg=none
hi Folded ctermfg=14 ctermbg=0The result is more or less what you want, though achieved a bit differently.
:: Registered Linux User No. 223384
:: github
:: infinality-bundle+fonts: good looking fonts made easy
Offline
I should also add that the reason I'm looking at this as a feature is because I'm as noob as they come when it comes to coding, and this feature helps me quickly find my little screw-ups (and move on to bigger, better screw-ups) rather than spend time looking for them.
Does not do exactly what you are looking for, but does this help?
Offline