Xcode - 在外部编辑器中快速打开当前文件

时间:2012-09-06 13:16:13

标签: xcode xcode4

是否可以设置键盘快捷键(或者可能在某处添加一些菜单项)以在外部编辑器中打开当前编辑的文件?

(显然我可以[(右键单击文件树→在Finder中显示)/(右键单击窗口标题→选择包含目录)]→右键单击文件→打开方式→“应用程序” - 但步骤太多了。)

4 个答案:

答案 0 :(得分:9)

嗯,我找到了。

  1. 启动Automator.app。
  2. 选择“服务”。
  3. 拖放“运行AppleScript”到工作流程。
  4. 将“service receive”设置为“no input”,应用程序为Xcode。
  5. 粘贴此代码(将MacVim替换为您的编辑器)

    tell application "Xcode"
        set current_document to last source document
        set current_document_path to path of current_document
    end tell
    
    tell application "MacVim"
        activate
        open current_document_path
    end tell
    
  6. 保存工作流程。

  7. 在系统偏好设置→键盘→键盘快捷键→服务→常规中,指定快捷方式。
  8. 你已经完成了!
  9. 我从这个项目中借用了AppleScript代码:Uncrustify Automator Services for Xcode 4

答案 1 :(得分:3)

更好的解决方案是直接在键盘首选项面板中添加键盘快捷键:

  1. 打开“系统偏好设置”→“键盘”→“键盘快捷键”→“应用程序快捷方式”
  2. 点击“+”加号
  3. 选择“XCode”作为应用程序,并在菜单标题
  4. 中键入“使用外部编辑器打开”
  5. 设置你的shourcut(我正在使用⇧^E)

答案 2 :(得分:1)

因为我使用标签I was eager作为无法从第一个标签打开文档的解决方案。我ended up有以下内容:

注意:如果打开了助理编辑器,则无论哪个编辑器处于活动状态,都会打开标准编辑器(左侧)中的文件,但对我而言,它比第一个选项卡更好。

on run {input, parameters}

    set current_document_path to ""

    tell application "Xcode"
        set last_word_in_main_window to (word -1 of (get name of window 1))
        if (last_word_in_main_window is "Edited") then
            display notification "Please save the current document and try again"
            -- eventually we could automatically save the document when this becomes annoying
        else
            set current_document to document 1 whose name ends with last_word_in_main_window
            set current_document_path to path of current_document
        end if
    end tell

    tell application "MacVim"
        if (current_document_path is not "") then
            activate
            open current_document_path
        end if
    end tell

    return input
end run

答案 3 :(得分:0)

我真的很喜欢Fjölnir所做的解决方案,所以要扩展如何做到这一点。

  1. 选择菜单:“Xcode” - > “预置...”
  2. 单击“首选项”窗口中的“键绑定”选项卡
  3. 在“过滤器”搜索框中输入External
  4. 双击“使用外部编辑器打开(文件菜单)”命令旁边的“密钥”列。
  5. keybinding preferences

    如果您正在使用MacVim,则可以通过将外部编辑器配置为在最后一个窗口关闭后保持运行来缩短外部编辑器的加载时间。

    1. 选择菜单:“MacVim” - > “预置...”
    2. 在“常规”标签中将“最后一个窗口关闭后”设置为“隐藏MacVim”
    3. MacVim settings

      现在,当我按下⌥E窗口弹出窗口时,我进行了更改:q,然后焦点返回Xcode。

相关问题