martanne / vis

A vi-like editor based on Plan 9's structural regular expressions
Other
4.26k stars 259 forks source link

Trying to bind to copy from system clipboard #865

Closed 80aff123-9163-4f3e-a93d-4a2f35af9be1 closed 4 years ago

80aff123-9163-4f3e-a93d-4a2f35af9be1 commented 4 years ago

Hi,

I'm trying to bind to a shortcut the following command:

vis:command('map! normal <Space>p "*p')

I want space + p to copy from my system clipboard. Do I have an error in my code?

Any help is greatly appreciated.

- Carla

sh4r1k7 commented 4 years ago

I expected it to work as well but ended up needing a more verbose approach to make it work: vis:command( 'map! normal <Space>p <vis-register>*p' )

maybe someone else can explain why the alternative doesn't.

erf commented 4 years ago

Try to use vis:map instead. Also i think * has changed to + for system clipboard ( * is now primary clipboard ).

Try this:

vis:map(vis.modes.NORMAL, ' p', '"+p')
sh4r1k7 commented 4 years ago

"copy from" = paste to :)

80aff123-9163-4f3e-a93d-4a2f35af9be1 commented 4 years ago

@3dc1d3 @erf

thank you! that worked :)

martanne commented 4 years ago

Hi, the map command takes 3 arguments and argument splitting is performed on single and double quotes, a backslash is used as escape character.

Also you can't currently use <Space> but have to use a literal space .

Meaning the following should work interactively:

map! normal ' p' \"*p
map! normal " p" \"*p

If you want to do the same through the Lua API then you have to take its rules for string quoting into account:

vis:command([[map! normal " p" \"*p]])

As was already shown, vis:map lets you specify the arguments individually.