I have a problem with
vim when I paste something it puts them in by placing in each newline. How can I set default settings of
If you paste from the system clipboard,
vim thinks the pasted text is user input and, if confiured to provide autoindent,
vim makes it's job and automatically indents the code.
You can turn off that autoindent when you paste code into
vim directly. Type that in the command mode:
Now, your pasted code should be written without indent. To re-enable autoindent again use:
To simplfy that, you can define a shortcut in you
.vimrc as follows:
Now, when you press F2 in insert mode to have the desired behavior. Then press again F2, to work with autoindent as before.
I learnt this neat automation from coderwall, write the following into your
let &t_SI .= "\<Esc>[?2004h" let &t_EI .= "\<Esc>[?2004l" inoremap <special> <expr> <Esc>[200~ XTermPasteBegin() function! XTermPasteBegin() set pastetoggle=<Esc>[201~ set paste return "" endfunction
and it will switch on and off paste mode for you.
tmux can be a little bit tricky, as you may (I use "may" because I do not have to double escape when I am inside
tmux) have to double escape using
function! WrapForTmux(s) if !exists('$TMUX') return a:s endif let tmux_start = "\<Esc>Ptmux;" let tmux_end = "\<Esc>\\" return tmux_start . substitute(a:s, "\<Esc>", "\<Esc>\<Esc>", 'g') . tmux_end endfunction let &t_SI .= WrapForTmux("\<Esc>[?2004h") let &t_EI .= WrapForTmux("\<Esc>[?2004l") function! XTermPasteBegin() set pastetoggle=<Esc>[201~ set paste return "" endfunction inoremap <special> <expr> <Esc>[200~ XTermPasteBegin()
You can paste directly from clipboard (
"*) using vim's
"*p without having to enter
Since the above won't work when you're connected to a remote terminal, chaos's suggestion would be your best option.
vim-unimpaired adds a nice shortcut
yO which automatically does
set paste, insert a new line after/before the cursor's current line and then
set nopaste once you exit