<!doctype html>
<title>CodeMirror 5 User Manual</title>
<meta charset="utf-8"/>
<link rel=stylesheet href="docs.css">
<script src="activebookmark.js"></script>
<script src="../lib/codemirror.js"></script>
<link rel="stylesheet" href="../lib/codemirror.css">
<script src="../addon/runmode/runmode.js"></script>
<script src="../addon/runmode/colorize.js"></script>
<script src="../mode/javascript/javascript.js"></script>
<script src="../mode/xml/xml.js"></script>
<script src="../mode/css/css.js"></script>
<script src="../mode/htmlmixed/htmlmixed.js"></script>
<style>
dt { text-indent: -2em; padding-left: 2em; margin-top: 1em; }
dd { margin-left: 1.5em; margin-bottom: 1em; }
dt {margin-top: 1em;}
dd dl, dd dt, dd dd, dd ul { margin-top: 0; margin-bottom: 0; }
dt + dt { margin-top: 0; }
dt.command { position: relative; }
span.keybinding { position: absolute; right: 0; font-size: 80%; color: #555; text-indent: 0; }
</style>
<div id=nav>
<a href="https://codemirror.net/5"><h1>CodeMirror</h1><img id=logo src="logo.png"></a>
<ul>
<li><a href="../index.html">Home</a></li>
<li><a href="#overview" class=active data-default="true">Manual</a></li>
<li><a href="https://github.com/codemirror/codemirror5">Code</a></li>
</ul>
<ul>
<li><a href="#usage">Basic Usage</a></li>
<li><a href="#config">Configuration</a></li>
<li><a href="#events">Events</a></li>
<li><a href="#keymaps">Key maps</a></li>
<li><a href="#commands">Commands</a></li>
<li><a href="#styling">Customized Styling</a></li>
<li><a href="#api">Programming API</a>
<ul>
<li><a href="#api_constructor">Constructor</a></li>
<li><a href="#api_content">Content manipulation</a></li>
<li><a href="#api_selection">Selection</a></li>
<li><a href="#api_configuration">Configuration</a></li>
<li><a href="#api_doc">Document management</a></li>
<li><a href="#api_history">History</a></li>
<li><a href="#api_marker">Text-marking</a></li>
<li><a href="#api_decoration">Widget, gutter, and decoration</a></li>
<li><a href="#api_sizing">Sizing, scrolling, and positioning</a></li>
<li><a href="#api_mode">Mode, state, and tokens</a></li>
<li><a href="#api_misc">Miscellaneous methods</a></li>
<li><a href="#api_static">Static properties</a></li>
</ul>
</li>
<li><a href="#addons">Addons</a></li>
<li><a href="#modeapi">Writing CodeMirror Modes</a></li>
<li><a href="#vimapi">Vim Mode API</a>
<ul>
<li><a href="#vimapi_configuration">Configuration</a></li>
<li><a href="#vimapi_events">Events</a></li>
<li><a href="#vimapi_extending">Extending VIM</a></li>
</ul>
</li>
</ul>
</div>
<article>
<section class=first id=overview>
<h2 style="position: relative">
User manual and reference guide
<span style="color: #888; font-size: 1rem; position: absolute; right: 0; bottom: 0">version 5.65.16</span>
</h2>
<p>CodeMirror is a code-editor component that can be embedded in
Web pages. The core library provides <em>only</em> the editor
component, no accompanying buttons, auto-completion, or other IDE
functionality. It does provide a rich API on top of which such
functionality can be straightforwardly implemented. See
the <a href="#addons">addons</a> included in the distribution,
and <a href="https://npms.io/search?q=codemirror">3rd party
packages on npm</a>, for reusable implementations of extra
features.</p>
<p>CodeMirror works with language-specific modes. Modes are
JavaScript programs that help color (and optionally indent) text
written in a given language. The distribution comes with a number
of modes (see the <a href="../mode/"><code>mode/</code></a>
directory), and it isn't hard to <a href="#modeapi">write new
ones</a> for other languages.</p>
</section>
<section id=usage>
<h2>Basic Usage</h2>
<p>The easiest way to use CodeMirror is to simply load the script
and style sheet found under <code>lib/</code> in the distribution,
plus a mode script from one of the <code>mode/</code> directories.
For example:</p>
<pre data-lang="text/html"><script src="lib/codemirror.js"></script>
<link rel="stylesheet" href="lib/codemirror.css">
<script src="mode/javascript/javascript.js"></script></pre>
<p>(Alternatively, use a module loader. <a href="#modloader">More
about that later.</a>)</p>
<p>Having done this, an editor instance can be created like
this:</p>
<pre data-lang="javascript">var myCodeMirror = CodeMirror(document.body);</pre>
<p>The editor will be appended to the document body, will start
empty, and will use the mode that we loaded. To have more control
over the new editor, a configuration object can be passed
to <a href="#CodeMirror"><code>CodeMirror</code></a> as a second
argument:</p>
<pre data-lang="javascript">var myCodeMirror = CodeMirror(document.body, {
value: "function myScript(){return 100;}\n",
mode: "javascript"
});</pre>
<p>This will initialize the editor with a piece of code already in
it, and explicitly tell it to use the JavaScript mode (which is
useful when multiple modes are loaded).
See <a href="#config">below</a> for a full discussion of the
configuration options that CodeMirror accepts.</p>
<p>In cases where you don't want to append the editor to an
element, and need more control over the way it is inserted, the
first argument to the <code>CodeMirror</code> function can also
be a function that, when given a DOM element, inserts it into the
document somewhere. This could be used to, for example, replace a
textarea with a real editor:</p>
<pre data-lang="javascript">var myCodeMirror = CodeMirror(function(elt) {
myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});</pre>
<p>However, for this use case, which is a common way to use
CodeMirror, the library provides a much more powerful
shortcut:</p>
<pre data-lang="javascript">var myCodeMirror = CodeMirror.fromTextArea(myTextArea);</pre>
<p>This will, among other things, ensure that the textarea's value
is updated with the editor's contents when the form (if it is part
of a form) is submitted. See the <a href="#fromTextArea">API
reference</a> for a full description of this method.</p>
<h3 id=modloader>Module loaders</h3>
<p>The files in the CodeMirror distribution contain shims for
loading them (and their dependencies) in AMD or CommonJS
environments. If the variables <code>exports</code>
and <code>module</code> exist and have type object, CommonJS-style
require will be used. If not, but there is a
function <code>define</code> with an <code>amd</code> property
present, AMD-style (RequireJS) will be used.</p>
<p>It is possible to
use <a href="http://browserify.org/">Browserify</a> or similar
tools to statically build modules using CodeMirror. Alternatively,
use <a href="http://requirejs.org/">RequireJS</a> to dynamically
load dependencies at runtime. Both of these approaches have the
advantage that they don't use the global namespace and can, thus,
do things like load multiple versions of CodeMirror alongside each
other.</p>
<p>Here's a simple example of using RequireJS to load CodeMirror:</p>
<pre data-lang="javascript">require([
"cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
CodeMirror.fromTextArea(document.getElementById("code"), {
lineNumbers: true,
mode: "htmlmixed"
});
});</pre>
<p>It will automatically load the modes that the mixed HTML mode
depends on (XML, JavaScript, and CSS). Do <em>not</em> use
RequireJS' <code>paths</code> option to configure the path to
CodeMirror, since it will break loading submodules through
relative pa
codemirror.zip
需积分: 0 150 浏览量
更新于2024-04-19
收藏 1.45MB ZIP 举报
CodeMirror是一个开源的、跨平台的代码编辑器,主要用于网页开发。它可以在浏览器环境中运行,为Web应用提供高质量的代码编辑功能。这个"codemirror.zip"文件包含了CodeMirror的一个特定版本,即5.65.16。下面将详细介绍CodeMirror的相关知识点。
1. **CodeMirror基本概念**:
CodeMirror是一个JavaScript库,它可以被嵌入到HTML页面中,为用户提供在线代码编辑的功能。支持多种编程语言的语法高亮,包括但不限于JavaScript、HTML、CSS、Python、Java等,并且可以自定义更多语言。
2. **主要特性**:
- **语法高亮**:CodeMirror能够识别多种编程语言,并对不同语言的代码进行颜色区分,提高代码可读性。
- **自动缩进**:根据代码的结构自动调整缩进,保持代码整洁。
- **代码折叠**:允许用户折叠和展开代码块,方便查看和管理大量代码。
- **实时错误检测**:通过模式匹配,可以在用户输入时即时检查代码错误。
- **搜索与替换**:内置搜索和替换功能,方便用户在代码中查找和替换文本。
- **多光标与多选**:支持同时设置多个光标,实现快速编辑。
- **可扩展性**:可以通过插件系统添加新的语言支持和功能。
3. **版本5.65.16**:
这个版本可能包含了一些修复的bug、性能优化或者新特性的添加。每个版本的更新都会在官方文档中记录,具体改动需要查看当时的发布日志。
4. **使用方法**:
在网页中引入CodeMirror的JS和CSS文件,然后创建一个HTML元素作为编辑器的容器,通过JavaScript调用CodeMirror实例化编辑器,并配置需要的语言和支持的特性。
5. **集成与应用**:
CodeMirror常用于在线编程教育平台、代码分享网站、网页版IDE(集成开发环境)等场景,为用户提供友好的代码编辑体验。
6. **插件系统**:
CodeMirror的插件系统是其强大之处,开发者可以根据需求选择或开发插件,如行号显示、行拖拽、自动完成等,进一步增强编辑器功能。
7. **API与事件**:
CodeMirror提供了丰富的API供开发者操作编辑器,如获取/设置当前选区、监听用户输入事件等,方便与后端或其他前端组件交互。
8. **社区与文档**:
CodeMirror有一个活跃的开发者社区,提供了详尽的文档和示例,帮助开发者快速上手和解决问题。
总结来说,CodeMirror是一个功能强大的在线代码编辑器,适用于各种需要在网页中编辑代码的场景。这个"codemirror.zip"文件包含的5.65.16版本,是CodeMirror的一个稳定版本,可以用于项目中,或者作为研究和学习CodeMirror的基础。
晴天16
- 粉丝: 2
- 资源: 2
最新资源
- 这是一个对于开源的四轴无人机开源飞控系统修改学习的仓库.zip
- 用于FPV微型无人机比赛和自由式的一流拉丝飞行控制器 http_alienwhoop.us_.zip
- 这是一个通过pixhawk飞控来学习多旋翼无人机的学生的仓库.zip
- 这是一个简单的无人机轨迹追踪demo,也是一份offboard实飞控制踩坑经验总结.zip
- 这是一个无人机四轴项项目,使用stm32 作为主控,使用固件库编程,移植ucos ii 操作系统,最终实现飞机可以起飞的完整项目.zip
- 这是一个与电院天线所合作的项目,由501实验室的研发学生Phillweston与Devotlig负责.zip
- 整合uav模型与gazebo环境,开放测试demo,可使用键盘控制无人机进行遥控飞行与飞行状态数据检.zip
- 1.科大讯飞智慧课堂平板之前大多是联想系或者荣耀系低端机,此类平板基本都可以解除bl锁,进行刷机操作.zip
- 悬浮颗粒两相流模拟 本案例基于COMSOL软件模拟了不同密度大小的悬浮颗粒在混合溶液中的流动沉积情况,模拟结果如图所示1.密度较大颗粒的沉积情况2.密度较小颗粒悬浮混合情况 3000j
- 压盖检测机sw20可编辑全套技术资料100%好用.zip
- 机器人开发代码实战项目ros开发,可以快速上手 有安装运行教程
- 44、COMSOL模拟二维裂隙流压裂水平井裂缝性油藏离散裂缝网络模型COMSOL数值模拟案例
- 硬盘上料机sw16全套技术资料100%好用.zip
- VT笔记,VT仿真笔记,VT教程,原版仿真实战笔记升级版,加入多轴及车铣复合仿真笔记啦加量不加价(vericut)原版仿真设置实战经验笔记 +cimco edit仿真笔记分享:全网唯一超详解析,让你快
- 2006-2020年各省常住人口数数据
- 光伏储能交直流微电网Matlab simulink仿真~由光伏、蓄电池及负载组成的独立直流微电网,提出电压和电流分段式协同控制策略 该控制策略将能量管理划分为 4 种工作模式,采用最大功率点跟踪控制