Opening a directory in vim

前端 未结 5 2068
清酒与你
清酒与你 2021-02-12 12:22

I\'m a mac user giving vim a serious try. Most of the GUI editors I\'m used to allow me to open a directory as a \"project\" by executing a command like:

5条回答
  •  旧时难觅i
    2021-02-12 13:12

    Thanks to @sehe's suggestions, I came up with this. Not sure if it's the best solution, but it seems to work.

    #!/bin/bash
    
    if [ "$#" -eq 1 ];then # is there a path argument?
      if test -d $1;then # open directory in vim
        vim $1 +':cd %'
      else # open file in vim
        vim $1 +':cd %:h'
      fi
    else # no path argument, just open vim
      vim 
    fi
    

提交回复
热议问题