hanschen / vim-ipython-cell

Seamlessly run Python code in IPython from Vim
GNU General Public License v3.0
335 stars 18 forks source link

Highlight IPython cells #21

Closed gerazov closed 3 years ago

gerazov commented 3 years ago

It's useful if cells are highlighted in the code. This would augment the plugin nicely :+1:

I was thinking maybe with automatically setting marks or horizontal lines, but I'm not sure if this can be done.

What I came up with is:

highlight MyGroup ctermbg=238 guifg=darkgrey guibg=#444d56
match MyGroup /^# %%.*/

Of course going with a color from your colorscheme should be better or else here's a nice color picker Vim Color Scheme Editor :slightly_smiling_face:

Also this could be toggled as in vim-interestingwords

hanschen commented 3 years ago

Nice idea! This has now been added in 71ea0c6258829e8b1ca2cf0a862eb8dd5ac7f75b, please update the plugin and see if it works as expected.

Also see the README for how to change the highlight colors (it uses the Folded highlight group by default). The way Vim handles highlighting seems pretty messy, let me know if I missed anything.

I don't intent to implement visualization of code cells defined using marks unless there's a simple way to do it. I'll therefore close this issue for now. Feel free to re-open if there are any issues with the current implementation.

gerazov commented 3 years ago

Nice job! :muscle:

It doesn't seem to work for me though :thinking:

I've added some comments in the PR.

Yeah highlighting seems pretty messy to me too, otherwise I'd have sent you a PR of my own :sweat_smile:

hanschen commented 3 years ago

Thanks for your comments, I've fixed the ones you pointed out.

Not sure why it doesn't work no you, I've tested it on two very different setups and it works on both. Does it work if you add the following to your .vimrc (or equivalent for neovim)?

let g:ipython_cell_highlight_cells = 0
highlight default link IPythonCell Folded
augroup highlight_python_cells
    autocmd!
    autocmd VimEnter,WinEnter * match IPythonCell /\s*# %%.*\|\s*#%%.*\|\s*# <codecell>.*\|\s*##.*/
augroup END
gerazov commented 3 years ago

Awesome :sunglasses: - works with the plugin itself :+1: