Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use flake
File renamed without changes.
18 changes: 11 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,17 @@ jobs:
with:
access_token: ${{ github.token }}

- uses: actions/checkout@v1
- uses: actions/checkout@v4

- uses: actions/setup-node@v2
- uses: pnpm/action-setup@v4

- uses: actions/setup-node@v4
with:
node-version: 18
node-version: 22
cache: pnpm
cache-dependency-path: pnpm-lock.yaml

- run: yarn install
- run: cd ./dev/cm5 && yarn install
- run: yarn run build
- run: yarn run testAll
- run: pnpm install --frozen-lockfile
- run: pnpm run typecheck
- run: pnpm run build
- run: pnpm run testAll
40 changes: 40 additions & 0 deletions .github/workflows/publish-cm5.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: publish cm5-vim
on:
workflow_dispatch:

permissions:
contents: read

jobs:
publish:
name: Publish cm5-vim
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: pnpm/action-setup@v4

- uses: actions/setup-node@v4
with:
node-version: 22
cache: pnpm
cache-dependency-path: pnpm-lock.yaml
registry-url: https://registry.npmjs.org

- run: pnpm install --frozen-lockfile

# cm5-vim has no prepare script; its published files (vim.js,
# vim_test.js) are generated by its build.
- run: pnpm --filter cm5-vim run build

- name: Publish
env:
NODE_AUTH_TOKEN: ${{ secrets.CM5_NPM_TOKEN }}
run: |
version=$(node -p "require('./packages/cm5-vim/package.json').version")
if [ "$(npm view "cm5-vim@$version" version 2>/dev/null)" = "$version" ]; then
echo "cm5-vim@$version is already published, skipping"
else
echo "Publishing cm5-vim@$version"
(cd packages/cm5-vim && pnpm publish --no-git-checks)
fi
41 changes: 41 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: publish
on:
workflow_dispatch:

permissions:
contents: read

jobs:
publish:
name: Publish @replit/codemirror-vim-core and @replit/codemirror-vim
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: pnpm/action-setup@v4

- uses: actions/setup-node@v4
with:
node-version: 22
cache: pnpm
cache-dependency-path: pnpm-lock.yaml
registry-url: https://registry.npmjs.org

- run: pnpm install --frozen-lockfile

# Core is published first: @replit/codemirror-vim depends on it, so the
# version its workspace:^ range resolves to must exist on the registry.
- name: Publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
for dir in packages/codemirror-vim-core packages/codemirror-vim; do
name=$(node -p "require('./$dir/package.json').name")
version=$(node -p "require('./$dir/package.json').version")
if [ "$(npm view "$name@$version" version 2>/dev/null)" = "$version" ]; then
echo "$name@$version is already published, skipping"
else
echo "Publishing $name@$version"
(cd "$dir" && pnpm publish --access public --no-git-checks)
fi
done
2 changes: 1 addition & 1 deletion .github/workflows/test-link.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
const owner = context.payload.pull_request.head.repo.owner.login;
const repo = context.payload.pull_request.head.repo.name;
const commit = context.payload.pull_request.head.sha;
const link = `https://raw.githack.com/${owner}/${repo}/${commit}/dev/web-demo.html`;
const link = `https://raw.githack.com/${owner}/${repo}/${commit}/packages/codemirror-vim/dev/web-demo.html`;

const { data: pullRequest } = await github.rest.pulls.get({
owner: context.repo.owner,
Expand Down
9 changes: 6 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ node_modules
package-lock.json
dist
out
/test/*.js
/test/*.d.ts
/test/*.d.ts.map
/packages/codemirror-vim/test/*.js
/packages/codemirror-vim/test/*.d.ts
/packages/codemirror-vim/test/*.d.ts.map
.*
!.envrc
!.github
!.github/**
.DS_Store
4 changes: 2 additions & 2 deletions .replit
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
run="yarn run dev"
run="pnpm run dev"

[packager]
language = "nodejs-yarn"
language = "nodejs-pnpm"
[packager.features]
packageSearch = true
guessImports = false
Expand Down
82 changes: 14 additions & 68 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,75 +1,21 @@
# Vim keybindings for CM6
# codemirror-vim

<span><a href="https://replit.com/@util/codemirror-vim" title="Run on Replit badge"><img src="https://replit.com/badge/github/replit/codemirror-vim" alt="Run on Replit badge" /></a></span>
<span><a href="https://www.npmjs.com/package/@replit/codemirror-vim" title="NPM version badge"><img src="https://img.shields.io/npm/v/@replit/codemirror-vim?color=blue" alt="NPM version badge" /></a></span>
Vim keybindings for CodeMirror.

## Installation
This is a pnpm workspace containing three packages:

```sh
npm i @replit/codemirror-vim
```

## Usage

```js
import { basicSetup, EditorView } from 'codemirror';
import { vim } from "@replit/codemirror-vim"

let view = new EditorView({
doc: "",
extensions: [
// make sure vim is included before other keymaps
vim(),
// include the default keymap and all other keymaps you want to use in insert mode
basicSetup,
],
parent: document.querySelector('#editor'),
})
```
> **Note**:
> if you are not using `basicSetup`, make sure you include the [drawSelection](https://codemirror.net/docs/ref/#view.drawSelection) plugin to correctly render the selection in visual mode.

## Usage of cm5 vim extension api

The same api that could be used in previous version of codemirror https://codemirror.net/doc/manual.html#vimapi, can be used with this plugin too, just replace the old editor instance with `view.cm` in your code

```js
import {Vim, getCM} from "@replit/codemirror-vim"

let cm = getCM(view)
// use cm to access the old cm5 api
Vim.exitInsertMode(cm)
Vim.handleKey(cm, "<Esc>")
```

### Define additional ex commands
```js
Vim.defineEx('write', 'w', function() {
// save the file
});
```

### Map keys
```js
Vim.map("jj", "<Esc>", "insert"); // in insert mode
Vim.map("Y", "y$"); // in normal mode
```
- [`@replit/codemirror-vim`](packages/codemirror-vim) — Vim keybindings for CodeMirror 6 (the main package)
- [`cm5-vim`](packages/cm5-vim) — the same vim engine bundled for CodeMirror 5
- [`@replit/codemirror-vim-core`](packages/codemirror-vim-core) — the editor-agnostic vim engine and shared test suite used by both, originally authored by [@mightyguava](https://github.com/mightyguava) (Yunchi Luo)

### Unmap keys
## Development

```js
Vim.unmap("jj", "insert");
```

### Add custom key

```js
defaultKeymap.push({ keys: 'gq', type: 'operator', operator: 'hardWrap' });
Vim.defineOperator("hardWrap", function(cm, operatorArgs, ranges, oldAnchor, newHead) {
// make changes and return new cursor position
});
```sh
pnpm install
pnpm run dev # start the CodeMirror 6 demo
pnpm run test # run the CodeMirror 6 test suite
pnpm run testAll # run all tests, including cm5 and packaging checks
```

## Credits

This plugin was originally authored by [@mightyguava](https://github.com/mightyguava) (Yunchi Luo) as part of [CodeMirror](https://github.com/codemirror/dev), before being extracted and maintained here.
The repo ships a nix dev shell via direnv: `direnv allow` provides node, pnpm,
and the browsers needed for tests.
29 changes: 0 additions & 29 deletions dev/cm5/package.json

This file was deleted.

27 changes: 27 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
description = "Dev environment for @replit/codemirror-vim";

inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";

outputs = { self, nixpkgs }:
let
systems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ];
forAllSystems = f: nixpkgs.lib.genAttrs systems (system: f nixpkgs.legacyPackages.${system});
in {
devShells = forAllSystems (pkgs: {
default = pkgs.mkShell {
packages = [
pkgs.nodejs_22
pkgs.pnpm
] ++ pkgs.lib.optionals pkgs.stdenv.isLinux [
# needed by cm-runtests (selenium)
pkgs.chromedriver
pkgs.chromium
];
};
});
};
}
58 changes: 8 additions & 50 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,56 +1,14 @@
{
"name": "@replit/codemirror-vim",
"version": "6.3.0",
"description": "Vim keybindings for CodeMirror 6",
"author": {
"name": "Yunchi Luo",
"email": "mightyguava@gmail.com"
},
"name": "codemirror-vim-workspace",
"private": true,
"packageManager": "pnpm@11.17.0",
"scripts": {
"dev": "vite ./dev",
"test": "cm-runtests",
"build-types": "rm -rf out && tsc && dts-bundle-generator out/index.ts -o dist/index.d.ts && cp dist/index.d.ts dist/index.d.cts",
"testAll": "yarn run build-test-package && yarn run test && cd dev/cm5 && yarn run buildAndTest",
"build": "cm-buildhelper src/index.ts && node scripts/addVersion.cjs && npm run build-types",
"publish": "yarn run build && npm publish",
"build-test-package": "bash ./scripts/build-test-package.sh",
"prepare": "yarn run build"
},
"keywords": [
"editor",
"code"
],
"type": "module",
"main": "dist/index.cjs",
"exports": {
"import": "./dist/index.js",
"require": "./dist/index.cjs"
},
"types": "dist/index.d.ts",
"module": "dist/index.js",
"sideEffects": false,
"license": "MIT",
"peerDependencies": {
"@codemirror/commands": "6.x.x",
"@codemirror/language": "6.x.x",
"@codemirror/search": "6.x.x",
"@codemirror/state": "6.x.x",
"@codemirror/view": "6.x.x"
},
"devDependencies": {
"@codemirror/buildhelper": "^1.0.2",
"@codemirror/lang-javascript": "6.x.x",
"@codemirror/lang-xml": "6.x.x",
"@codemirror/language": "6.x.x",
"codemirror": "6.x.x",
"dts-bundle-generator": "^9.5.1",
"typescript": "^5.8.2",
"vite": "^6.2.2"
"dev": "pnpm --filter @replit/codemirror-vim run dev",
"build": "pnpm -r run build",
"test": "pnpm --filter @replit/codemirror-vim run test",
"testAll": "pnpm --filter @replit/codemirror-vim run testAll && pnpm --filter cm5-vim run buildAndTest",
"typecheck": "pnpm -r run typecheck"
},
"files": [
"dist",
"README.md"
],
"repository": {
"type": "git",
"url": "https://github.com/replit/codemirror-vim.git"
Expand Down
File renamed without changes.
Loading
Loading