martanne / vis

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

Use system clipboard by default #1003

Closed gcoelho05 closed 11 months ago

gcoelho05 commented 2 years ago

I have been using neovim for some years now, but vis seems like a much saner way to do things and I would love to make it my daily driver.

I'm not sure this is the right place to ask for help and if it's not, please forgive me and point me to the right direction.


I wanted to have vis use the system clipboard for everything. In neovim, this is how I would do that:

set clipboard+=unnamedplus

How can I replicate this behaviour in my lua config?

Also, I would be grateful if someone pointed me to some documentation on how to configure vis with lua.

deepcube commented 2 years ago

I'm not sure about lua, but I've done this before:

diff --git a/vis.h b/vis.h
index b5a27fe..7a1dc95 100644
--- a/vis.h
+++ b/vis.h
@@ -722,6 +722,8 @@ bool vis_jumplist_next(Vis*);
 /** Register specifiers. */
 enum VisRegister {
    VIS_REG_DEFAULT,    /* used when no other register is specified */
+   VIS_REG_CLIPBOARD = VIS_REG_DEFAULT,  /* system clipboard register */
+   VIS_REG_PRIMARY = VIS_REG_DEFAULT,    /* system primary clipboard register */
    VIS_REG_ZERO,       /* yank register */
    VIS_REG_AMPERSAND,  /* last regex match */
    VIS_REG_1,      /* 1-9 last sub-expression matches */
@@ -734,8 +736,6 @@ enum VisRegister {
    VIS_REG_8,
    VIS_REG_9,
    VIS_REG_BLACKHOLE,  /* /dev/null register */
-   VIS_REG_CLIPBOARD,  /* system clipboard register */
-   VIS_REG_PRIMARY,    /* system primary clipboard register */
    VIS_REG_DOT,        /* last inserted text, copy of VIS_MACRO_OPERATOR */
    VIS_REG_SEARCH,     /* last used search pattern "/ */
    VIS_REG_COMMAND,    /* last used :-command ": */
erf commented 2 years ago

There is a documentation section in the README.md that links to the Lua Api. Also check out the Wiki on plugins.

mcepl commented 2 years ago
  1. https://github.com/martanne/vis/wiki is a pretty good starting point for documentation of vis
  2. ~/.config/dotfiles/vis/visrc.lua is the configuration file (see vis(1)).
  3. /usr/bin/vis-clipboard (that’s the location on my system, yours may vary) is a shell script
jpaulogg commented 2 years ago

Applying @deepcube's diff seems like the best way to me. You can also do something like this :map! normal d <vis-register>+<vis-operator-delete>.

In your viscr.lua:

vis:map(vis.modes.NORMAL, "d", "<vis-register>+<vis-operator-delete>")

From config.h:

{ "d",                  ALIAS("<vis-register>+<vis-operator-delete>") },

Abraços de Minas Gerais!

leorosa commented 2 years ago

In addition to @jpaulogg answer, you may also find useful to copy the system clipboard content into the main register, by including the following line somewhere in your visrc.lua:

vis.registers['"'] = { io.popen("vis-clipboard --paste"):read("*all") }
gcoelho05 commented 2 years ago

Thanks everyone for the answers. I have found @deepcube's solution to be my favourite, but everyone helped me with their good insight

bscuron commented 1 year ago

Did these changes work for you on a Mac? I am currently trying to use the system clipboard by default, but I receive this message when I compile with these changes: "Command failed System clipboard not supported". I also tried just setting the primary register = clipboard register. This works inside of vis, but when I paste outside of the editor it does not paste the contents of the yanked text.

Please let me know if you have any additional ideas that may help. Thank you.

mcepl commented 1 year ago

@bscuron It would be probably better to write this as a separate ticket rather than continue this never ending story.

gcoelho05 commented 1 year ago

Sorry to reopen this. @deepcube's solution was helpful, and I am now able to copy something from my e.g. browser to vis with p, yet, something I yank in vis with y cannot be copied into my browser. How can I get this to work?

rnpnr commented 1 year ago

You should be able to. The text is copied to PRIMARY not CLIPBOARD. You probably need to use middle mouse click to paste into your browser.

mcepl commented 11 months ago

@rnpnr Isn’t this ticket long overdue for closing?

rnpnr commented 11 months ago

Yes I was waiting for confirmation about using middle mouse button but I am certain it is correct.