vscode 基本配置和使用

原文地址为: vscode 基本配置和使用

快捷键

在terminal打开vccode code

ctrl+p 查看搜索打开目录下的所有的文件

ctrl+shift+p 或者 F1 打开控制台

alt+shift+up/down 列选择

alt+up/down 选中后使用快捷键,整块代码向上/下移动

alt+click Multiple cursors多处编辑(注:ubuntu和本身快捷键冲突,按alt会弹出菜单,需要设置gsettings set org.gnome.desktop.wm.preferences mouse-button-modifier "<Super>"

ctrl+  将一个文档分分为两个窗口,最多三个

ctrl+tab 切换打开的tab栏,按tab选择

ctrl+g 跳转到指定的行

ctrl+shift+f 在打开的文件夹中寻找(可以选择文件搜索范围,支持正则表达式,反向引用:$1)

ctrl+f 在当前文件查找

ctrl+h在当前文件中

shift+alt+鼠标 块选择

ctrl+` 启动终端

ctrl+/ 加/解注释

folding折叠

  • Fold (Ctrl+Shift+[) 折叠所在的这个部分

  • Unfold (Ctrl+Shift+]) 取消所在部分的折叠
    Fold All (Ctrl+K Ctrl+0) 折叠当前编辑文件的所有可折叠部分

  • Unfold All (Ctrl+K Ctrl+J) 取消当当前文件所有折叠

  • Fold Level X (Ctrl+K Ctrl+2 for level 2) 折叠所有level x(还可以用 ctrl+3、ctrl+4等)的缩进去(除了当前编辑位置所在的)

控制台Command Palette

不一定要输入完整的命令,会有提示的

  • theme、setting、keybord(快捷键)、snip、fold
  • git(各种操作)
    比如:git checkout
    蓝色:改变的行,绿色:新的行,红色尖尖:被删除的行
    选项里:撤销上次提交、显示git信息

使用和配置

基本配置

自动保存

在用户配置文件中配置,可以通过控制台熟读setting快速打开

files.autoSave: 可以有以下的值

off - to disable auto save.

afterDelay - to save files after a configured delay.

onFocusChange - to save files when focus moves out of the editor of the dirty file.

onWindowChange - to save files when the focus moves out of the VS Code window.

files.autoSaveDelay: Configures the delay in milliseconds when files.autoSave is configured to afterDelay.

代理

详情见

Note: VS Code supports http and https proxies, but not SOCKS proxies.

tasks

tasks就是一些预定义的任务,必须在文件夹下才可以运行(因为人家需要有配置文件嘛)

定义自己的task

控制台输入task,然后就知道怎么做了,后边选others(任意任务),有示例

command and tasks[]

同一命令,不同参数

{
    "version": "0.1.0",
    "command": "echo",
    "isShellCommand": true,
    "args": [],
    "showOutput": "always",
    "echoCommand": true,
    "suppressTaskName": true,
    "tasks": [
        { 
            "taskName": "hello",
            "args": ["Hello World"]
        },
        { 
            "taskName": "bye",
            "args": ["Good Bye"]
        }
    ]
}
running task commands through a shell command
{
    "version": "0.1.0",
    "command": "sh",
    "args": ["-c"],
    "isShellCommand": true,
    "showOutput": "always",
    "suppressTaskName": true,
    "tasks": [
        {
            "taskName": "make",
            "args": ["make"]
        },
        {
            "taskName": "ls",
            "args": ["ls"]
        }
    ]
}
也许配置中会使用到的变量

${workspaceRoot} VS Code当前打开的文件夹

${file} 当前打开的文件

${relativeFile} 相对于workspaceRoot的相对路径

${fileBasename} 当前打开文件的文件名

${fileDirname} 所在的文件夹,是绝对路径

${fileExtname} 当前打开文件的拓展名,如.json

${cwd} the task runner's current working directory on startup

使用环境变量${env.Name} (e.g. ${env.PATH})

Editor Groups分屏

Ctrl+1 go to the leftmost editor group.

Ctrl+2 go to the center editor group.

Ctrl+3 go to the rightmost editor group.

Ctrl+W close the active editor.

snippets设置和使用代码块
   "For Loop": {
        "prefix": "for",
        "body": [
            "for (var ${index} = 0; ${index} < ${array}.length; ${index}++) {",
            "\tvar ${element} = ${array}[${index}];",
            "\t$0",
            "}"
        ],
        "description": "For Loop"
    },
  • For Loop 代码块的名字
  • prefix 定义触发的关键词
  • body 内容
  • description 输入关键词出发snippets的提示信息

可选的变量:

  • $1, $2 tab 停止的地方

  • ${id} 定义变量(填空的地方),如 ${lable}是变量

相同id的文件会被绑定到一起同时编辑


如果你的代码含有{ or}, 需要转义,如\\{ and \\}

配置内部使用的terminal

参见cmder基本配置和使用

插件推荐

  • amVim

可以像使用wim那样使用VSC

简直棒,可以在文件前显示语言logo之类的图标

  • vscode-fileheader

在文件前边添加注释

特定语言

html

开头输入然后按tab,整个html框架补全
输入标签名称然后tab,补全标签

php
  • php Debug棒的不行
    需要在setting.json里设置"php.validate.executablePath": "/usr/bin/php"
  • php IntelliSense Crane 补全超级牛
  • PHP IntelliSense 另一个,能搜索函数、格式化代码
  • 好像要一个可以自动生成标准doc注释的插件,不过暂时没找到
C
  • C/C++ 微软出的
    note:觉得这些拓展的功能还是太弱了,居然上边定义的变量都没有提示。kdevelop还不错,界面也挺棒的,强烈推荐。
    debug需要使用make、gdb 。右击断点可以设置条件断点,监控栏可以监控一些表达式。
    配置示例:
    lanuch.json需要增加或者修改的,都有提示
"program": "${workspaceRoot}/build",
"preLaunchTask": "build"

task.json problemMatcher:将错误信息显示出来

{
     "version": "0.1.0",
     "command": "make",
     "showOutput": "always",
     "tasks": [
         {
             "taskName": "clean""args":[
                    "clean"
                ]
         },
         {
             "taskName": "build",
             "problemMatcher": {
                 "owner": "cpp",
                 "fileLocation":  ["relative", "${workspaceRoot}"],
                 "pattern": {
                     "regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
                     "file": 1,
                     "line": 2,
                     "column": 3,
                     "severity": 4,
                     "message": 5
                 }
             }
         }
     ]
 }

markdown

  • markdown theme kit
  • 好看的css找了一下午,好多挺好看css的和主题不搭
    有好看的可不可以分享一下~~

python

拓展推荐:python 就是搜python排名最高那个,安装之后右击查看强大功能
调试配置(只截取修改部分):
在用户配置(可通过console控制台里输setting打开)里面将python改为运行python命令的地址,如果在终端中可以直接运行python命令,只输入python也可以
下边python文件中的pythonpath也是指的python命令地址

    "configurations": [
        {
            "name": "Python",
            "type": "python",
            "request": "launch",
            "stopOnEntry": true,
            "pythonPath": "${config.python.pythonPath}",
            "program": "${file}",
            "debugOptions": [
                "WaitOnAbnormalExit",
                "WaitOnNormalExit",
                "RedirectOutput"
            ]
        },
        {
            "name": "Flask",
            "type": "python",
            "request": "launch",
            "stopOnEntry": false,
            "pythonPath": "${config.python.pythonPath}",        //如果需要用venv里面的python,需要把这个改成python命令位置,类似这样的/home/jcuan/code/python/project/venv/bin/python
            "program": "/home/jcuan/code/python/project/venv/bin/flask",        //flask命令地址,flask0.11之后可以通过flask run的方式来运行python,不过需要一些配置,比如FLASK_APP环境变量的设置,可以通过运行 flask --help 和flask  run --help来查看帮助
            "env": {
                "FLASK_APP": "${workspaceRoot}/app/__init__.py"        //设置必要环境变量,这个文件就是你项目开始的那个文件
            },
            "args": [            //运行flask命令的参数
                "run",
                "--no-debugger",
                "--no-reload"
            ],
            "debugOptions": [
                "WaitOnAbnormalExit",
                "WaitOnNormalExit",
                "RedirectOutput"
            ]
        }

我的__init__.py大概像这样的,

from flask import Flask

app = Flask(__name__, static_folder='statics', static_url_path='/static')
app.config.from_pyfile('config.py')

import hello

转载请注明本文地址: vscode 基本配置和使用
Visual Studio CodeVSCode)是一个轻量级但功能强大的源代码编辑器,它支持Git版本控制系统的集成使用,使得用户可以直接在VSCode中进行版本控制操作。以下是VSCode中Git配置使用基本步骤: 1. 安装Git:确保你的电脑上已经安装了Git。如果没有安装,你可以从Git官方网站下载并安装。 2. 打开你的项目:在VSCode中打开你想要版本控制的项目文件夹。 3. 初始化Git仓库(如果尚未初始化):在VSCode的终端(Terminal)中输入`git init`命令来初始化一个新的Git仓库。 4. 连接VSCode与Git:VSCode会自动检测到项目中的`.git`文件夹,并识别出这是一个Git仓库。如果没有自动识别,VSCode也可能提供一个提示来帮助你连接到Git。 5. 使用源代码控制面板:VSCode提供了一个源代码控制面板(Source Control),你可以在这里找到提交(Commit)按钮。点击该按钮,输入你的提交信息并提交更改。 6. 分支管理:VSCode支持查看和切换分支。你可以在源代码控制面板的顶部看到当前分支,点击下拉菜单可以切换分支或者创建新分支。 7. 查看和解决冲突:如果在合并分支时出现代码冲突,VSCode会高亮显示冲突区域,并提供解决冲突的选项。 8. 查看提交历史:你可以通过源代码控制面板查看所有的提交历史记录,包括每个提交的摘要和详细信息。 9. 远程仓库:对于远程仓库的操作,VSCode允许你从GitHub、GitLab、Azure DevOps等服务中拉取(Pull)和推送(Push)代码。 10. 扩展插件:VSCode有丰富的扩展插件市场,你可以安装如GitLens等扩展来增强Git功能,例如查看提交历史、比较差异等高级功能。 配置VSCode使用Git时,确保你的VSCode版本是最新的,以便获得最佳的Git支持体验。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值