Hey guys,

I'm new in Linux/Unix and just whant to figure out one simple thing:
So lets say I wrote my c program in vi in Linux, and whant it to be on the unix server.
When I'm trying to just copy and paste text from vi. It apperas in unix with tons of tabs spaces and stuff like that, so it is really hard to read.
So I would like to know how to copy text from my vi in linux and then paste it in exact the same format in Unix.

Sorry I accidentally create two posts and don't know how to delete one of them. does anyone also know this?

Dani AI

Generated

Common causes for the mangled layout reported by are editor auto‑indentation, differing tab widths between environments, terminal paste handling, and mixed line endings. As pointed out, the exact copy method and which editors/distros are involved change the right fix. As noted, most editors offer a “paste” mode to stop automatic reformatting; the suggestions below give practical alternatives so the file arrives on the Unix host exactly as saved on Linux.

Best practice: transfer the file instead of manual copy/paste. This preserves tabs, whitespace and permissions:

scp myprog.c username@unixhost:/home/username/
rsync -av --progress myprog.c username@unixhost:/home/username/

When paste is unavoidable: use the remote shell to accept raw input so the editor doesn’t reformat. For example:

cat > myprog.c
[paste file contents here]
Ctrl-D

This writes the pasted bytes directly to the file.

Post-transfer or post-paste cleanup: normalize tabs/spaces and line endings so the code looks the same everywhere. Convert tabs to spaces and strip DOS CRs with:

expand -t 4 infile.c > outfile.c
dos2unix outfile.c

For consistent editing in vim, set tab width and convert tabs to spaces (editor-local options). Also check the file with a visible‑chars view (shows tabs and CRs) to confirm what changed.

Notes and cautions: avoid copy/paste through middle tools that reflow lines (webmail, some chat clients). Keep backups when running converters. These options cover most cases seen when moving C source between Linux and classic Unix shells.

Recommended Answers

All 2 Replies

Three!!! - 2 here, one in scripting.

I deleted them. Please dont cross post.

More details please. What is the file, what distros, how are you copy and pasting into where?

If you are pasting into vi, you might try running ":set paste" in vi before hitting insert and pasting.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.