# How do I get the CodeMirror instance for the currently active view?
#obsidian/api/faq
---
## Sample Code
```ts
import type { MarkdownView } from 'obsidian';
/* ... */
const { workspace } = this.app;
const activeView = workspace.getActiveViewOfType(MarkdownView);
if (activeView) { // The active view might not be a markdown view
const editor = activeView.sourceMode.cmEditor;
}
```