r/vim • u/mpjuers • Dec 03 '19
My first plugin
Inspired my great deal of frustration after walking away from my computer only to come back in the middle of a 500 line class without a clue where I was, I made a plugin that shows the last line of each enclosing indentation level in a scratch buffer. I've only tested it with Python and Vimscript so far; other languages may have idiosyncrasies that I haven't accounted for, but the general concept should work well enough for any code that is well-formatted. Let me know what you think if you decide to try it! Below is the link.
1
u/-romainl- The Patient Vimmer Dec 04 '19
I would have used a scratch buffer, possibly in the preview window, instead of the location list.
2
0
Dec 04 '19
[deleted]
2
2
u/-romainl- The Patient Vimmer Dec 04 '19
Essentially, yes:
setlocal bufhidden=wipe buftype=nofile nobuflisted noswapfileis all it takes to turn a regular buffer into a "scratch" buffer.
3
u/xaizek Dec 03 '19
I think having opaque background could reduce size of the preview GIF down from 26 MiB, not sure by how much though. It just strikes me as being too big.
1
u/NilsLandt Dec 03 '19
I don't need this personally, but it looks really neat. A plugin you hope you don't need.
1
u/rebanc Dec 07 '19
You gave me an idea of a one-liner, so I'm just dropping it here...
nnoremap <silent> <expr> <C-A> '?\v^\s+\zs\S%<' . indent(prevnonblank('.')) . 'v\|^#@!\S<CR>
\ :noh\|call histdel("search", -1)\|let @/ = histget("search", -1)<CR>zz'(You can walk back with <C-O>.)
1
u/monkoose vim9 Dec 04 '19 edited Dec 04 '19
Your code is less then 10K, your useless image in the repository itself is 26M. Are you serious? Move image to another repository or some image sharing resource.
3
u/washtubs Dec 08 '19
I'll be that guy for a minute. The problem with editors showing something different than how the code actually looks is it masks problems that should instead be mitigated by refactoring the code.
Another similar IDE feature is intellij showing method parameter names, which aren't actually part of the code. It makes a method with 7+ parameters not seem so bad, because to everybody using intellij, it's readable. Similarly, a 500 line class simply should be split up, and the same goes for a very large function.
It should be hard to navigate such a dense function. That will encourage you to reorganize it the way it should be.
/rant
Having said that, it is really cool, and I could definitely see it being useful reading someone else's code. Just wouldn't want it on by default, personally.