Reputation: 10865
When I opened a vim editor on terminal, I copied the following text to clipboard from another source
int thisVal = findMin(m);
// System.out.println(val);
m.add(val);
But it becomes
int thisVal = findMin(m);
// System.out.println(val);
// m.add(val);
Why is this case and how to paste correctly with the formatting? Thank you.
Upvotes: 21
Views: 24459
Reputation: 71
None of the previous answers worked for me.
What helped is paste the text via shift + insert
instead of ctrl + v
or smth.
This is direct paste without any enabling or disabling.
Found it here.
Upvotes: 0
Reputation: 157
This is just a simple hack, but it works. S1 : Create your file in <file_name>.txt format S2 : Paste your code and save S3 : Rename your file to whatever file format required
Done !
Upvotes: 0
Reputation: 373
In order to permanently save the defined variables:
vi ~/.vimrc
Add following lines, save & exit
:set paste #will enable the paste mode as answered above
:set nu #this will show the line numbers for editor
Some Other allowed parameters can be added from the following list:
autoindent(ai)
autowrite(aw)
exrc(ex)
errorbells
flash
ignorecase(ic)
lisp
list
magic
modelines
number(nu)
showmatch(sm)
showmode(smd)
wrapscan(ws)
Hope this helps to someone else too.
Upvotes: 1
Reputation: 11349
:set paste
should cause indenting to work correctly. As uku points out, you can read more information on paste mode using
:h paste
you can turn off paste mode with
:set nopaste
Upvotes: 42
Reputation: 1340
Use
:set paste
Or
:set noai
Noai (no auto indent) can be again disabled using :set ai
Upvotes: 3