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

Remove visual select storage after one use? #324

Open
JakeQueiser opened this issue Feb 12, 2023 · 4 comments
Open

Remove visual select storage after one use? #324

JakeQueiser opened this issue Feb 12, 2023 · 4 comments

Comments

@JakeQueiser
Copy link

I'm not sure if this is a bug, but whenever I perform a visual select and then expand a snippet, I get my visual select right where I want it in my snippet (i.e. which is how it should work), but then if I expand another visual snippet, I get the same piece of text inside this snippet. I don't want this to happen.

Is there a way to make it so that a visual selection is used only once in an expansion, and then not used afterwards? Here are some of the snippets where I see this happen:

global !p
def wraps(char):
	a = vim.current.window.buffer
	b = vim.current.window.cursor[0]
	c = vim.current.window.cursor[1]
	try:
		return a[b-1][c-1] + a[b-1][c] != char 
	except:
		return True 
endglobal

context "wraps('()')"
snippet ( "parenthesis" iA
(${1:${VISUAL}})$0
endsnippet

snippet { "Braces" iA
{
	${1:${VISUAL}}
}
endsnippet

context "wraps('[]')"
snippet [ "Brackets" iA
[${1:${VISUAL}}]$0
endsnippet

Thank you for your help and time.

@chemzqm
Copy link
Member

chemzqm commented Sep 8, 2023

The visual selection should only work once.

@newptcai
Copy link

I do have the same problem. If I use visual place holder to put some code in an expanded snippet. Then after that, the visual place holder would be replaced every time when I expand a snippet if I do not select anything when I expand it.

@newptcai
Copy link

I finally got it. You have to remove the content of g:coc_selected_text in order to use it for visual content only once.

@newptcai
Copy link

I added a key mapping to clean the variable.

" Reset the g:coc_selected_text
nmap <buffer><C-j> :let g:coc_selected_text='' <CR>

Not sure how this can be done automatically.

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

No branches or pull requests

3 participants