vscode-sftp
vscode-sftp copied to clipboard
Control M characters (^M) are getting added, at the line end
Expected Behavior
import os import sys import shutil import glob
Actual Behavior
import os^M import sys^M import shutil^M import glob^M
Steps to Reproduce the Problem
- Transfer any file to remote linux machine from windows client (VS code)
- After uploading the file , go to remote linux machine and open the file with vi editor
- At the end of each line, you can see ^M being added.
Usually this happens SFTP tranferred from windows to Unix. These characters need to be ripped off before uploaded. There is a utility called dos2unix, FYI
Requisites
Extension Logs
[set option sftp.printDebugLog
to true, then reload vscode, reproduce the problem, get the logs(view -> output-> sftp)]
Specifications
- Version: sftp:0.6.7
- Platform: Windows 10 client, Ubuntu 16.XX remote
I'm sorry. You should strip the ^M
character yourself. This extension just transfers files.
I got a solution to my problem. Anyways, Thanks!!
If anyone was curious about this question (in 2019) and you are using Windows VSCode, with a Linux remote & you're using git.
This works best if your repository is consistently using LF.
Windows git needs to be reconfigured to not automatically convert your local repos to CRLF
git config --global core.eol lf
git config --global core.autocrlf input
This way, when code comes in, it'll not be converted to CRLF, but when you check code in, it'll be guaranteed to be LF.
Then you need to refresh your repository. (If you have uncommitted changes, you might want to back them up, or push upstream. The --cached should not delete them, but if you want to be extra careful).
git rm -rf --cached .
git reset --hard HEAD
Where I got some info from: https://stackoverflow.com/a/33424884/3648890
I got a solution to my problem. Anyways, Thanks!!
It would be nice if you cloud explain the solution to this problem.
A little theoretical knowledge, you are running Windows, and the server is Linux. Windows uses CRLF (which corresponds to chr(10)chr(13), which is Ctrl+J Ctrl+M; and that is why you are seeing whose ^M characters.
The culprit is, almost always, Git. (Well, the other possibility is generally the editor, but VSCode does not have that behavior, so..)
Thanks @xNinjaKittyx for the solution.
I had the same issue, and found this extension to display actual end of lines (to adapt my setup to the actual project):
https://marketplace.visualstudio.com/items?itemName=medo64.render-crlf
I got a solution by changing the carriage return (CRLF in windows) to (LF) for line ending.
- I used the command palette (shift+crtl+p) then I selected the option "Change End Of Line sequence"
- Select LF
Furthermore, you can install the "Render Line Endings" to check the changes
I found this solution which ignores the difference between carriage return:
git config --global core.whitespace cr-at-eol