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
26 changes: 26 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Tests

on:
push:
branches: [main, master]
pull_request:
branches: [main, master]

jobs:
test:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Install Vim
run: sudo apt-get update && sudo apt-get install -y vim

- name: Clone vim-themis
run: git clone --depth 1 https://github.com/thinca/vim-themis.git test/vim-themis

- name: Run tests
env:
THEMIS_VIM: vim
run: ./scripts/test.sh
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Testing framework (cloned during tests)
test/vim-themis/
197 changes: 197 additions & 0 deletions IMPLEMENTATION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
# vim-logseq Implementation Summary

## Overview
Complete implementation of a Vim plugin for Logseq-style markdown files with all requested features.

## Features Implemented

### 1. TODO/DOING/DONE Syntax Highlighting ✓
- **TODO**: Red, bold
- **DOING**: Yellow, bold
- **DONE**: Green, bold
- **Tags (#tag)**: Cyan, italic
- **Wiki links ([[page]])**: Blue, underlined

**Files**: `syntax/logseq.vim`

### 2. Tag Search Functionality ✓

#### :Ltag Command
- Search for tags across all Logseq markdown files
- Usage: `:Ltag work` or `:Ltag #work`
- Opens editable buffer with results
- Shows file paths and line numbers
- Changes can be saved with `:w` to update original files

#### gf on Tags
- Place cursor on any tag (e.g., `#work`)
- Press `gf` to trigger tag search
- Works anywhere within the tag text

**Files**: `autoload/logseq.vim`, `plugin/logseq.vim`

### 3. Jump to Today's Journal ✓
- Command: `:Ltoday`
- Opens `journals/YYYY_MM_DD.md` with today's date
- Creates file if it doesn't exist
- Auto-generates header for new journals

**Files**: `autoload/logseq.vim`, `plugin/logseq.vim`

### 4. Wiki Link Support ✓

#### gf on Wiki Links
- Place cursor on `[[Page Name]]`
- Press `gf` to open the linked page
- Searches in `pages/` directory first
- Falls back to searching entire Logseq directory
- Creates new page if not found

**Files**: `autoload/logseq.vim`, `plugin/logseq.vim`

### 5. Search Across Directory ✓
- Command: `:Lsearch pattern`
- Full-text search across all markdown files
- Results displayed in quickfix window
- Navigate with `:cn` and `:cp`

**Files**: `autoload/logseq.vim`, `plugin/logseq.vim`

## Architecture

### Directory Structure
```
vim-logseq/
├── plugin/logseq.vim # Main plugin, commands, mappings
├── autoload/logseq.vim # Core functions (lazy-loaded)
├── syntax/logseq.vim # Syntax highlighting rules
├── ftdetect/logseq.vim # Filetype detection
├── doc/vim-logseq.txt # Vim help documentation
├── README.md # User documentation
├── TESTING.md # Testing guide
└── examples/ # Sample Logseq files for testing
├── journals/
│ └── 2026_01_10.md
└── pages/
├── Project_Alpha.md
├── Technical_Specs.md
└── Team_Members.md
```

### Key Design Decisions

1. **Autoload Pattern**: Core functions use Vim's autoload mechanism for lazy loading
2. **Filetype Detection**: Automatically detects Logseq directories based on structure
3. **Editable Search Results**: Tag search creates a special buffer with write hooks
4. **Smart Link Following**: Single `gf` mapping handles both tags and wiki links
5. **Caching**: Directory detection results are cached for performance

## Security & Quality

### Security Fixes Applied
- ✓ Escape special characters in search patterns to prevent command injection
- ✓ Use `fnameescape()` for file paths
- ✓ Proper input sanitization for user queries

### Code Quality Improvements
- ✓ Extracted magic numbers to named constants
- ✓ Fixed off-by-one errors in array indexing
- ✓ Added caching to reduce filesystem calls
- ✓ Consistent use of header_lines constant

### Testing
- Comprehensive testing guide in `TESTING.md`
- Example files for manual testing
- All features verified with test scripts

## Configuration

### Optional Settings
```vim
" Set Logseq root directory (defaults to current directory)
let g:logseq_root = '~/Documents/Logseq'
```

### Auto-Detection
Plugin automatically detects Logseq directories when files are in:
- `journals/` directory
- `pages/` directory
- `logseq/` directory
- Any directory with `journals/` or `pages/` sibling

## Usage Examples

### Basic Workflow
```vim
" Open today's journal
:Ltoday

" Add content with tags
- TODO Review code #work #priority
- Meeting notes about [[Project Alpha]]

" Search for all work items
:Ltag work

" Edit results and save
:w

" Follow a tag
" (move cursor to #priority and press gf)

" Follow a wiki link
" (move cursor to [[Project Alpha]] and press gf)

" Search for text
:Lsearch architecture
```

## Documentation

1. **README.md**: Quick start and feature overview
2. **doc/vim-logseq.txt**: Complete Vim help documentation (`:help vim-logseq`)
3. **TESTING.md**: Comprehensive testing guide with examples
4. **examples/**: Sample Logseq files demonstrating all features

## Completeness

All requirements from the problem statement are fully implemented:

- [x] TODO/DOING/DONE syntax with appropriate colors
- [x] Tag search with `gf` on `#tag`
- [x] `:Ltag` command for arbitrary tag search
- [x] Editable tag search results that propagate changes
- [x] Jump to today's journal with correct naming format
- [x] Wiki links to other pages with `gf` support
- [x] Search across entire Logseq directory

## Installation

### vim-plug
```vim
Plug 'spacebarlabs/vim-logseq'
```

### Vundle
```vim
Plugin 'spacebarlabs/vim-logseq'
```

### Manual
```bash
git clone https://github.com/spacebarlabs/vim-logseq.git ~/.vim/pack/plugins/start/vim-logseq
```

## Future Enhancements (Not in Scope)

Potential improvements for future versions:
- Syntax highlighting for other Logseq elements (properties, queries)
- Auto-complete for tags and page names
- Integration with Logseq's query language
- Task status cycling with keyboard shortcuts
- Preview of linked pages in popup
- Backlink navigation

## Conclusion

The vim-logseq plugin is complete and production-ready. It provides a comprehensive set of features for working with Logseq markdown files in Vim, with proper documentation, testing, and security considerations.
100 changes: 99 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,100 @@
# vim-logseq
A vim plugin for Logseq-style files

A Vim plugin for working with Logseq-style markdown files.

## Features

- **Syntax Highlighting** for TODO/DOING/DONE keywords and tags
- **Tag Search** (`:Ltag`) with editable results that propagate changes back to source files
- **Jump to Today's Journal** (`:Ltoday`) - opens `journals/YYYY_MM_DD.md`
- **Wiki Links** - navigate with `gf` on `[[page]]` links
- **Tag Navigation** - use `gf` on `#tag` to search for all occurrences
- **Full Directory Search** (`:Lsearch`) across all Logseq markdown files

## Installation

### Using vim-plug
```vim
Plug 'spacebarlabs/vim-logseq'
```

After adding to your `init.vim` or `.vimrc`:
1. Restart Vim/Neovim or run `:source $MYVIMRC`
2. Run `:PlugInstall`
3. Restart Vim/Neovim again

### Using Vundle
```vim
Plugin 'spacebarlabs/vim-logseq'
```

After adding, run `:PluginInstall` and restart Vim/Neovim.

### Manual
```bash
git clone https://github.com/spacebarlabs/vim-logseq.git ~/.vim/pack/plugins/start/vim-logseq
```

For Neovim:
```bash
git clone https://github.com/spacebarlabs/vim-logseq.git ~/.local/share/nvim/site/pack/plugins/start/vim-logseq
```

## Quick Start

1. Open any markdown file in your Logseq directory
2. Try `:Ltoday` to open today's journal
3. Use `:Ltag <tagname>` to search for tags
4. Press `gf` on tags or wiki links to navigate

## Troubleshooting

### Plugin not loading (`:Ltag` command not found)

1. **Check if plugin is installed**: Run `:LogseqDebug` to see plugin status
2. **Verify filetype plugin is enabled**: Add to your config:
```vim
filetype plugin indent on
syntax on
```
3. **Check installation path**: Run `:set runtimepath?` and verify vim-logseq is listed
4. **Restart Vim/Neovim**: After installing or modifying config, restart completely
5. **Run the test script**: From the plugin directory, run `./test-install.sh`

### Syntax highlighting not working

1. Check filetype is set correctly: Open a Logseq file and run `:set filetype?`
- Should show `logseq` for files in `journals/` or `pages/` directories
- If it shows `markdown`, manually set: `:set filetype=logseq`
2. Ensure syntax is enabled: `:syntax on`
3. For files outside journals/pages, manually set filetype: `:set filetype=logseq`

### Commands exist but don't work

1. Ensure you're in a Logseq directory structure (with `journals/` or `pages/` subdirectories)
2. Set the Logseq root: `let g:logseq_root = '/path/to/your/logseq'`
3. Run `:LogseqDebug` to check configuration

### For vim-plug users specifically

Make sure your `init.vim` or `.vimrc` has this structure:
```vim
call plug#begin()
Plug 'spacebarlabs/vim-logseq'
call plug#end()

" These must come AFTER plug#end()
filetype plugin indent on
syntax on
```

## Documentation

See `:help vim-logseq` for full documentation.

## Configuration

```vim
" Set your Logseq root directory (optional)
let g:logseq_root = '~/Documents/Logseq'
```
Loading