lambdalisue / jupyter-vim-binding

Jupyter meets Vim. Vimmer will fall in love.
2.1k stars 136 forks source link

Support vim-surround like bindings #79

Open omrihar opened 8 years ago

omrihar commented 8 years ago

Jupyter notebook supports surrounding a selected piece of code with brackets, which is broken once vim bindings are enabled. It would be great to add a way of surrounding pieces of code with brackets, at least with ()[]{}"".

lambdalisue commented 8 years ago

vi( vi[ vi{ vi" doesn't work?

vim-surround is not an official Vim feature so I'm not feel comfortable to adding this to jupyter-vim-binding.

Maybe you can make a jupyter-vim-binding-surround or whatever to implement that feature.

omrihar commented 8 years ago

Hi @lambdalisue, thanks for the reply. I'm not sure how to use vi( (or siblings) in this case - this will select the text within the brackets. What I was hoping for is something where I can select a piece of code and surround it by brackets. Or am I missing something?

Thanks, Omri

lambdalisue commented 8 years ago

What I was hoping for is something where I can select a piece of code and surround it by brackets. Or am I missing something?

Sorry I thought you would want to select the word.

As I said, that is not a Vim's feature so no direct way is available. If you want to do something like that, try using macro like:

  1. Press qa to record a macro
  2. Move cursor on the word : wo|rd (| indicate the cursor)
  3. Press bi'<Esc> then the word become : '|word
  4. Press ea'<Esc> then the word become : 'word'|
  5. Press q to stop macro recording
  6. Repeat the operation with @a

Or add custom mapping which does the above operation (without step 1 and 5) while macro is only for temporary use. The page https://github.com/lambdalisue/jupyter-vim-binding/wiki/Customization would help you to do that. Please add that tips if you successfully define that mapping ;-)

shea-parkes commented 6 years ago

Although not officially part of Vim, I believe this particular plugin has to be just about the most commonly installed plugin out there: https://github.com/tpope/vim-surround

Having some way to replicate that functionality would be awesome. Nobody has added it to that Wiki (although they did try to implement another one or two of Tim Pope's popular plugins).

lambdalisue commented 6 years ago

We cannot say if a particular plugin is common or not. e.g. I don't use any tpope's plugins so from my point of view, vim-surround is not common.

I belive that a lot of people like jupyter-vim-binding because it tried to follow Vim's flavor so that nobody confuse the usage. Adding external plugin features to jupyter-vim-binding itself may helps someone but may dissapoint someone. So I think if the feature is official or not is a good point.

Additionally, if someone desire that feature, they can make external jupyter-vim-binding plugin I think.

tkchris93 commented 6 years ago

I don't think the issue is whether or not it's an official part of vim, I think the issue is that there is a piece of functionality native to Jupyter that people are wanting back. I don't care about vim-surround, but I really miss the Jupyter functionality that vim-surround would fix.

lambdalisue commented 6 years ago

I think the issue is that there is a piece of functionality native to Jupyter that people are wanting back

Some point of view, I agree. But while this plugin is for providing a Vim-like environment, I still don't think that the behavior should be in a default configuration.

So I think this should be in https://github.com/lambdalisue/jupyter-vim-binding/wiki/Customization page. While I don't use that feature, I've no idea which action should be mapped. Could you tell me which or fill the Customization page? @tkchris93

cocoaaa commented 4 years ago

Jupyter notebook supports surrounding a selected piece of code with brackets, which is broken once vim bindings are enabled. It would be great to add a way of surrounding pieces of code with brackets, at least with ()[]{}"".

Could you share how we can do this in jupyter notebook? I've been looking for this feature in jupyterlab for awhile. Thanks!

fdav10 commented 4 years ago

@cocoaaa Selecting a block of code and pressing the key for the bracket/quote opening character causes the selected text to be surrounded by those brackets/quotes. e.g. select a block of text and press "(".

@tkchris93 I believe you can still do this by activating insert mode and then pretend you're using vanilla Jupyter, i.e. doing what I described above.

cocoaaa commented 3 years ago

@FredDavison Thank you for your reply. I tried selecting a word and then pressing "(", but the selection is not surrounded by the "(...)". The selection is deleted and replaced by "(". I'm wondering if this feature is overwritten by my user-settings. Below is my current setting:

image

Could you tell me if you have any suggestion to enable this feature? Thanks!