• macOS下VS Code 使用记录(使用调试运行 Python/C 等)


    一、首先可以在本地新建分支

    git branch hce

    然后切换分支

    git checkout hce

    也可以两个命令一起使用合并成一条新建加切换分支

    git checkout -b hce

    二、新建一个远程分支(同名字的远程分支)

    git push origin hce:hce

    //创建了一个远程分支名字叫 hce

    三、把本地的新分支,和远程的新分支关联
    如果新建本地分支之后直接git push推送的话会出现fatal: 当前分支 hce没有对应的上游分支。为推送当前分支并建立与远程上游的跟踪,使用git push --set-upstream origin Dev
    就直接使用下面命令

    git push --set-upstream origin hce
    也可以使用

    git push -u origin hce
    -u参数与–set-upstream参数是同一个意思

    四、查看远程分支
    git branch -a

    查看本地分支和远程分支关联情况

    git remote -v


    远程开发
    1. 安装插件 Remote Development

    2. 修改设置
    Command + , 打开设置面板,输入关键词来查询

     

    3. 添加远程配置

    安装完插件后左下角会出现一个绿色的图标


    点击选择会在命令窗口弹出几个选项,选择 Connect to Host – Open SSH Configuration File
    点击后,会打开 ~/.ssh/config 文件,内容如下

    Host alias
        HostName hostname
        User user

    我改为自己需要远程的 IP 地址和登录名

    Host 10.xx.xx.xx

       HostName 10.xx.xx.xx

       User root

       IdentityFile  ~/.ssh/id_rsa


    4. 连接

    再次点击左下角绿色按钮,再次选择 Connect to Host,这时会出现刚设置的 host,比如我的 55

    连接中,需要输入密码

    点击打开,可以选择远程主机上的文件夹


    在打开的文件中编写,远程主机上的文件就会发生改变。

    其他配置
    添加配置文件(launch.json)解决 ModuleNotFoundError 的问题
    如果工程目录有多级,在子目录中引用另一个子目录的内容,即使增加了 sys.path,在 VSCode 中可能依然会会报 ModuleNotFoundError 问题(PyCharm 则不会)
    根据查询,这是VSCode 的问题,增加 launch.json 设置 env 可以解决这个问题。方式如下:

    点击添加配置

    会在项目目录下生成 .vscode 目录,目录下有 launch.json 文件

    增加 env 和 envFile 两个键即可

    {
        // 使用 IntelliSense 了解相关属性。 
        // 悬停以查看现有属性的描述。
        // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
        "version": "0.2.0",
        "configurations": [
            {
                "name": "Python",
                "type": "python",
                "request": "launch",
                "program": "${file}",
                "console": "integratedTerminal",
                "env": {"PYTHONPATH":"${workspaceRoot}"},
                "envFile": "${workspaceRoot}/.env",
            }
        ]
    }

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    窗口显示完整路径


    可以看到原来的设置为:

    ${activeEditorShort}${separator}${rootName}
    1
    将 activeEditorShort 改为 activeEditorMedium;

    如果需要显示完整路径,则改为 activeEditorLong

    完整即:

    ${activeEditorLong}${separator}${rootName}
    1
    user snippets 快捷代码块
    进入 python.json
    比如 pycharm 中输入 main 的时候,会自动补全 main 函数,vscode 中则需要手动设置。

    会在主窗口弹出这样的 sheet

    列表中有众多语言,输入 py 选择 python 即可;

    会进入 python.json 的编辑页面

    这个文件位于 ~/Library/Application Support/Code/User/snippets/python.json

    初始内容如下:

    {
        // Place your snippets for python here. Each snippet is defined under a snippet name and has a prefix, body and 
        // description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
        // $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the 
        // same ids are connected.
        // Example:
        // "Print to console": {
        //     "prefix": "log",
        //     "body": [
        //         "console.log('$1');",
        //         "$2"
        //     ],
        //     "description": "Log output to console"
        // }
    }
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    添加多组配置
    原有内容不改动,增加 pymain 的配置;结果如下

    {
        // Place your snippets for python here. Each snippet is defined under a snippet name and has a prefix, body and 
        // description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
        // $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the 
        // same ids are connected.
        // Example:
        // "Print to console": {
        //     "prefix": "log",
        //     "body": [
        //         "console.log('$1');",
        //         "$2"
        //     ],
        //     "description": "Log output to console"
        // }

        "py1":{
          "prefix": "pymain",
          "body": [
            "if __name__ == '__main__':",
            "    ",
          ],
          "description": "python–main"
        },

        "py2":{
            "prefix": "prt",
            "body": [
                "print('')", 
            ],
            "description": "print fuction"
        }

    }

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    保存即可生效

    在编辑器键入 pymain 的时候,即可出现提示,回车即可键入

    添加代码头部
    参考:https://blog.csdn.net/itsxwz/article/details/102697216

    pycharm 中可以设置创建 py 文件时,自动添加头部信息,vscode 目前没发现这个功能,我们也可以用 user snippets 来快捷添加头部信息。这里还可以使用一些变量,如:


        "HEADER": {
            "prefix": "header",
            "body": [
                "#!/usr/bin/env python",
                "# -*- encoding: utf-8 -*-",
                "'''",
                "@File    :   $TM_FILENAME",
                "@Time    :   $CURRENT_YEAR/$CURRENT_MONTH/$CURRENT_DATE $CURRENT_HOUR:$CURRENT_MINUTE:$CURRENT_SECOND",
                "@Author  :   Allen Mike",
                "@Version :   1.0",
                "@Contact :   wsjjfal@126.com",
                "@Desc    :   None",
                "'''",
                "",
                "",
                "$0"
            ],
        }

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    出现效果为:

    #!/usr/bin/env python
    # -*- encoding: utf-8 -*-
    '''
    @File    :   csd.py
    @Time    :   2021/10/28 15:54:07
    @Author  :   Allen Mike
    @Version :   1.0
    @Contact :   wsjjfal@126.com
    @Desc    :   None
    '''
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    你可以根据需要,修改这个代码段,更多变量和使用方法可见:https://blog.csdn.net/maokelong95/article/details/54379046/

    word wrap 自动换行
    进入设置,搜索 wrap,在 Editor : Word Wrap 选择 bounded;
    Command + ,


    自动补全函数的括号
    进入 settings.json 文件(我的位于 ~/Library/Application\ Support/Code/User/settings.json)
    添加如下行:

    "python.analysis.completeFunctionParens": true,
    ————————————————
    版权声明:本文为CSDN博主「伊织code」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
    原文链接:https://blog.csdn.net/lovechris00/article/details/120982639

  • 相关阅读:
    力扣287. 寻找重复数
    C++多态
    Android学习笔记 70. 学会帮助自己【自理】
    渗透实例------2个星期艰难的渗透纪实
    代码整洁之道-读书笔记之对象和数据结构
    【环境】ubuntu下anaconda虚拟环境中安装的pytorch终于配置成功了!
    【mcuclub】STC89C52单片机最小系统讲解
    队栈
    树莓派4B UbuntuMate 远程桌面 步骤
    HY11P54紘康SOC芯片
  • 原文地址:https://blog.csdn.net/weixin_42498050/article/details/126165598