copy paste in iterm, vim - macos

I use iterm in Mac as my command line terminal. In iterm I use tmux as the terminal manager. When I open my code files in Vim copying has become painful in this. To copy text in vim I need to hold "option" key and then select the text. When holding option there are multiple issues:
1) I am unable to scroll while in select mode
2) When I split my terminal into 2 panes, select using option copies across panes making it tough.
I am not sure about the reason for this issue and where to find a workaround. Could anyone help me with it?

You cannot depend on iTerm's clipboard support because it will not know anything about Vim's or tmux's splits. Use native Vim copy instead.
:help v
:help V
:help y
:help d
:help "*
:help clipboard
So e.g. in order to copy two lines, you can do "*2yy (to clipboard register, two line yank); or you can mark something using visual mode, then just "*y (to clipboard register, yank). If you want the clipboard register to be always automatically used unless another register is specified, you can add the following to your .vimrc:
set clipboard+=unnamed
Then a simple 2yy will copy two lines, and you can just paste it in iTerm or any other application.

Related

How to set terminal tabs titles in zsh, to vim filenames

I am using a oh-my-zsh shell in an Apple terminal (2.11) in full screen, and by default the name of the tabs is the name of the program being run (eg. vim).
Is there an easy way to set the title of the individual terminal tabs to the filename currently opened with vim?
The terminal window title is already set, but not visible in full screen mode. What I'm looking for is to get at a glance the title of all terminal tabs where vim is opened.
Screenshot below:
The solution seems to use vim script shared in https://stackoverflow.com/a/48975505/4756084. It sets the title dynamically based on what file is currently being viewed — which you cannot obtain by going into Terminal Preferences > Tab, and checking "Active process name" and "Arguments" (that would only display the name of the file opened when typing vim file.ext, ignoring any file opened with :e file2.txt, switches between vim panes, etc.)
(With oh-my-zsh, uncommenting DISABLE_AUTO_TITLE="true" in ~/.zshrc might help, as suggested in https://superuser.com/questions/292652/change-iterm2-window-and-tab-titles-in-zsh, although it seems optional after the step above.)

Can't figure out how to copy between VIM terminals on OS X

I know I need to copy into the " or * registers or something like that
Let's say I have one c program in one terminal running vim and another program in another terminal...
How do I copy a line between them?
Visually select the line you want to copy with V.
Hit "*y to yank the line into the * (clipboard) register.
Open the other terminal and vim inside it.
Hit "*p to paste or press i and then paste the info in there (like you would normally copy paste).
If this does not work then you may need to run vim --version and see if your copy of vim is compiled with a +clipboard. If it says -clipboard then you will need to install a version of vim that was compiled with clipboard. Results may vary when ssh-ing into a server.

Vim does not execute plugins in editor, only in application

I am on windows 10. I set up my files like this.
~/.vimrc
set nocp
source ~/vimfiles/autoload/pathogen.vim "location of my pathogen.vim
call pathogen#infect()
call pathogen#helptags()
autocmd vimenter * NERDTree
syntax on
filetype plugin indent on
~/vimfiles/autoload/pathogen.vim
~/vimfiles/bundle/nerdtree
When I open via the desktop application Vim I can use the :NerdTree command okay, I can also use other pluings, but when I open the vim editor from git bash or cmd.
One thing to note is that I do not need the autocmd vimenter command to run :NERDTree in Vim application, but it errors when I try to open :NerdTree from the vim editor.
Any ideas for what I can check?
On Windows, Vim expects your vimrc to be in either of these two locations:
%UserProfile%\_vimrc (note that it's a _, not a .),
%UserProfile%\vimfiles\vimrc (note that there's no _ or . anymore).
The latter is generally recommended because it allows you to keep all your Vim stuff under a single, easy to move around, directory.
Once you have moved your vimrc to a correct location you can remove the first line which is completely useless as Vim sets the nocompatible option itself when it finds a vimrc at an expected location.
See :help vimrc and :help 'nocompatible'.
The second line is also useless because lines 3 and 4 use a feature called "autoloading" through which Vim already knows where to find those functions.
See :help autoload.

Copy and paste in vim via keyboard between different mac terminals?

Can anyone help me with this:
I'm trying to figure out how to copy and paste text between 2 different instances of vim on different terminals (using iterm2 or mac terminal). I can do it using the mouse if I do ":set mouse=a" but I'd like to be able to do it using the keyboard.
I've googled around and it says you can use the "* or "+ registers to copy/paste to/from the system clipboard, but when I type * or + in vim, the mac makes one of those sounds it makes when you can't do something. I've also done ":set clipboard=unnamed" but that hasn't worked either.
I'm using Mac OSX 10.7 (Lion) and iTerm2 or Mac terminal.
Thanks for the help
Could you add the output of :version?
I can yank with yy or y in one Vim instance running in Terminal.app window A and put with p or P in another Vim instance running in Terminal.app window B with this line in my ~/.vimrc:
set clipboard+=unnamed
without using specific clipboard registers (* or +).
And why do you have two Vim instances running in different terminals? SSH/local? If one is in an SSH session yanking/putting won't work because the two machines (local/remote) don't share the same clipboard(s).
EDIT
I suspected that Vim wasn't compiled with the right flag(s). Apparently that's the case.
Since you are using Mac OS X's default Vim my opinion is that you shouldn't need to re-compile it or even compile anything as it often leads to more problem's than it's worth.
Instead, download the latest MacVim build and use the (CLI) Vim executable within MacVim's bundle: it has all the same functionalities as MacVim (within the constraints of the CLI, of course).
Add this line to your ~/.bashrc or ~/.profile or wherever you are used to put aliases and custom bash functions:
alias vim='/path/to/MacVim.app/Contents/MacOS/Vim'
If you want to copy an entire file into your target file.
Open your target file in vim.
Put your cursor where you want it and type the following:
:r /path_to_file/file.ext
This will copy an entire file to where your cursor is...

How do I copy and paste from bash to vim and vice-versa using only the keyboard?

Using this command:
http://www.hypexr.org/bash_tutorial.php#vi
I'm able to use vim commands in the bash. But, what I'd like to do is copy and paste from that (bash) into vim and vice-versa.
I know there are other posts on here using the middle mouse button, but I use putty to connect to linux boxes, and the middle mouse performs a selection, just like the left click drag.
I'm not looking for something that will modify my windows clipboard. Selecting in vim is useful for transfering stuff to and from windows, but I'd like a solution that will work both through putty and using a direct terminal.
Thanks in advance...
I use the copy&paste feature in screen. ctrl-[ to enter copy mode and ctrl-] to paste. There are different buffers and the ability to dump to a file. It's pretty powerful. The default is to copy lines, but you can curtail by columns join display lines into a single copied line (and other options). And since you would likely already be in screen when you run vim, you would have the paste buffer available. I also have hooks to copy the buffer to/from the X clipboard.
I don't know if that can help you, but I have installed a utility called xclip, which shares the X11 clipboard with VIM. I mainly use it to copy and paste between instances of VIM running in different terminal windows.
I typically use xclip with the following mappings, which keep a very similar behaviour to the usual yank and paste commands, but using the clipboard:
nmap `yy :.w !xclip<CR><CR>
vmap `y :w !xclip<CR><CR>
nmap `p :.r!xclip -o<CR>
nmap `P :.-r!xclip -o<CR>
Use the * (or + in X Windows) registers to reference the system clipboard. Anything yanked-to or pasted-from those registers can be used to cooperate with other applications:
Cut/Copy examples
"*yy : copy current line to the system clipbard
gg"*yG : copy current file to the system clipbard
"*dd : cut current line to the system clipbard
etc, etc
Paste examples
"*p : paste the system clipbard
Or in insert mode:
i Ctrl+r *
Or
i Ctrl+r Ctrl+p *
(the last one pastes withouth formatting, useful to avoid those ugly pastes from the OS clipboard where each indented line appears more and more shifted)
You can copy from/to the clipboard in both vim and bash using ctrl + ins for copy, and shift + ins for paste.

Resources