Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[surround] How to surround a line with empty lines? #321

Closed
2 tasks done
lfilho opened this issue May 9, 2023 · 2 comments
Closed
2 tasks done

[surround] How to surround a line with empty lines? #321

lfilho opened this issue May 9, 2023 · 2 comments
Labels
feature-request Request for a feature to existing module mini.surround

Comments

@lfilho
Copy link

lfilho commented May 9, 2023

Contributing guidelines

Module(s)

Surround

Description

Basically what i wanted is:

With the cursor anywhere on line two:

one
two
thre

get the following result:

one

two

three

I tried sa_<enter>, but then it just surrounds that line with enter's code ^M, which i hardly think will be useful to anyone. Could we maybe intercept that ^M and actually surround the line with new lines? Or maybe there's already a way to achieve that that i'm missing?

Thanks a lot for your great work

@lfilho lfilho added the feature-request Request for a feature to existing module label May 9, 2023
@echasnovski
Copy link
Owner

Thanks for suggestion!

I don't think it is possible under current design. The closest you can get is via setting respect_selection_type = true and then using interactive surrounding ? like sa_?<CR><CR>. But this will indent current selection.

There are alternatives:

  • Use custom mappings. Like so:
vim.keymap.set('n', '<M-m>', [[<Cmd>call append(line('.'), '') | call append(line('.')-1, '')<CR>]])
vim.keymap.set('x', '<M-m>', [[:<C-u>call append(line("'>"), '') | call append(line("'<")-1, '')<CR>]])
  • Use 'mini.basics' and its go/gO to insert blank line after/before current line.

I'll think about if there is a relatively simple way to add this to 'mini.surround'.

@echasnovski
Copy link
Owner

I've made several attempts to make it possible to write custom surrounding that would support this fully, but I don't think it is possible without changing 'mini.surround' code. The main problem is that for linewise selection left surrounding is applied to the first non-blank character. If it wasn't the case, then the following would work:

require('mini.surround').setup({
  custom_surroundings = {
    -- Use `<CR>` as surrounding identifier
    ['\r'] = { output = { left = '\n', right = '\n' } },
  },
})

Currently, it will affect the indentation of first selected line.

As present behavior of special handling of indent in linewise selection seems to be more universally applicable, I don't think this will be possible in 'mini.surround'. I'd suggest using my previous advice on custom mapping or combination of go/gO from 'mini.basics'.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request Request for a feature to existing module mini.surround
Projects
None yet
Development

No branches or pull requests

2 participants