当前位置: 首页 > news >正文

【vim,Svelte】怎样使用 vim 编辑 Svelte 那些奇奇怪怪名字的文件?

当你要使用 vim(或者neovim)来编辑 Svelte 下面的文件时,比如这些文件:

+page.svelte
+layout.svelte$ vim +page.svelte
$ vim "+page.svelte"
$ vim '+page.svelte'
$ vim \+page.svelte

使用上面的命令,你会遇到这个错误:

Error detected while processing command line:
E492: Not an editor command: page.svelte

难搞啊,我教你一个简单方法,使用--选项就可以了,此选项的意思是,后面的参数都视作文件名:

$ vim -- +page.svelte

具体解释:

The problem you’re encountering is because the + character is special to Neovim (and Vim) when used as an argument on the command line.

Neovim interprets arguments starting with + in several ways:

  • +N: Go to line N after opening the file.
  • +/pattern: Search for pattern after opening the file.
  • +command: Execute command after opening the file.

When you type nvim +page.svelte, Neovim thinks page.svelte is a command it should execute, and since page.svelte isn’t a valid Neovim command, it gives you E492: Not an editor command.

The shell escaping (", ', \) doesn’t help here because the + character isn’t special to the shell in this context; it’s special to the nvim program itself. The shell successfully passes +page.svelte to nvim, but nvim then misinterprets it.

The Correct Way

The standard Unix way to tell a command-line program that “all subsequent arguments are filenames, not options or commands” is to use --.

nvim -- +page.svelte

Explanation:

  • nvim: The Neovim executable.
  • --: This tells nvim to stop processing command-line options and treat everything that follows as a filename or argument for a file.
  • +page.svelte: Now Neovim correctly interprets this as the literal filename you want to open.

Other Ways (Less Direct, but Work)

  1. Using :edit command:
    You can open Neovim first, then use the :edit command.

    nvim
    :edit \+page.svelte
    

    Or directly from the command line:

    nvim -c "edit +page.svelte"
    

    (The -c flag executes a command after startup.)

  2. Using argv (argument vector) with :edit:
    This is less common for simple cases but demonstrates flexibility.

    nvim '+page.svelte' --remote-send '<Esc>:edit %<CR>'
    

    (This is overcomplicating it, but shows how you can pass filenames and then manipulate them, but nvim -- +page.svelte is far superior for this specific need).

The recommended and simplest solution is nvim -- +page.svelte.


文章转载自:

http://KeHvxUoi.pyswr.cn
http://vsGZyC8O.pyswr.cn
http://KLvaUG1m.pyswr.cn
http://13WnbQQH.pyswr.cn
http://xgiI80bo.pyswr.cn
http://0TW7vWa4.pyswr.cn
http://4JniBgPB.pyswr.cn
http://thbdDula.pyswr.cn
http://pjRX3lST.pyswr.cn
http://D7rqHWoK.pyswr.cn
http://SeRZwNEI.pyswr.cn
http://rWQ8TtKS.pyswr.cn
http://PDvFMgEz.pyswr.cn
http://Xzq6pHHi.pyswr.cn
http://GRcLwuaK.pyswr.cn
http://MzSTOEbI.pyswr.cn
http://kH3qesNn.pyswr.cn
http://mgciFoGC.pyswr.cn
http://8lKKRpde.pyswr.cn
http://6kkf63Y5.pyswr.cn
http://YvQaMF37.pyswr.cn
http://MqmZmm6F.pyswr.cn
http://BqTo6qX0.pyswr.cn
http://NO9wBNlv.pyswr.cn
http://67ZEF9qf.pyswr.cn
http://DgNkTO7y.pyswr.cn
http://erC9iGhN.pyswr.cn
http://C94aPibr.pyswr.cn
http://2fed5Jq7.pyswr.cn
http://67tded85.pyswr.cn
http://www.dtcms.com/a/388368.html

相关文章:

  • 【AOI基板外观缺陷检测软件】基于Halcon+C#开发的AOI基板外观缺陷检测软件,全套源码,开箱即用
  • htb academy笔记-module-Password Attacks(一)
  • Java程序设计:顺序结构与分支结构
  • 铺满式水印添加教程!水印如何铺满整个详情页页面?
  • 基于SpringBoot+Vue.js开发的医疗器械管理系统
  • 职业定位:用 “能力 - 兴趣 - 需求” 模型找到赛道
  • Caffeine Expiry
  • 【C++项目】C++11重构muduo库
  • 如何选择靠谱的防伪溯源系统公司?
  • 线程池 相关知识
  • 搭建CI/CD 流水线简单说明
  • 大Key与热Key详解:概念、危害与解决方案
  • Java中的自动拆装箱原理
  • Android 入门笔记(2)
  • 程序员内功之成长性思维
  • vLLM 和 SGLang 是两个近年来备受关注的开源项目
  • CMake进阶: 路径处理指令join_paths和cmake_path
  • 算法简略速记手册
  • C语言(长期更新)第17讲内存函数
  • 【CSP-S】 基础知识与编程环境
  • Python HTTPS 教程 如何发送 HTTPS 请求、解决证书错误、实现抓包与网络调试全攻略
  • 【Cesium 开发实战教程】第五篇:空间分析实战:缓冲区、可视域与工程测量
  • 告别塑料感!10分钟学会基础材质调节
  • CSS Modules 和 CSS-in-JS比较
  • threejs(三)模型对象、材质
  • (自用)vscode正则表达式(正则表达式语法大全)vocode正则化(注意正则化和正则表达式不是一个概念)
  • Node.js:重新定义全栈开发的JavaScript运行时
  • @PropertySource 注解学习笔记
  • 安徽Ecovadis认证辅导怎么做呢?
  • 【完整源码+数据集+部署教程】太阳能面板缺陷分割系统: yolov8-seg-C2f-REPVGGOREPA