Tag Archive
3D 3dprinting android ant BigData bitcoin Browsers C/C++ cryptocurrency CSS dd ddrescue dogecoin DOS editors find Games Git hadoop html html5 Java Linux litecoin node perl Postgres Programming Python scripting Shell SQL Swing TOTK Utilities utilization vi Video Web Web Design Wifi Windows Wordpress XML Zelda
VI: Paste code without formatting
I happened to be creating a script and found myself trying to copy and past some functions between them. Well my functions
had some comments and this caused the paste operation into vi to add comments to every line after the first comment.
So this:
sub somefunc { # input args my $var1 = shift; my $var2 = shift; if ($var1 < $var2) { return $var1; } else { return $var2; } }
Became this:
sub somefunc { # input args #my $var1 = shift; #my $var2 = shift; # #if ($var1 < $var2) #{ # return $var1; #} #else #{ # return $var2; #} #}
This made all my formatting go awry as well, and there were about 4 different functions I was about to cut and past. So I looked into how to make vi accept the text as is without adding formatting. The answer is the paste and nopaste mode.
To enter the mode to allow pasting without formatting:
:set paste
To return to regular mode:
:set nopaste
There are also ways to bind a key to more quickly enter and exit this mode if you are pasting on a regular basis.
That will be in another article.