I am currently reading a manual about how to compile and run a program. Currently I have two terminals, one terminal shows the manual, the other terminal is where I follow the instructions and type the command. Is it possible to do those two things in one terminal. Just like show two files in one terminal. I want to read the instruction in the left side of the terminal window and type command in the right side of the terminal window. Any advice?
I don't know what's your problem, having two terminal emulator windows side by side is perfectly acceptable. If you really want to add complexity to your learning experience, you can try one of these terminal multiplexers:
tmux
dvtm
or, if such a thing exists for your platform, a terminal emulator with split windows like:
iTerm (Mac OS X)
Terminator (Linux)
In VIM you can create new "windows"/panes just type
:vnew
For vertical window and
:new
For horizontal window
If you want to know more about windows you can check this or if you want to know more about VIM features you can try this
you can use one of the following
:tabe filename to open a new tab containing filename or nothing for a blank tab.
gt to switch and gT to switch backwards.
:sp to split the current window ^w j to jump down and ^w k to jump up
or :vsp to split vertically (so you can read in the left) ^w h to jump left and ^w l to jump right
all key strokes are in command mode
I've been trying to get a script working which would copy a line of text from vim, delete the line, then paste the line to another window. So far I've tried implementing the script with Autohotkey (on Windows 8) and Autokey (on a Ubuntu VM I run). Here's what I've put down:
On Autohotkey:
!^p::
SendRaw "*yydd
SendEvent !{tab}
SendPlay ^v
On Autokey (linked to Ctrl+Alt+p):
keyboard.send_keys("\"*yydd")
keyboard.send_keys("%{TAB}")
keyboard.send_keys("^v")
In both instances, the Vim commands (yank current line to system clipboard, delete current line) work properly, but the scripts fail to switch windows for the paste, and instead execute a Ctrl-v in vim.
Does anyone know what I would need to change in order to get the Alt-Tab functionality working?
Sending the raw Alt + Tab keys doesn't work, as application switching is a core Windows function. In AutoHotKey, there's the AltTab special command (look it up in the help), or better use the WinActivate command, as AutoHotKey seems to still have issues with Alt-Tab on Windows 8.
Vim version is 7.2.411, operating system is CentOS 6.
By default, i can use the mouse to select the text and click right key, then copy the selection to clipboard.
Now i want to use this option set mouse=a that i set it in ~/.vimrc file,
but the previous operation is not working. Whatever i try "+y or "*y, still not works.
I just want to use the function that copys the yand text to clipboard, simultaneously, and the set mouse=a to be set in .vimrc file.
Check whether you have set clipboard=autoselect,autoselectml and set guioptions+=a set (you'll probably have some other "letters" in there as well)? The a is related to copying to the cliboard. The mouse=a only enables you to use the mouse in all modes.
From your description it sounds like you're using Vim in a terminal. By default, the terminal is handling the mouse clicks, so it's the terminal selecting and copying the text. When you set mouse=a, Vim handles the mouse itself, so selecting doesn't copy to the clipboard.
If the version of Vim you're using was compiled without X11 support, you can't copy and paste from inside Vim. This would explain why "+y and "*y don't work. You should try to install a "full" Vim version using your distribution's package manager. Be sure to run vim and not vi from the command-line, to get the proper version.
In this case, you can still let the terminal handle mouse-clicks (instead of Vim) by holding shift when you click or drag. This way, you'll get the behaviour you had previously had before you set mouse=a.
In my previous Linux install, when I selected some text in visual mode (without the mouse!), it would automatically put it in my X11 clipboard. Then I could naturally paste this text anywhere else using the mouse middle button.
With my new Linux installation, this doesn't work anymore (merely selecting text in visual mode doesn't put it in X11 clipboard anymore).
How can I get this nice feature back?
(I am not interested into the "*y or "+y solutions, which by the way don't work on my system.)
Thanks in advance!
The visual selection (v, V, or CTRL-V) can automatically be copied to the
X11 selection (* buffer).
In non-gui mode the clipboard option controls this (only supported if
+xterm_clipboard appears when you type vim --version). In gui mode
guioptions controls it.
This makes all Visual mode selections automatically go to the X11 primary
selection:
set clipboard+=autoselect
set guioptions+=a
This turns it off:
set clipboard-=autoselect
set guioptions-=a
In vim see:
help 'clipboard'
(single quotes required)
Use:
set guioptions+=a
This works with the GUI (Gvim). Reference is at :help guioptions_a.
*guioptions_a* *'go-a'*
'a' Autoselect: If present, then whenever VISUAL mode is started,
or the Visual area extended, Vim tries to become the owner of
the windowing system's global selection. This means that the
Visually highlighted text is available for pasting into other
applications as well as into Vim itself. When the Visual mode
ends, possibly due to an operation on the text, or when an
application wants to paste the selection, the highlighted text
is automatically yanked into the "* selection register.
Thus the selection is still available for pasting into other
applications after the VISUAL mode has ended.
If not present, then Vim won't become the owner of the
windowing system's global selection unless explicitly told to
by a yank or delete operation for the "* register.
The same applies to the modeless selection.
When using Vim inside gnome-terminal on Arch and Gentoo Linux this functionality just works.
When using Vim inside Konsole this does not work.
Using gvim -v will launch a terminal version of GVim where set guioptions+=a works:
any text selected within that Vim is automatically copied to Linux's selection buffer.
To paste text from the selection buffer press the middle mouse button
On my Debian I got it working after installing vim-gnome package.
A comment from pkg-vim-maintainers mailing list instructs to install either vim-gtk, vim-gnome or vim-lesstif.
With my new installation of Kali, I solved the issue above by installing vim-gtk package for gnome-terminal. The vim-gtk package changes the "-xterm_clipboard" to "+xterm_clipboard", and the problem is solved. After selecting text in vim, the text will be copied to system clipboard automatically.
After enabling set mouse=a, text copied inside of Vim will not paste outside of Vim. Does anybody know of a way to fix this?
Here, selecting text with the mouse turns on visual mode and disables the Copy option in the popup menu:
Press shift while selecting with the mouse. This will make mouse selection behave as if mouse=a was not enabled.
Note: this trick also applies to "middle button paste": if you want to paste in vim text that was selected outside, press shift while clicking the middle button. Just make sure that insert mode is activated when you do that (you may also want to :set paste to avoid unexpected effects).
OS X (mac):
hold alt/option while selecting (source)
Use ", +, y after making a visual selection either with the keyboard or the mouse. You shouldn’t be using the terminal’s copy command anyway, because that copies what the terminal sees instead of the actual content. Here is what this does:
",+ tells Vim to use the register named + for the next delete, yank or put. The register named + is a special register, it is the X11 clipboard register. (On other systems, you would use * instead, I think, see :help clipboard and :help x11-selection)
y is the yank command, which tells Vim to put the selection in the register named previously.
You could map it like this:
:vmap <C-C> "+y
And then highlight something with the mouse and press Control-C to copy it.
This feature only works when Vim has been compiled with the +xterm_clipboard option. Run vim --version to find out if it has.
Instead of set mouse=a use set mouse=r in .vimrc
On OSX use fn instead of shift.
In Ubuntu, it is possible to use the X-Term copy & paste bindings inside VIM (Ctrl-Shift-C & Ctrl-Shift-V) on text that has been hilighted using the Shift key.
Another OSX-Mac option is to uncheck View->Allow Mouse Reporting (or press ⌘-R to toggle it.) This allows you to toggle between mouse interaction and mouse selecting, which might be useful when selecting and copy/pasting a few bits because you don't have to hold a modifier key to do it.
Note for Multiline with line numbers:
I usually have line numbers enabled so this will also copy the line numbers if you select multiple lines. If you want to copy multiple lines without the line numbers disable the numbers with :set nonu and then you can :set nu to re-enable them after you're done copying.
Holding shift while copying and pasting with selection worked for me
You can use :set mouse& in the vim command line to enable copy/paste of text selected using the mouse. You can then simply use the middle mouse button or shiftinsert to paste it.
I accidently explained how to switch off set mouse=a, when I reread the question and found out that the OP did not want to switch it off in the first place. Anyway for anyone searching how to switch off the mouse (set mouse=) centrally, I leave a reference to my answer here: https://unix.stackexchange.com/a/506723/194822
Compilation settings that vim was compiled with, are part of the issue. vim --version shows these.
In OSX, the default vim has -clipboard But you need +clipboard
On osx you can and apparently generally should, use macvim. You can do brew cask install macvim That one has +clipboard.
Them you'll have two vims.
~$ ls -l /usr/bin/vim <--- default vim
-rwxr-xr-x 1 root wheel 1745984 15 Jul 2017 /usr/bin/vim
~$ ls -l /usr/local/bin/vim <-- macvim, installed recently via that mentioned brew line.
lrwxr-xr-x 1 apple admin 42 16 May 23:32 /usr/local/bin/vim -> /Applications/MacVim.app/Contents/bin/mvim
~$
running vim will run macvim 'cos /usr/local/bin should be before /usr/bin in the path, though you can check with which vim.
running vim(to run macvim), is fine but you may want to map vi to macvim 'cos otherwise running vi stays at the default vim! You can rewrite or delete(with rm) and recreate the vi sym link, with ln. And to do that without an 'operation not permitted" error, you have to (temporarily) disable SIL. https://apple.stackexchange.com/questions/208478/how-do-i-disable-system-integrity-protection-sip-aka-rootless-on-macos-os-x .
macvim has +clipboard as shown by vim --version
Here is a working ~/.vim/vimrc with just the required lines.
:set mouse=a
:map <leader>c "+y
:map <leader>v "+p
The default leader key is backslash.
I read a suggestion that one should use the leader key.. (certainly control has many keys already in use, so the suggestion was to not use control. I don't know if that applies to command key too, but anyhow).
With that mentioned mapping, \c will do "+y which will copy from the register known as +, to the clipboard. And \v will paste from the register known as +.
So that's a copy/paste that works between windows.
Another OS may require "* rather than "+
Add set clipboard=unnamed to your .vimrc. So it will use the clipboard register '*' instead of the unnamed register for all yank, delete, change and put operations (note it does not only affect the mouse).
The behavior of register '*' depends on your platform and how your vim has been compiled (or if you use neovim).
If it does not work, you can try with set clipboard=unnamedplus, but this option only makes sense on X11 systems (and gvim therefore).
If you are using, Putty session, then it automatically copies selection.
If we have used "set mouse=a" option in vim, selecting using Shift+Mouse drag selects the text automatically.
Need to check in X-term.
em...
Keep pressing Shift and then click the right mouse button
Also worth mentioning, by having set mouse=nvi, when doing a selection and then pressing : <ESC> you will get the mouse selection copied to the primary selection clipboard (equivalent to a "*y).
Reference: help mouse
Main advantage of this method is the fact that if you have multiple vertical splits, it will only select from the current buffer. Using <Shift> as mentioned in the main answer, will, in this case, copy from all 3 files at the same time which is not exactly what one would want, expect or need.
A good workaround which is worth adding:
GPM daemon can be used which is a a cut and paste utility and mouse server for virtual consoles. It will provide functionalities across all the virtual consoles!
Copy-Paste actions can be done by <CTRL-C>/<CTRL-V>.
sudo apt-get install gpm
MAN pages of GPM
set set mouse=a in vi, using MobaXterm, after installing vim-gtk3 on server, dragging with mouse and Ctrl + Insert works, but seems it only work with MobaXterm
after installing vim-gtk3, vi will link to it
lala#kubu:~$ sudo apt install gvim
[sudo] password for lala:
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Package gvim is a virtual package provided by:
vim-gtk3 2:8.2.2434-3ubuntu3.2
vim-athena 2:8.2.2434-3ubuntu3.2
You should explicitly select one to install.
E: Package 'gvim' has no installation candidate
lala#kubu:~$ which vi
/usr/bin/vi
lala#kubu:~$ file /usr/bin/vi
/usr/bin/vi: symbolic link to /etc/alternatives/vi
lala#kubu:~$ file /etc/alternatives/vi
/etc/alternatives/vi: symbolic link to /usr/bin/vim.gtk3
lala#kubu:~$
In ESC mode, when set mouse=a, select the text using mouse. This would enable the visual mode in vim. Then you can press 'y' to yank the selected text and 'p' to paste it wherever you want. This happens only within vim.