大家有没有遇到过这样的情况:在终端里找到一个文件或者文件夹,想直接用代码编辑器打开,却还得费劲鼠标操作?这时候,命令行工具就派上用场了。今天咱们聊聊 Cursor 的命令行工具,这可是个效率神器,能让你轻松搞定各种代码编辑任务。
Cursor 是一个基于 Visual Studio Code 的现代化代码编辑器,既继承了 VS Code 的强大功能,又加入了自己的特色。它的命令行工具可以通过cursor
命令快速打开文件、对比文件、安装扩展等等,非常方便。下面咱们就来详细说说怎么用。
Cursor 是一款基于 Visual Studio Code (VS Code) 的现代化代码编辑器,所以它继承了 VS Code 的强大功能,如本文要介绍的 code 命令。
在 Visual Studio Code 中,code 或 cursor 命令是一个命令行工具,用于快速打开 VS Code 并执行一些与代码相关的操作。
AI代码生成神器 Cursor v0.47.8 for Windows 官方免费版
类型:编程工具 大小:107MB 语言:英文软件 时间:2025-03-19查看详情
cursor 基于GT-4的代码编辑器 V0.17.0 Linux最新免费版
类型:编程工具 大小:159MB 语言:英文软件 时间:2023-11-29查看详情
Cursor(智能AI代码生成工具) v0.48.9 官方版
类型:编程工具 大小:112MB 语言:简体中文 时间:2025-04-21查看详情
code 命令直接可以帮助开发者从终端或命令提示符中直接启动 VS Code 或处理特定的任务。
最常用的方式就是使用 code 或 cursor命令直接从命令行中打开文件目录,此时需要先安装 code 命令。
Cursor 支持将终端启动命令设置为 code 或 cursor,以便快速启动编辑器,如果本地已经安装了 VS Code,code 命令一般用在 VS Code 中,Cursor 使用 cursor 命令。
Table of Contents
启用 Cursor 的 code 命令 非常简单
1、打开命令面板
macOS 系统快捷键:⇧⌘P(command + shift + p) Windows/Linux 快捷键: Ctrl + Shift + P2、搜索安装命令
搜索安装 >shell command:
然后选择 在 PATH 中 安装 "cursor" 命令 - Shell Command: Install 'cursor' command in PATH 即可为系统 PATH 路径添加了 cursor 命令的引用。
3、完成安装
系统会自动把cursor
命令添加到 PATH 路径中,你就可以在终端里直接使用了。
我们可以通过命令行打开文件、安装扩展、修改显示语言,甚至查看诊断信息。
1、查看版本信息
通过 cursor --version 查看版本信息:
# cursor --version0.45.14906121b8c0bdf041c14a15dac228e66ab5505260arm64
这条命令会显示当前安装的 Cursor 版本信息,比如:
以下是一些常用的命令行选项,可以通过 cursor --help 命令查看:
Cursor 0.45.14Usage: cursor [options][paths...]To read from stdin, append '-' (e.g. 'ps aux | grep code | cursor -')Options -d --diff <file> <file> Compare two files with each other. -m --merge <path1> <path2> <base> <result> Perform a three-way merge by providing paths for two modified versions of a file, the common origin of both modified versions and the output file to save merge results. -a --add <folder> Add folder(s) to the last active window. -g --goto <file:line[:character]> Open a file at the path on the specified line and character position. -n --new-window Force to open a new window. -r --reuse-window Force to open a file or folder in an already opened window. -w --wait Wait for the files to be closed before returning. --locale <locale> The locale to use (e.g. en-US or zh-TW). --user-data-dir <dir> Specifies the directory that user data is kept in. Can be used to open multiple distinct instances of Code. --profile <profileName> Opens the provided folder or workspace with the given profile and associates the profile with the workspace. If the profile does not exist, a new empty one is created. -h --help Print usage.
2、打开文件或文件夹
我们可以在命令行中使用 cursor . 命令让文件夹在 Cursor 中打开:
cursor <路径>打开当前目录作为工作区:
cursor .
3、新窗口打开
如果你希望在一个新窗口中打开文件或文件夹,可以加上--new-window
参数:
cursor --new-window <路径>
4、对比两个文件
通过--diff
参数可以轻松对比两个文件的内容:
cursor --diff <文件1> <文件2>
5、等待窗口关闭
如果你希望在 Cursor 窗口关闭后再返回终端,可以使用--wait
参数:
cursor --wait <文件>
6、禁用扩展
想要在不加载任何扩展的情况下启动 Cursor,可以用这个命令:
cursor --disable-extensions
7、安装扩展
如果你想直接从命令行安装某个扩展,可以用以下命令:
cursor --install-extension <扩展名>
8、列出已安装扩展
想知道当前都装了哪些扩展?用这条命令就行:
cursor --list-extensions
9、卸载扩展
如果某个扩展已经用不上了,可以直接卸载:
cursor --uninstall-extension <扩展名>
快速打开当前目录如果你正在某个项目的根目录下,想快速用 Cursor 打开它,只需输入:
cursor .
这比用鼠标点来点去要快多了。
对比文件想看看两个文件的不同之处?用这个命令:cursor --diff file1.js file2.js
Cursor 会直接帮你打开一个对比视图,方便你查看差异。
多窗口操作有时候你可能需要同时打开多个项目,这时候可以用--new-window
参数:
cursor --new-window project1cursor --new-window project2安装扩展比如你需要安装一个叫做
Prettier
的格式化工具扩展,可以直接运行:
cursor --install-extension esbenp.prettier-vscode
命令功能说明code <路径>
打开文件或文件夹cursor .
打开当前目录作为工作区cursor --new-window
在新窗口中打开cursor --diff
对比两个文件的内容cursor --wait
等待窗口关闭后再返回终端cursor --disable-extensions
禁用所有扩展运行 VS Codecursor --install-extension <扩展名>
安装指定扩展cursor --list-extensions
列出所有已安装的扩展cursor --uninstall-extension <扩展名>
卸载指定扩展
命令 | 功能说明 |
---|---|
code <路径> |
打开文件或文件夹 |
cursor . |
打开当前目录作为工作区 |
cursor --new-window |
在新窗口中打开 |
cursor --diff |
对比两个文件的内容 |
cursor --wait |
等待窗口关闭后再返回终端 |
cursor --disable-extensions |
禁用所有扩展运行 VS Code |
cursor --install-extension <扩展名> |
安装指定扩展 |
cursor --list-extensions |
列出所有已安装的扩展 |
cursor --uninstall-extension <扩展名> |
卸载指定扩展 |
我觉得吧,Cursor 的命令行工具真的特别适合那些喜欢用键盘操作的开发者。它不仅能提高效率,还能让你在工作中更专注。比如说,我经常用cursor .
打开当前项目目录,或者用cursor --diff
对比代码文件,省去了不少麻烦。
最后嘛,感觉 Cursor 的命令行工具对日常开发帮助很大的,尤其是那些需要频繁切换项目或者管理扩展的场景。如果你还没试过,赶紧装一个试试吧!
WiFi已连接却无法上网怎么办? 无线路由器连接上但不能上网的解决办法