Code Import

pending

by yhao3

Import code files with @import syntax. Compatible with Foam.

1 starsUpdated 16d agoMITDiscovered via Obsidian Unofficial Plugins
View on GitHub

Code Import Plugin for Obsidian

Import external code files in your Obsidian notes using @import syntax (compatible with Markdown Preview Enhanced).

Screenshots

Desktop

Full file import:

Full Import

Partial import (specific lines):

Partial Import

Mobile (iOS)

Full importPartial import
Mobile FullMobile Partial

Features

  • Import code files directly in Reading View
  • Support line range selection (line_begin, line_end)
  • Automatic syntax highlighting based on file extension
  • Works with relative paths (including ../)

Syntax

@import "path/to/file.go"
@import "path/to/file.go" {line_begin=4 line_end=14}
@import "examples/main.py" {line_begin=10}
@import "config.yaml" {line_end=-4}

Parameters

ParameterDescription (0-based)Description (1-based)
line_beginStart line, 0-based indexStart line, 1-based index
line_endEnd line, exclusive (supports negative)End line, inclusive (supports negative)

Line Index Examples

0-based mode (default, MPE-compatible):

  • {line_begin=0 line_end=10} → Lines 1-10 (indices 0-9)
  • {line_begin=5} → From line 6 to end
  • {line_end=-2} → From start, excluding last 2 lines

1-based mode:

  • {line_begin=1 line_end=10} → Lines 1-10
  • {line_begin=5} → From line 5 to end
  • {line_end=-2} → From start, excluding last 2 lines

Installation

From Community Plugins

  1. Open Settings → Community plugins
  2. Search for "Code Import"
  3. Install and enable

Manual Installation

  1. Download main.js, manifest.json, styles.css from Releases
  2. Create folder: <vault>/.obsidian/plugins/code-import/
  3. Copy the files into the folder
  4. Enable the plugin in Settings → Community plugins

Usage

  1. Place your code files in your vault (or reference them with relative paths)
  2. Add @import directive in your markdown file
  3. Switch to Reading View to see the imported code

Example

In your markdown file:

## User Struct Definition

@import "examples/user.go" {line_begin=10 line_end=25}

Settings

SettingDescriptionDefault
Show file nameDisplay filename header above code blockOn
Wrap codeWrap long lines instead of horizontal scrollingOff
Line number base0-based (MPE-compatible) or 1-based indexing for line_begin/line_end0-based

License

MIT

For plugin developers

Search results and similarity scores are powered by semantic analysis of your plugin's README. If your plugin isn't appearing for searches you'd expect, try updating your README to clearly describe your plugin's purpose, features, and use cases.