Editor Plugins
While sgrep doesn’t have native editor plugins yet, its CLI-first design makes it easy to integrate with any editor through configuration. Below are setups for popular editors.
VS Code
tasks.json Configuration
Add semantic search tasks to your workspace:
{
"version": "2.0.0",
"tasks": [
{
"label": "sgrep: Current File",
"type": "shell",
"command": "sgrep",
"args": [
"${input:query}",
"${file}"
],
"problemMatcher": [],
"presentation": {
"reveal": "always",
"panel": "new"
}
},
{
"label": "sgrep: Workspace",
"type": "shell",
"command": "sgrep",
"args": [
"${input:query}",
"${workspaceFolder}"
],
"problemMatcher": []
}
],
"inputs": [
{
"id": "query",
"type": "promptString",
"description": "Search query"
}
]
}
Keybinding
Add a keybinding to trigger sgrep quickly:
{
"key": "ctrl+shift+s",
"command": "workbench.action.tasks.runTask",
"args": "sgrep: Current File"
}
Extension Integration
Use with any terminal extension like:
- code-runner: Configure custom command
- multi-command: Chain sgrep with other tools
- output-colorizer: Highlight results
Quick Pick
Create a VS Code extension that uses Quick Pick:
// Extension that wraps sgrep
const query = await vscode.window.showInputBox({
prompt: 'Search semantically'
});
if (query) {
const terminal = vscode.window.createTerminal('sgrep');
terminal.sendText(`sgrep "${query}" ${file}`);
}
Neovim / Vim
Basic Integration
Add to your init.lua:
-- Semantic search function
vim.api.nvim_create_user_command('Sgrep', function(opts)
local query = opts.args
if query == '' then
query = vim.fn.input('Search: ')
end
local file = vim.fn.expand('%:p')
vim.cmd('term sgrep "' .. query .. '" ' .. file)
end, { nargs = '?' })
-- Keybinding
vim.keymap.set('n', '<leader>sg', ':Sgrep ', { desc = 'Sgrep search' })
Using grepprg
Set sgrep as your grep program:
" In your .vimrc or init.vim
set grepprg=sgrep\ $*
set grepformat=%f:%l:%m
" Usage
:grep "database query" src/
" Open quickfix automatically
autocmd QuickFixCmdPost grep copen
Telescope Integration
If you use Telescope.nvim:
local telescope = require('telescope')
local pickers = require('telescope.pickers')
local finders = require('telescope.finders')
local conf = require('telescope.config').values
vim.api.nvim_create_user_command('TelescopeSgrep', function(opts)
local query = opts.args
if query == '' then
query = vim.fn.input('Search: ')
end
pickers.new({}, {
prompt_title = 'Sgrep Results',
finder = finders.new_oneside_job({
command_generator = function()
return { 'sgrep', '--json', query, vim.fn.expand('%:p:h') }
end,
entry_maker = function(line)
local ok, data = pcall(vim.json.decode, line)
if ok and data.score then
return {
value = data,
display = string.format('%s:%d %s', data.path, data.line, data.text),
ordinal = data.text,
}
end
end
}),
sorter = conf.generic_sorter(),
previewer = conf.grep_previewer(),
}):find()
end, { nargs = '?' })
FZF Integration
command! -nargs=1 FzfSgrep call fzf#run({
\ 'source': 'sgrep --json <args> | jq -r ".[] | \(.path):\(.line):\(.text)"',
\ 'sink': 'e',
\ 'options': '--multi --reverse'
\ })
JetBrains IDEs
External Tool Configuration
Go to Settings → Tools → External Tools and add:
Name: sgrep Search
Program: /path/to/sgrep (or just sgrep if in PATH)
Arguments: $Prompt$ $FilePath$
Working directory: $ProjectFileDir$
External Tool for Workspace
Name: sgrep Workspace
Program: sgrep
Arguments: $Prompt$ $ProjectFileDir$
Working directory: $ProjectFileDir$
Keyboard Shortcut
Assign a keyboard shortcut in Settings → Keymap: Search for “sgrep” and bind to your preferred keys.
Using File Watchers
Set up a file watcher to run sgrep on save:
- Go to Settings → Tools → File Watchers
- Add new watcher for your file type
- Program:
sgrep - Arguments:
"potential bug" $FilePath$ - Output: Parse with regex for highlighting
Emacs
Basic Function
(defun sgrep-search (query)
"Run sgrep with QUERY on current file."
(interactive "sSearch query: ")
(let ((file (buffer-file-name)))
(compile (format "sgrep \"%s\" %s" query file))))
;; Keybinding
(global-set-key (kbd "C-c s") 'sgrep-search)
With Transient
Create a transient menu for sgrep:
(require 'transient)
(transient-define-prefix sgrep-transient ()
"Sgrep commands"
["Sgrep"
[("s" "Search File" sgrep-search-file)
("w" "Search Workspace" sgrep-search-workspace)
("j" "JSON Output" sgrep-json-search)]])
(global-set-key (kbd "C-c g") 'sgrep-transient)
Consult Integration
If you use Consult:
(defun consult-sgrep (query)
"Search with sgrep using Consult."
(interactive "sSearch: ")
(consult--grep
"sgrep"
(list "sgrep" "--json" query)
nil))
(define-key global-map (kbd "C-c g") 'consult-sgrep)
Compilation Mode
Parse sgrep JSON output in compilation mode:
(defun sgrep-compilation (query directory)
(interactive "sQuery: \nDDirectory: ")
(let ((buf (compile (format "sgrep --json \"%s\" %s" query directory))))
(with-current-buffer buf
(setq-local compilation-error-regexp-alist
'(sgrep))
(setq-local compilation-error-regexp-alist-alist
'((sgrep "^{\"path\":\"\\([^\"]+\\)\",\"line\":\\([0-9]+\\)" 1 2))))))
Sublime Text
Build System
Create Packages/User/sgrep.sublime-build:
{
"selector": "source.rust,source.python,source.js",
"cmd": ["sgrep", "$query", "$file"],
"working_dir": "$project_path",
"variants": [
{
"name": "Workspace",
"cmd": ["sgrep", "$query", "$project_path"]
}
]
}
Command Palette
Add a command to Packages/User/Default.sublime-commands:
[
{
"caption": "Sgrep: Search File",
"command": "show_overlay",
"args": {"overlay": "command_palette", "text": "Build: sgrep - $query"}
}
]
Kakoune
# Define sgrep command
define-command sgrep -params 1 %{
evaluate-commands %sh{
query=$1
file=$kak_buffile
results=$(sgrep --json "$query" "$file")
echo "$results" | jq -r '"'"$file"':\(.line):\(.text)"'
}
}
# Keybinding
map global user s ':sgrep ' -docstring 'sgrep search'
Helix
Add to ~/.config/helix/config.toml:
[[keys]]
key = "space"
mode = "n"
commands = [
{ name = "sgrep_search", command = [":run-shell-command", "sgrep \"$0\" {file}"] }
]
Tip: Most editors support running external commands. If your editor isn’t listed, check its documentation for “external tools” or “shell commands.”
Was this page helpful?