Is Vim's Haskell syntax highlighting broken? - haskell

It seems to me that Vim's syntax highlighting for Haskell is broken, or very buggy. Multiline comments in Haskell (beginning with {- and ending with -}) are arbitrarily greened-out and un-greened-out. Sometimes dragging the mouse over the commented code causes it to reverse color.
Has anyone else been experiencing this problem?

Vim's syntax highlighting trades off accuracy for performance, by default. To do this, it only examines a certain number of lines before the current position to determine how things should be highlighted. This means that it can sometimes get out of sync.
The different methods it uses to determine how much text to examine can be seen at :help :syn-sync. If you want it to Just Work, use :syn sync fromstart to make Vim consider the entire buffer up to the cursor to determine the highlighting.

This happens with other languages as well, it's just the way vim works. It does not actually use a parser, which would be required to be completely accurate all of the time. Actually, sometimes you may need more than just a syntax parser.
http://vimdoc.sourceforge.net/htmldoc/syntax.html

Related

Vim folding breaks colorscheme [duplicate]

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

Pair completion in Vim

I do my coding in Vim and recently have been getting more annoyed by its pair completion features. I don't really see the need for pair completion in general as I tend to naturally try to close pairs myself (by pair here I mean type the closing ')' of a set of parentheses, for example). What really annoys me is when I have text already written and to surround it by quotes for example I'll be at the beginning of the word, type ' and then two will pop up right over there rather than just 1 and then me pivoting to the end of the word and typing the other exclamation point. Anyways, that's it for my rant, so any help on stopping my vim from doing this would be appreciated. I use spfvim-13 (https://github.com/spf13/spf13-vim) and have only modified the .vimrc slightly. I wasn't able to pinpoint exactly from where this specific issue arises.
This is not a native vim behavior, it's definitely some plugin causing it. I can't pin-point a particular plugin that spf13 might be having for this, I looked for popular ones I know, like simple_pairs, delimitMate etc.
Best way to investigate what's causing is to just see the output of :verbose imap ' and you'll come to know where it's being set and then remove that plugin / setting.

vim: how to get parentheses matching like in DrRacket et al.?

I want to my vim setup to color my parentheses as is default in the DrRacket IDE for Scheme.
I know how to set up parentheses matching using the built-in MatchParen hlgroup but I think it's going to be hard to use that to good effect.
DrRacket highlights matching parenthese as follows:
make the background of the parentheses and all their contents a bit darker
also do this for any parentheses inside the parentheses
only do this for parentheses where the cursor is (like MatchParen)
Take a look at this screenshot to get a clearer idea what I mean:
This way you get a good visual feedback when writing paren-heavy languages such as Lisp.
Does a plugin exist that implements this behaviour? Or do you have tips on how I could
implement this myself?
I haven't seen a plugin implementing the staggered background coloring (and that would be difficult with low-color terminals and Vim shortcomings in the syntax highlighting), but a popular plugin is rainbow_parentheses.vim - Better Rainbow Parentheses, which uses different colors for each set of parens.
I wanted the same thing, so I forked the script and changed it accordingly.
Let me know if it works for you (and don't forget to set the colours to match your colour theme, as the defaults are unlikely to be pleasant!)
https://github.com/cbranch/rainbow_parentheses.vim
This script doesn't highlight on the cursor's position, but hopefully it is not difficult to merge the behaviour of the MatchParen plugin with this one. I personally don't care for it, so that is an exercise for others :)

Using linebreak and line options at the same time

The documentation of linebreak says:
This option is not used when the 'wrap' option is off or 'list' is on.
I find this unsatisfactory. Is there a workaround to use certain listchars and linebreak?
My ideal .vimrc looks like this:
set linebreak
set list
set listchars=tab:▸–,trail:·,extends:»,precedes:«,nbsp:⍽
… so I’m not actually interested in eol:$, which is presumably the reason why list conflicts with linebreak (that’s just my assumption but I see no other plausible reason for them to conflict).
There’s a closely related question but in that the OP specifically wants the EOL mark, and the accepted answer addresses only this, so it’s not useful for me.
I would guess (but do not know for sure) that the current implementation cannot deal with the change of the displayed width when a Tab character shrinks to ^I (assuming it has no value in 'listchars'). In any way, I think Vim could be enhanced to do just what you want, though it might not be easy to implement. It might be worth to raise this request on the vim_dev mailing list.
There are little good workarounds; one could theoretically use the new conceal feature to emulate certain things of :set list, but it interferes with syntax highlighting and there's only one choice for highlighting.

Is there a way to move within a file in Vim similar to Emacs' Isearch?

I've been using Vim for some time and I feel that I'm finally becoming somehow 'fluent' with it, but some of the feature listings, videos and other stuff I've seen (particularly Tim Visher's Vimgolf in Emacs series) really convinced me to give Emacs a try.
So for the past week, I've been using Emacs almost exclusively. I really miss some concepts I'm familiar with from Vim (mostly the action-movement style, things like ci" etc.), but one thing I really learned to love in Emacs is the way to move around a file with Isearch.
For example, if I wanted to move to a line where a function fn is called, and there were 2 other instances of 'fn' between the point and the position I want to move to, I'd do C-s fn C-s C-s. If I wanted to do the same in Vim, I'd have to do something like /fn <CR> n n :noh <CR>, which is nowhere as nice, so I'd probably just check the line number and do #G wwwww....
So my question is: is there a way to emulate the efficiency of Emacs' movement with search in Vim? It doesn't have to use search, I'm just looking for something other than the cumbersome go-to-line and forward several words I described above.
Edit: Item 4 in Effective Emacs describes nicely what I'm trying to accomplish.
What is described in your link is exactly my primary mean of movement in Vim: /foo<CR>nn for incremental forward search and ?bar<CR>nn for incremental backward search.
I don't see what is more efficient in <C-s>foo<C-s><C-s> and <C-r>foo<C-r><C-r>: that's even more keystrokes!
Anyway, I think that :set hlsearch is your problem. If all the matches are contained in the viewport that's OK but, as soon as some matches are hidden it becomes useless. I don't have set hlsearch so /foo<CR> is quite the opposite of inneficient for me.
Well, another problem is having (at least) three functions with the same name in the same file…
Vim has wonderful text-ojects: } or ]m that are very useful when looking at some code for the first time.
You can emulate Emacs with this keymap: cnoremap <C-s> <Cr>/<C-p>.
Though Vim has better ways for moving around than searching. Have you tried ctags?
I also recommend the EasyMotion plugin for quickly moving around in the visible area of the text.
I think you're looking for
set incsearch
you can couple it with
set hlsearch
for even better results.
Also check out "*", it's pretty awesome.

Resources