I'm using ZSH on Mac OS if that is important. When doing some manual cherry picking on branches in git, I sometimes would like to type git checkout origin/develop --<path> where I copy and paste from gitlab. However for some reason sometimes the copy and paste feature seems to fail but then there is a newline for some reason on the clipboard and it checks out the branch. I would like to prevent that.
1 Answer
This is possible with iTerm as follows.
I chose Ctrl+Shift+V as my hotkey when programming the following as that is used in Chrome and other applications to be "paste as plain text."
Option 1: Strip all new lines
Preferences -> Keys (tab) -> + (button) -> Action: Paste... -> Remove newlines (checkbox checked).
Pasting the following:
asdf
asdf
Will result in this:
asdfasdf
Option 2: Replace new lines with spaces via regex
Preferences -> Keys (tab) -> + (button) -> Action: Paste... -> Replace (checkbox checked) and enter the following:
(\r\n|\r|\n) -> (a space character).
Pasting the following:
asdf
asdf
Results in this (this is my preference over Option 1 above):
asdf asdf
It is still safe (the command won't execute, but it is more readable in case there are multiple lines).
-
Will this work if you trigger paste via the middle mouse button instead of the keyboard?Sridhar Sarnobat– Sridhar Sarnobat2022-05-26 23:21:09 +00:00Commented May 26, 2022 at 23:21


#(#git checkout origin/develop --<path>) then paste/edit command line then remove#. If there is a newline in pasted text or I accidentaly depress CR i just press arrow-up and continue editing.vimuser I can't disable newlines when I want to paste into a file.