Closed normenmueller closed 6 years ago
You could setlocal formatprg=hindent
and then execute gq
on your visual selected area... But that brings back the very problem this plugin aims to solve (your code will be replaced by a hindent error, if the code has a syntax error).
I will try to provide that feature in this plugin on its next version as soon as I can. In the mean time you might just setlocal formatprg=hindent
and gq
as I've described above.
👍 Will do. Looking forward to your next update :)
BTW, the approach formatprg
works but on comments. Say, I select a code block and gq
, then this code block is formatted nicely. But if I just select a comment block and gq
, then the lines are not formatted according to the line length. Do you know a workaround?
Oh that!. It's been a recurrent problem for me as well, the thing is, if you define your own formatprg
you're effectively overwriting vim's default behavior on that (the internal format function). Whenever I need to format trough an external program, but also need to wrap up text nicely with gq
on its default function, I use a custom function: https://github.com/alx741/dotfiles/blob/master/vim/.vimrc#L524-L553 And map it to g=
. For Haskell, I use this plugin (also mapped to g=
) so whenever I need hindent formating I just hit g=
but as formatprg
remains empty, I have gq
on the default behavior (really handy for comments formatting)
Thanks! Just to get things right. You proposal is (not using your Format()
function but your 'Hindent' function out of this plugin directly):
nmap g= :Hindent<CR>
setlocal formatprg=
But will you still work on the "range restriction" feature?
Yep, that's what I'm using/doing right now. You get your code through hindent with g=
and nice comments formatting with default gq
.
Will try to fit the "pass this visual selected code to hindent safely" thing... don't know how yet, but there will be some trade off I guess
@alx741 any updates on this?
Sorry about the delay on this. Now writing a range manually like :7,10Hindent
or visually selecting some code and then invoking :Hindent
should do the right thing.
Awesome! Thank you @alx741 :cake:
Hi, would it be possible to restrict hindent to the (visual) selected area?