Jump to content

Martin Chadwick

New Member
  • Posts

    1
  • Joined

  • Last visited

Posts posted by Martin Chadwick

  1. Hi .. I thought it might be interesting to extend the Vim+iTerm idea as follows:

     

    Refer to the automator scripts described here:
    https://blog.schembri.me/post/neovim-everywhere-on-macos/

     

    #1 'Edit in Vim'
    This automator takes text in and spits text out. In other words, you need to select some text to edit in vim, run the action, and the text will be replaced with whatever you saved in vim.

    (for reference - AS code attached below from the above URL).

     

    #2 'Write in NeoVim'

    This automator launches vim launch vim with the current context without requiring text to be selected.

    (for reference - see above URL).

     

    This solution neatly resolves the problem of integrating vim-style editing into Mail.app for long emails (as well as posts to forums like this!)

     

    I assume this needs a script-filter > osascript-AS workflow (separate from the 'custom-alfred-iterm-scripts' described earlier). However I'm not familiar enough with Alfred workflow AS coding to implement the input/output methods required. (I've had a look through Packal and this Forum for equivalent solutions.)

     

    Any assistance appreciated from others interested in these workflow ideas.

     

    Martin

    on run {input, parameters}
      set tempfile to do shell script "mktemp -t edit-in-vim"
    
      tell application "iTerm"
        create window with default profile
          tell the current window
            tell the current session
              write text "cat <<EOF > \"" & tempfile & "\"\n" & input & "\nEOF"
              write text "vim \"" & tempfile & "\""
    
              repeat while name contains "Shell" or name contains "vim"
                delay 0.5
              end repeat
    
              set content to do shell script "cat \"" & tempfile & "\""
            end tell
    
            close
          end tell
      end tell
    
      return content
    end run

     

     

     

     

×
×
  • Create New...