Sometimes we want to open another file in the same folder with current editing file, what we can do to avoid typing the whole path?

 
For better understanding, it's better to know the info showing in the table. (when making the table, i learned how to rotate a table in Excel)
 

 
Now let's see how to edit a file in the same folder with current document quickly and easily.
 
1. Edit directly
:edit %:p:h/<anotherfile.txt>
using Tab key to show the complete path.
 
%:p:h indicates the absolute folder path of current file.
 
2. Change current working directory

:lcd %:p:h or :cd %:p:h
:cd is to set the working directory for all windows; while :lcd only change the working directory for current window.
 
3. Key mapping
in .vimrc/_vimrc, map the keystrokes ,c to do that.
nnoremap ,c :cd %:p:h<CR>
 
4. Using a command
in .vimrc/_vimrc, define command CD to do that.
command CD cd %:p:h
 
The advantage of this way is that you can customize multi commands for different directories. (As well as key mapping)
e.g.
command WORK cd D:\Work
command GAME cd E:\Game
5. autocmd
if you want it changes the working directory to the file editing automatically, adding following content in your .vimrc/_vimrc file.
autocmd BufEnter * silent! lcd %:p:h
There is another cmd can be added in vimrc,
set autochdir
But it may cause conflict with some plug-ins.
 
6. Add file directory to Vim path
 
 
References:
 

Changing the working directory of VIM的更多相关文章

  1. 打造vim成类source insight

    一.Ubuntu14.04下配置 1.配置vimrc文件 输入:version课查看vimrc文件及位置: system vimrc file: "$VIM/vimrc" user ...

  2. vim编辑指令(转)

    跳跃指令 类似于游览器中的<前进><后退>按钮  CTRL-] -> 跟着link/tag转入 (follow link/tag)  CTRL-o -> 回到上一次 ...

  3. vim 设置 swap file, 防止 同一个文件同时被多次打开,而且有恢复的功效

    在.vimrc里加入:   set swapfile   即可以使能swap file, swapfile的名字一般是      .filename.swp    (如     .doc.txt.sw ...

  4. vim 常用快捷键 二[转]

    键盘移动 (Move) 一切都从键盘的移动k -> 上 upj -> 下 downh -> 左 leftl -> 右 rightz -> 重画屏幕,当前光标变成屏幕的第一 ...

  5. Vim插件之Command-T使用问题

    最近在使用vim插件CommandT时出现问题其实就是vim没有支持ruby,不过google之后找到了解决方法,老外的态度还是很让人敬佩的,度娘搜索的结果太让人呕心了.. 贴下,以后再次遇到解决. ...

  6. Visual Studio - File Properties (Build Action, Copy to Output Directory)

    Ref: MSDN (https://docs.microsoft.com/en-us/previous-versions/visualstudio/visual-studio-2010/0c6xyb ...

  7. vim 常用 NERDTree 快捷键

    ctrl + w + h 光标 focus 左侧树形目录 ctrl + w + l 光标 focus 右侧文件显示窗口 ctrl + w + w 光标自动在左右侧窗口切换 ctrl + w + r 移 ...

  8. 解决安装YouCompleteMe与Vim版本不兼容问题

    用vim 7.4.4版本装YouCompleMe的时候提示这样的信息: YouCompleteMe unavailable: requires Vim 7.4.1578+.明明版本比它要求的还高,居然 ...

  9. (转)vim 常用快捷键 二

    转自:http://www.cnblogs.com/wangkangluo1/archive/2012/04/12/2444952.html 键盘移动 (Move) 一切都从键盘的移动 k -> ...

随机推荐

  1. Linux_下安装MySQL

    linux下mysql 最新版安装图解教程 1.查看当前安装的linux版本 命令:lsb_release -a 如下图所示 通过上图中的数据可以看出安装的版本为RedHat5.4,所以我们需要下载R ...

  2. linux-ubuntu关闭防火墙

    SYNOPSIS iptables [-t table] {-A|-C|-D} chain rule-specification ip6tables [-t table] {-A|-C|-D} cha ...

  3. IOS SDK相机的详细解释/画廊(默认+他们的高清摄像头接口)

    原版的blog,转载请注明出处 blog.csdn.net/hello_hwc 前言: 新NSURLSession的UploadTask的,结果写那个Demo的时候想要写成拍照上传.然后就想到先写一个 ...

  4. centos5.8本地安装yum资源,安装软件包

    首先 [root@mode media]# cd /etc/yum.repos.d/ [root@mode yum.repos.d]# ll total 16 -rw-r--r-- 1 root ro ...

  5. OracleServiceORCL服务不见了怎么办

    用管理员身份运行命令提示符(CMD) 然后输入“oradim -new -sid orcl”即可

  6. cmd 跟踪路由

    cmd   命令   tracert  ip 地址 用 来 跟踪路由

  7. SALT 加密

    大家都知道,MD5加密是不可逆.但事实上,我们通常值的MD5算法.黑客的眼下破解率相对较高.也有非常多站点上干脆就提供批量解密MD5的服务,当然是收费的.http://www.xmd5.org.这里提 ...

  8. VMware Workstation 无法与 Windows XP \ Windows 7 \ Windows 8 进行共享文件夹。

    1.这是一个小Bug,做法很简单. ----①.如果安装了VMware Tools,先卸载VMware Tools,重启虚拟机,再安装VMware Tools,重启虚拟机,就行了. ----②.如果没 ...

  9. 纯CSS3打造七巧板

    原文:纯CSS3打造七巧板 最近项目上要制作一个七巧板,脑子里瞬间闪现,什么...七巧板不是小时候玩的吗... 七巧板的由来 先来个科普吧,是我在查资料过程中看到的,感觉很有意思. 宋朝有个叫黄伯思的 ...

  10. SQL点滴19—T-SQL中的透视和逆透视

    原文:SQL点滴19-T-SQL中的透视和逆透视 透视 今天抽一点时间来看看透视和逆透视语句,简单的说就是行列转换.假设一个销售表中存放着产品号,产品折扣,产品价格三个列,每一种产品号可能有多种折扣, ...