macvim-dev / macvim-dev/macvim
Feature Request: detect and reuse MacVim instance to open file by mvim:// url
Nessuno ha ancora preso questa issue.
- Lingua principale
- Vim Script
- Stelle
- 7.9k
- Fork
- 691
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Descrizione
Greeting!
I configure mvim:// in React Developer Tools to open file in MacVim from the browser extension.
mvim://open?url=file://{path}&line={line}
It works good, but there's a small issue. The issue is that MacVim doesn't reuse the instance that I opened if the target file hasn't been opened. For example, I launch MacVim from /path/to/my-project, and I open files /path/to/my-project/{a,b,c}.js from React Developer Tools. They have different results:
| file | is editing or has been opened | result |
|---|---|---|
| a.js | editing | 😃 get opened in the right instance |
| b.js | has been opened | 😃 ditto |
| c.js | neither | 💔 get opened in a new instance |
I hope the c.js can be opened like a.js and b.js.
I have a workaround in favor of Raycast Script Command deeplinks. My script launch MacVim with specified servername, the launched instance will be reuse if I execute the script again. Here it is (I have multiple ones generated by another script):
#!/bin/bash
# Required parameters:
# @raycast.schemaVersion 1
# @raycast.title Vim Launch
# @raycast.mode silent
# Optional parameters:
# @raycast.icon ✅
# @raycast.packageName vim-launch
# @raycast.argument1 { "type": "text", "placeholder": "file path", "optional": true }
# @raycast.argument2 { "type": "text", "placeholder": "line number", "optional": true }
# Documentation:
# @raycast.description Open vim startify session
export PATH=/Applications/MacVim.app/Contents/bin:$PATH
open_file()
{
if [[ -n $1 ]]; then
mvim --servername THE_SERVER_NAME --remote-send "<c-w>:tabedit $1<CR>"
fi
if [[ -n $2 ]]; then
mvim --servername THE_SERVER_NAME --remote-send "$2G"
fi
}
SERVERS=`mvim --serverlist | grep -i THE_SERVER_NAME | awk '{print tolower($0)}'`
for server in $SERVERS; do
if [[ $server == "THE_SERVER_NAME" ]];
then
osascript >/dev/null <<END
tell application "System Events" to tell process "MacVim"
set frontmost to true
windows where title ends with "THE_SERVER_NAME"
if result is not {} then perform action "AXRaise" of item 1 of result
end tell
END
open_file $1 $2
exit 0
fi
done
LANG=en_US.UTF-8 mvim --servername THE_SERVER_NAME +SLoad\ THE_SERVER_NAME >/dev/null 2>&1
# wait for server registration
sleep 1
open_file $1 $2
With this script, I replace mvim:// url with Raycast's deeplink:
raycast://script-commands/vim-launch?arguments={path}&arguments={line}
It's fixed! However it would be better to have native support in MacVim.
I would suggestion to add feature to detect the instance I want to open file with (like if the opening file path is in the working directory of an instance, the closest one), or add another parameter to specified the instance.
Thanks!
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
L’issue cita la gestione degli URL mvim:// di MacVim e la selezione dell’istanza/server, ma non indica file sorgente né test. Inizia individuando il punto di ingresso dell’URL e la logica che sceglie un’istanza MacVim esistente. Il lavoro è completo quando un file non aperto può riutilizzare l’istanza esistente appropriata, con una copertura per i casi segnalati a.js, b.js e c.js.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- bash, macos, vim
- Ambito
- desktop
- Tipo di issue
- Funzionalità
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 30/100