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

change registery when replacing placeholder #175

Open
kkharji opened this issue Mar 15, 2021 · 8 comments
Open

change registery when replacing placeholder #175

kkharji opened this issue Mar 15, 2021 · 8 comments

Comments

@kkharji
Copy link

kkharji commented Mar 15, 2021

hey @hrsh7th, is there a way to change the registry when replacing the placeholder. I was so annoyed for sometime now that I'd need to skip replacing the placeholders because it means I will lose what I have in my main registry .

Thanks

@Shougo
Copy link

Shougo commented Mar 15, 2021

You should describe the example.
It is hard to understand.

@kkharji
Copy link
Author

kkharji commented Mar 15, 2021

Sorry about that. For example: given the following snippet:

    "body": [
      "```${1:lang}  ",
      "$0",
      "```"
    ]

When expanding it the cursor goes to lang placeholder, when I change it, my main vim registry gets replace with lang. And that basically my main issue

@Shougo
Copy link

Shougo commented Mar 15, 2021

The example is better, but I don't understand why the feature fixes your problem.
Please compare with current behavior and your desired behavior.

@kkharji
Copy link
Author

kkharji commented Mar 15, 2021

Okay, Say I have this in my main registry +:

type KeyProduct struct{}

When I write go to replace lang, + registry get replaced with lang. so when a tab over to the body and try to paste, I get lang.

The desired behavior is that when I replace lang, the main + or * registry does not get modified or overwritten with the placeholder.

@Shougo
Copy link

Shougo commented Mar 15, 2021

Ah I get it. This is the feature of replace. It is hard to fix...

@Shougo
Copy link

Shougo commented Mar 15, 2021

And the "registory" should be "register" in Vim word.
I was confused.

@davidsierradz
Copy link

davidsierradz commented Sep 16, 2021

I'm having the same issue. I think we can have two possible solutions:

  1. The easiest: Use vim-cutlass/cutlass.vim or copy/call this function:
    function! cutlass#overrideSelectBindings()
      let i = 33
    
      " Add a map for every printable character to copy to black hole register
      " I see no easier way to do this
      while i <= 126
          if i !=# 124
              let char = nr2char(i)
              if i ==# 92
                let char = '\\'
              endif
              exec 'snoremap '. char .' <c-o>"_c'. char
          endif
    
          let i = i + 1
      endwhile
    
      snoremap <bs> <c-o>"_c
      snoremap <space> <c-o>"_c<space>
      snoremap \| <c-o>"_c|
    endfunction
  2. Maybe vim-vsnip can implement some autocommands so we can run our custom hooks, like ultisnips. Then we can change the clipboard before and after the expansion, for example:
    autocmd User VimVsnipEnterFirstSnippet set clipboard-=unnamedplus
    autocmd User VimVsnipExitLastSnippet set clipboard+=unnamedplus

I had used solution 1, It's a bit hackish (clever?) but got some problems with other plugins and it polluted the mappings, so I'm evaluating other solutions.

Personally, I would like 2 (is more flexible and powerful). But I'll understand if it's not something the maintainers would like to add to the codebase.

EDIT: A third option, but not optimal: add an explicit mapping to delete the text and send it to the blackhole register before writing the replace text:

snoremap <silent> <c-h> <c-g>"_c

So when you have lang selected, press <C-h> before writing go.

@kkharji
Copy link
Author

kkharji commented Oct 13, 2021

Maybe vim-vsnip can implement some autocommands so we can run our custom hooks, like ultisnips. Then we can change the clipboard before and after the expansion, for example:

autocmd User VimVsnipEnterFirstSnippet set clipboard-=unnamedplus
autocmd User VimVsnipExitLastSnippet set clipboard+=unnamedplus

Interesting, this looks clean and simple, @hrsh7th any chances this can be implemented?

For now I will try to adjust to snoremap <silent> <c-h> <c-g>"_c

Thanks @davidsierradz

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants