I'm having a problem with pasting on MacOS Sierra. When I copy text with newlines, I can paste it in a terminal without issue. e.g.: Text to be copied:

echo 'Foo'
echo 'Bar'

result from terminal (same in iTerm, Term using both bash and zsh):

[23:38:29] ~ $ echo 'Foo'
echo 'Bar'

result from vim within terminal

echo 'Foo'^Mecho 'Bar'^MFoo^MBar

As you see, the carriage return is interpreted as a literal string. I have tried in pastemode and fileformat=unix

My .vimrc can be found at https://github.com/zsoobhan/configs/blob/feature/osx/vimrc.

Vim version:

VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Jan 24 2017 14:45:56)
MacOS X (unix) version
Included patches: 1-225
Compiled by Homebrew
Huge version without GUI.  Features included (+) or not (-):
+acl             +file_in_path    +mouse_sgr       +tag_old_static
+arabic          +find_in_path    -mouse_sysmouse  -tag_any_white
+autocmd         +float           +mouse_urxvt     -tcl
-balloon_eval    +folding         +mouse_xterm     +termguicolors
-browse          -footer          +multi_byte      +terminfo
++builtin_terms  +fork()          +multi_lang      +termresponse
+byte_offset     -gettext         -mzscheme        +textobjects
+channel         -hangul_input    +netbeans_intg   +timers
+cindent         +iconv           +num64           +title
-clientserver    +insert_expand   +packages        -toolbar
+clipboard       +job             +path_extra      +user_commands
+cmdline_compl   +jumplist        +perl            +vertsplit
+cmdline_hist    +keymap          +persistent_undo +virtualedit
+cmdline_info    +lambda          +postscript      +visual
+comments        +langmap         +printer         +visualextra
+conceal         +libcall         +profile         +viminfo
+cryptv          +linebreak       +python          +vreplace
+cscope          +lispindent      -python3         +wildignore
+cursorbind      +listcmds        +quickfix        +wildmenu
+cursorshape     +localmap        +reltime         +windows
+dialog_con      -lua             +rightleft       +writebackup
+diff            +menu            +ruby            -X11
+digraphs        +mksession       +scrollbind      -xfontset
-dnd             +modify_fname    +signs           -xim
-ebcdic          +mouse           +smartindent     -xpm
+emacs_tags      -mouseshape      +startuptime     -xsmp
+eval            +mouse_dec       +statusline      -xterm_clipboard
+ex_extra        -mouse_gpm       -sun_workshop    -xterm_save
+extra_search    -mouse_jsbterm   +syntax
+farsi           +mouse_netterm   +tag_binary
   system vimrc file: "$VIM/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
       defaults file: "$VIMRUNTIME/defaults.vim"
  fall-back for $VIM: "/usr/local/share/vim"
Compilation: clang -c -I. -Iproto -DHAVE_CONFIG_H   -DMACOS_X_UNIX  -g -O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
Linking: clang   -L. -fstack-protector -L/usr/local/lib -L/usr/local/opt/libyaml/lib -L/usr/local/opt/openssl/lib -L/usr/local/opt/readline/lib  -L/usr/local/lib -o vim        -lncurses -liconv -framework Cocoa   -mmacosx-version-min=10.12 -fstack-protector-strong -L/usr/local/lib  -L/usr/local/Cellar/perl/5.24.0_1/lib/perl5/5.24.0/darwin-thread-multi-2level/CORE -lperl -lm -lutil -lc -F/usr/local/opt/python/Frameworks -framework Python   -lruby.2.4.0 -lobjc

Any help is greatly appreciated

  • 1
    Look at the "* and "+ registers, also, :.!pbpaste on an empty line should work
    – hgiesel
    Commented Jan 31, 2017 at 0:18
  • Register values: "* echo 'Foo'^Jecho 'Bar' and "+ is not set. :.!pbpaste did the trick... but why? I want to be able to paste using the cmd + v shortcut in insert mode without mangling the line breaks. Thanks for insight so far @hgiesel
    – zsoobhan
    Commented Jan 31, 2017 at 11:57

2 Answers 2


Basically when you paste using cmd + V, it is just throwing the content of the macOS clipboard at vim. It is just like typing each character that is in the clipboard literally into vim. That sometimes works, but often it doesn't. So the use is discouraged.

For this purpose there is the "* and "+ registers which use the system clipboard and paste the content of that into a native vim register. These are buggy on macOS, but well they seem to work in your case.

Also see help quotestart, help quoteplus and help clipboard

The other alternative is using pbpaste and pbcopy and use line filtering. When you .!pbpaste, the current line is the input and the output (that's signaled by the dot) of the external following command (that's signaled by the exclamation mark) used.

So you can use :.!pbpaste to paste the content.

And you can use :.!pbcopy to copy a single line. But the line vanishes if you do this, because pbcopy has no output. However you can do this: .!tee >(pbcopy)

  • You are quite correct with the registers and indeed :.!pbpaste solved the issue at hand. The root issue was solved by unlinking vim and reinstalling with brew install vim. The terminal now interprets the line breaks correctly for me. Previously in the :register the line breaks were being interpreted as letters instead of the ^J character which was evident from the syntax highlighting. ("* echo 'Foo'^Jecho 'Bar' was all in one colour instead of the ^J being in a different colour when compared to the values in the register.
    – zsoobhan
    Commented Jan 31, 2017 at 15:17

Quoting from Bram:

I assume you are talking about the command line, or entering search. Yes, it's intentional that the line break does not work like pressing Enter. The idea is that you are pasting text, not a command. You are supposed to view the text before deciding to execute it. The thread that started it mentioned that the source of the text may give you something else than what you expected. In practice, what often happens is that you accidentally copy the wrong text and include the line break when that is not intended.

This has been recently been changed when bracketed paste support was added. You can disable bracketed paste mode by :set t_BE=

  • :set t_BE? returns t_BE=^[[?2004h. I didn't realise bracketed post was a thing and it works (at least it does now). I can't test your solution since I have solved it by unlinking vim and doing a brew install. I cant figure out the difference it made but paste seems to work.
    – zsoobhan
    Commented Jan 31, 2017 at 15:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.