Vim on Mac OS X terminal

06
2014-04
  • mnemonicj

    I'm on Mac OS X 10.9 using Vim 7.4 and I'm looking to find a way to map the key combination behavior "option + delete" to delete a word backwards. Currently, this works on every app in the OS, except when running Vim in the terminal. "control + W" works in Vim and some apps but not in all of the ones I use.

    Any help?

    Regards.

  • Answers
  • echristopherson

    This works for me, but I use iTerm2:

    inoremap <A-Backspace> <C-w>
    cnoremap <A-Backspace> <C-w>
    

    I have a note near that in my config file that says Terminal doesn't allow you to map delete combinations; but since I haven't used the default Terminal in quite a long time I don't know if that's true anymore.

  • Yitzchak

    Check out the vim wiki page on mapping to learn more than you ever wanted to know about how to map keys in vim. To preserve your key mappings, open (or create) a .vimrc file in your home directory.


  • Related Question

    osx - Mac OS X: how to open vim in terminal when double click on a file
  • sixtyfootersdude

    I have defined my own custom vim file type with highlighting etc. I would like to open it using the terminal based vim when I double click on it. I am using mac os x. Any pointers on how to start on this?


  • Related Answers
  • ghoppe

    Create an Automator Application to run the following applescript:

    on run {input}
       set the_path to POSIX path of input
       set cmd to "vim " & quoted form of the_path
       tell application "System Events" to set terminalIsRunning to exists application process "Terminal"
       tell application "Terminal"
          activate
          if terminalIsRunning is true then
             do script with command cmd
          else
             do script with command cmd in window 1
          end if
       end tell
    end run
    

    Save the automator application. (eg. name it Vim Launcher)

    Right click (or control-click) on your custom vim-type file (eg. use .vim as the extension) and under Open With… choose the bottom option Other… and find your Automator Application (eg. Vim Launcher), double-click it.

    Boom.

  • Josh K

    From the five or so minutes I spent playing with it to see if it would I couldn't find a built -in option to do so.

    However, you can probably write a simple Applescript that will take the files absolute path and then run vim {path} in a bash shell.

  • ggustafsson
    set the_path to POSIX path of input
       set cmd to "vim " & quoted form of the_path & "; exit"
       tell application "System Events" to set terminalIsRunning to exists application process "Terminal"
       tell application "Terminal"
          if terminalIsRunning is true then
             do script with command cmd
          else
             do script with command cmd in window 1
          end if
          activate
       end tell
    end run
    

    I use this AppleScript instead. It activates Terminal.app after (not before!) execution to stop things from acting odd when using Spaces. It also closes the window after Vim exits. Just set Terminal.app to close after clean exits.