Vim-gtk3

0 views
Skip to first unread message

Karren Bangura

unread,
Aug 3, 2024, 10:24:40 AM8/3/24
to poidselgamen

I have habitually installed vim-gtk3 on new builds of Ubuntu for at least a decade, but it's always bothered me that I don't have a basis for making this decision. For end users who are used to gvim as an IDE, but who don't necessarily know about or care about "gtk3" or "athena," whatever they are, why would someone choose one or the other?

It strikes me odd that apt doesn't just make the call for the user who types `apt install gvim` with a default choice, when so much else about the Ubuntu experience is about doing the usually-right thing. Instead, users are prompted to essentially make a coin-flip choice with no other information.

I would expect `apt install gvim` to pick vim-gtk3 as the default option and roll with it, instead of asking the user to make a value judgement between two or more packages they haven't evaluated yet.

Unlike other editors, Vim stores copied text in its own clipboard. So, it's very hard for me to copy some text from a webpage and paste it into the current working file. It so happens I have to either open gedit or type it manually.

Be aware that copying/pasting from the system clipboard will not work if :echo has('clipboard') returns 0. In this case, Vim is not compiled with the +clipboard feature and you'll have to install a different version or recompile it. Some Linux distros supply a minimal Vim installation by default, but if you install the vim-gtk or vim-gtk3 package you can get the extra features nonetheless.

The "* and "+ registers are for the system's clipboard (:help registers). Depending on your system, they may do different things. For instance, on systems that don't use X11 like OS X or Windows, the "* register is used to read from and write to the system clipboard. On X11 systems, both registers can be used. See :help x11-selection for more details, but basically the "* is analogous to X11's _PRIMARY_ selection (which usually copies things you select with the mouse and pastes with the middle mouse button) and "+ is analogous to X11's _CLIPBOARD_ selection (which is the clipboard proper).

You also may want to have a look at the 'clipboard' option described in :help cb. In this case, you can :set clipboard=unnamed or :set clipboard=unnamedplus to make all yanking/deleting operations automatically copy to the system clipboard. This could be an inconvenience in some cases where you are storing something else in the clipboard as it will overwrite it.

To paste you can use "+p or "*p (again, depending on your system and/or desired selection) or you can map these to something else. I type them explicitly, but I often find myself in insert mode. If you're in insert mode you can still paste them with proper indentation by using * or +. See :help i_CTRL-R_CTRL-P.

Vim's paste option (:help paste) is also worth mentioning: This puts Vim into a special "paste mode" that disables several other options, allowing you to easily paste into Vim using your terminal emulator's or multiplexer's familiar paste shortcut. (Simply type :set paste to enable it, paste your content and then type :set nopaste to disable it.) Alternatively, you can use the pastetoggle option to set a keycode that toggles the mode (:help pastetoggle).

On my Linux system, the + and * registers map to an X11 selection, which can be pasted with the middle mouse button. When :set clipboard=unnamed and :set clipboard=unnamedplus are used, then the registers map to the clipboard, and can be pasted with CTRL-V.

There is a special register for storing this selection, it is the "*register. Nothing is put in here unless the information about what text isselected is about to change (e.g. with a left mouse click somewhere), or whenanother application wants to paste the selected text. Then the text is putin the "* register. For example, to cut a line and make it the currentselection/put it on the CLIPBOARD:

Similarly, when you want to paste a selection from another application, e.g.,by clicking the middle mouse button, the selection is put in the "* registerfirst, and then 'put' like any other register. For example, to put theselection (contents of the CLIPBOARD):

Now copying and pasting should work exactly as expected on a single, and across different machines by only using y for yank and p for paste. NB modify .vimrc on all machines where you want to use this feature.

You don't even need the +clipboard or +xterm_clipboard vim features installed anymore. This feature is called "bracketed paste". For more details, see Turning off auto indent when pasting text into vim

A quick note for people whose Vim installation does not support the * and + registers. It is not necessary to download a new Vim installation to paste from the clipboard. Here is an alternative method:

Now when you type in :Clip as an ex command, the contents of the clipboard will be pasted in at the cursor. You can also map the new command to a function key so as to be able to do this with one keystroke.

As other answers have suggested, I ran vim --version and noticed that it returns -clipboard, which means that the version of vim that shipped with my machine hasn't been compiled with the clipboard option.

On top of the setting :set clipboard=unnamed, you should use mvim -v which you can get with brew install macvim if you're using vim on Terminal.app on Mac OS X 10.9. Default vim does not support clipboard option.

The other solutions are good if you want to change your vimrc, etc... However I wanted an simple way to copy from vim to my system keyboard. This is what I came up with.

The benefits is you do not need to mess with indentation. The text is inserted right as is.Note in cat's place, there could be any command, like fold (I used to use this until I discovered gq) or any other filtering utility.

I'm running vim-gtk3 in Debian Netrunner 20.01 which is KDE, and normally using Konsole, but also Terminator in debugging this, on a Thinkpad T410. I've posted at Netrunner forums and Vi&Vim, and it was suggested that I try here.

In Konsole, I go into VIM (usually through VIFM, but that doesn't seem to matter) and start editing a document. Then I do :new to get another panel, and then :Explore and start editing a second document, switching back and forth between the documents by using c-w (Ctrl-w) twice. Last night, something happened, and now when I press c-w, the first press makes the mouse pointer visible, and the second press makes the vim cursor blink once, but it does not switch panes.

I then, in vim :map :winc to shorten the number of keystrokes. That worked fine, but now has started working again, so it is fully functional normal vim in both Konsole and Terminator. I restored all the old config files, and it still works fine. So, I still have no idea what the actual problem was.

Debian is my Linux distro of choice, so the first thing I want to understand is what do the default settings look like right after sudo apt install vim-gtk3 (I use vim-gtk3 instead of vim or vim-nox because I need system clipboard integration for copying and pasting from a web browser, etc.) A lot of thought has presumably gone into these default configs, so they should make a good starting point. At a minimum, understanding the defaults will at least let me make informed decisions when my settings contradict them.

c80f0f1006
Reply all
Reply to author
Forward
0 new messages