Vim has a paste mode you can toggle on or off -
:set paste and
:set nopaste. What if you can do this with less keystrokes?
Essentially, these commands prevent weird formatting when pasting text into your editor.
I will say - copy/pasting isn't a trivial action. Expect to perform copy/paste tenfold throughout your career. Typing out these commands gets cumbersome. If only we can shortcut this to improve your workflow.
Below is a leader command to which you can add to
.vimrc (config file). Leader commands are merely a fancy shortcut native to Vim.
function! TogglePaste() if(&paste == 0) set paste echo "Paste Mode Enabled" else set nopaste echo "Paste Mode Disabled" endif endfunction map <leader>p :call TogglePaste()<cr>
No Vimscript knowledge necessary. Just "copy/paste" this snippet to your
Ensure your terminal shell of choice knows about your updates. I either restart my terminal session or source my
Toggle on paste mode: hit the key combination
p. If this doesn't work... ensure you're in Vim normal mode (not insert or visual).
Toggle off paste mode: