Skip to content

Commit 4e68d36

Browse files
committed
initial commit
0 parents  commit 4e68d36

File tree

16 files changed

+2506
-0
lines changed

16 files changed

+2506
-0
lines changed

.github/workflows/lint.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Lint
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
lint:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v4
10+
11+
- name: Setup Lua
12+
uses: leafo/gh-actions-lua@v10
13+
with:
14+
luaVersion: "5.1"
15+
16+
- name: Setup LuaRocks
17+
uses: leafo/gh-actions-luarocks@v4
18+
19+
- name: Install luacheck
20+
run: luarocks install luacheck
21+
22+
- name: Run luacheck
23+
run: luacheck lua/ --globals vim
24+
25+
- name: Install StyLua
26+
uses: JohnnyMorganz/stylua-action@v4
27+
with:
28+
token: ${{ secrets.GITHUB_TOKEN }}
29+
version: latest
30+
args: --check lua/

.github/workflows/test.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Tests
2+
on:
3+
push:
4+
branches: [master]
5+
pull_request:
6+
branches: [master]
7+
workflow_dispatch:
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
name: unit tests
13+
strategy:
14+
fail-fast: false
15+
matrix:
16+
neovim: [stable, nightly]
17+
18+
steps:
19+
- uses: actions/checkout@v4
20+
21+
- uses: rhysd/action-setup-vim@v1
22+
with:
23+
neovim: true
24+
version: ${{ matrix.neovim }}
25+
26+
- name: Cache stylua
27+
uses: actions/cache@v4
28+
with:
29+
path: /usr/local/bin/stylua
30+
key: stylua-${{ runner.os }}-${{ hashFiles('Makefile') }}
31+
32+
- name: Install dependencies
33+
run: make prepare
34+
35+
- name: Run tests
36+
run: |
37+
nvim --version
38+
make test

.gitignore

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Lua
2+
*.luac
3+
lua_modules/
4+
.luarocks/
5+
6+
# IDE
7+
.idea/
8+
.vscode/
9+
*.swp
10+
*.swo
11+
*~
12+
13+
# OS
14+
.DS_Store
15+
Thumbs.db
16+
17+
# Test output
18+
.tests/

.luacheckrc

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
-- Luacheck configuration for Neovim Lua plugins
2+
3+
-- Global objects
4+
globals = {
5+
"vim",
6+
}
7+
8+
-- Read-only globals
9+
read_globals = {
10+
"vim",
11+
}
12+
13+
-- Don't report unused self arguments of methods
14+
self = false
15+
16+
-- Don't report unused arguments when they start with underscore
17+
unused_args = false
18+
19+
-- Max line length
20+
max_line_length = 120
21+
22+
-- Ignore some warnings
23+
ignore = {
24+
"212", -- Unused argument
25+
"631", -- Line is too long
26+
}
27+
28+
-- Exclude test files from some checks
29+
files["tests/**/*.lua"] = {
30+
globals = {
31+
"describe",
32+
"it",
33+
"before_each",
34+
"after_each",
35+
"assert",
36+
}
37+
}

CLAUDE.md

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<!-- markdownlint-disable MD013 -->
2+
3+
# CLAUDE.md
4+
5+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
6+
7+
## Project Overview
8+
9+
search-replace.nvim is a Neovim plugin for enhanced search and replace with a floating dashboard. It provides quick keymaps to populate substitute commands, toggle flags (g/c/i), cycle through ranges/separators/magic modes, and shows a live dashboard during command-line editing.
10+
11+
## Commands
12+
13+
### Linting
14+
15+
```bash
16+
luacheck lua/ --globals vim
17+
stylua --check lua/
18+
```
19+
20+
### Formatting
21+
22+
```bash
23+
stylua lua/
24+
```
25+
26+
### Testing
27+
28+
```bash
29+
# Run all tests (requires busted test framework)
30+
busted tests/
31+
32+
# Run a specific test file
33+
busted tests/search-replace_spec.lua
34+
```
35+
36+
## Architecture
37+
38+
The plugin follows a modular architecture with four main components:
39+
40+
### init.lua (Entry Point)
41+
42+
- Handles `setup()` configuration merging
43+
- Sets up keymaps for normal/visual/command-line modes
44+
- Re-exports public API from core module
45+
46+
### core.lua (Business Logic)
47+
48+
- Manages search-replace state (`sar_state`) tracking active session, current word, separator, magic mode
49+
- Implements toggle functions that return keystroke sequences using `<C-\>e` expression pattern
50+
- All toggle functions use `set_cmd_and_pos()` helper to update both command text and cursor position atomically
51+
- Uses `should_sar()` to detect if current cmdline is a substitute command (either in active mode or auto-detected)
52+
53+
### dashboard.lua (UI)
54+
55+
- Parses substitute commands and displays current state in a floating window
56+
- Uses `CmdlineChanged` autocmd to auto-detect and display dashboard for any substitute command
57+
- Maintains a `hidden` state to respect user's manual toggle
58+
- Applies syntax highlighting using extmarks in a namespace
59+
60+
### float.lua (Window Management)
61+
62+
- Reusable floating window implementation inspired by mini.notify architecture
63+
- Handles buffer/window caching, creation, and cleanup
64+
- Uses `vim.cmd('redraw')` after updates for immediate display
65+
- Reschedules operations via `vim.schedule()` when in fast event context
66+
67+
### utils.lua (Shared Utilities)
68+
69+
- Pattern constants for substitute command detection
70+
- `parse_substitute_cmd()` - parses `:s` commands into range/separator/magic/search/replace/flags
71+
- `split_by_separator()` - splits strings while respecting escaped separators
72+
- `trigger_cmdline_refresh()` - uses fake keystroke (space + backspace) to force cmdline refresh
73+
74+
## Key Implementation Details
75+
76+
- Toggle functions return expression strings that Neovim evaluates (using `{ expr = true }` in keymap)
77+
- The `<C-\>e` pattern allows replacing the entire command line via expression evaluation
78+
- Dashboard refresh uses a fake keystroke technique because direct redraws don't work in cmdline mode
79+
- The plugin auto-detects any substitute command (not just those started via `<leader>r`) to show the dashboard
80+
81+
## Code Style
82+
83+
- Uses 2-space indentation
84+
- Single quotes preferred
85+
- Max line length: 120 characters
86+
- LuaDoc annotations for type hints (`---@class`, `---@param`, `---@return`)

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 Moshe Avni
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Makefile

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
.PHONY: all lint test prepare clean
2+
3+
all: test
4+
5+
lint:
6+
stylua --check lua/
7+
luacheck lua/ --globals vim
8+
9+
test: prepare lint
10+
nvim --headless --noplugin -u tests/minimal_init.vim -c "PlenaryBustedDirectory tests { minimal_init = './tests/minimal_init.vim' }"
11+
12+
prepare:
13+
@test -d ../plenary.nvim || git clone --depth 1 https://github.com/nvim-lua/plenary.nvim ../plenary.nvim
14+
@command -v stylua >/dev/null || { \
15+
curl -L -o stylua.zip https://github.com/JohnnyMorganz/StyLua/releases/latest/download/stylua-linux-x86_64.zip && \
16+
unzip stylua.zip && \
17+
rm -f stylua.zip && \
18+
chmod +x stylua && \
19+
sudo mv stylua /usr/local/bin/; \
20+
}
21+
22+
clean:
23+
rm -rf ../plenary.nvim

0 commit comments

Comments
 (0)