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. DYNAMICRESOLUTION | NODYNAMICRESOLUTION

    有时候开启OGG进程的时候较慢,可能是由于须要同步的表太多,OGG在开启进程之前会将须要同步的表建立一个记录而且存入到磁盘中,这样就须要耗费大量的时间.OGG同一时候也提供了DYNAMICRESOLU ...

  2. 【C++实现】HeadFirst策略模式设计模式

    策略模式定义了算法家族.分别封装起来.让它们之间能够相互替换,此模式让算法的变化独立于使用算法的客户. Head First设计模式中介绍策略模式时以Duck类作为样例.当中用flyBehavior和 ...

  3. 【百度地图API】批量地址解析与批量反地址解析(带商圈数据)

    原文:[百度地图API]批量地址解析与批量反地址解析(带商圈数据) 摘要:因为地址解析的webserives方式还没有开通,所以先用JS版本的地址解析接口来批量获取地址解析数据吧,同时还能得到商圈的数 ...

  4. TRIZ系列-创新原理-28-替代机械系统原理

    替代机械系统原理的详细描写叙述例如以下:1)用光.声.热.嗅觉系统替代机械系统:2)用电.磁或电磁场来与物体交互作用:3)用移动场替代精巧场,用随时间变化的场替代固定场,用结构化的场替代随机场:4)使 ...

  5. Cocos2d-xvision3.0加载失败,和,Vs2012环境搭建

    1.安装好VS2012,下载Cocos2d-x3.0 双击击win32 sln运行VS2012 如果加载失败点击程序运行,输入devenv.exe /resetuserdata 回车,然后再进入VS, ...

  6. 引擎介绍 - REngine

    引擎介绍 - REngine 规则引擎 规则引擎由推理引擎发展而来,是一种嵌入在应用程序中的组件,实现了将业务决策从应用程序代码中分离出来,并使用预定义的语义模块编写业务决策.接受数据输入,解释业务规 ...

  7. Android Material Design带UI变化

    谷歌Matias Duarte称,"Material Design是漂亮和大胆的.由于干净的排版和布局简单且easy理解.内容才是焦点. 谷歌I/O 014开发人员大会上宣布全新的设计语言& ...

  8. JS分析URL字符串,取得参数名,AJAX传参请求代码示例

    //当前页面URL中参数分析函数,正则校验 function getQueryString(name) { var reg = new RegExp("(^|&)" + n ...

  9. Windows下Oracle不显示中文[已解决]

    跟着视频学习,然后讲到插入的时候有中文性别,就GG了,该显示中文的时候都是问号,觉得应该是编码的问题. 于是上网找了下,测试可行,方法如下 1,查询Oracle编码的语句: [sql] SELECT ...

  10. Zend Server的WebAPI焦点:异步操作

    Zend Server作为Web应用服务器,在使用时,涉及连接的基本步骤,其中包括许多可用的WebAPI行为. WebAPI提供一些需要时间才能完成的操作,包括很复杂的或依靠外部实体(如远程服务器)才 ...