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. JavaScript语言基础知识1

    我们想知道什么JavaScript.首先,我们必须知道JavaScript有什么特点? JavaScript究竟是什么?它是一种基于对象而且具有安全性的脚本语言,对.它是脚本语言.所以它有下面特点: ...

  2. The Swift Programming Language-官方教程精译Swift(3)基本运算符

    运算符是检查, 改变, 合并值的特殊符号或短语. 例如, 加号 + 把计算两个数的和(如 let i = 1 + 2). 复杂些的运行算包括逻辑与&&(如 if enteredDoor ...

  3. windows系统下c语言暂停程序

    原文:windows系统下c语言暂停程序 windows系统下,很多C语言初学者的调试时,往往没看到结果程序就退出了,据我所知的方法主要有以下几种 方法一: #include int main() { ...

  4. JAVA学习第三十四课 (经常使用对象API)—List集合及其子类特点

    整个集合框架中最经常使用的就是List(列表)和Set(集) 一.List集合 && Set的特点 Collection的子接口: 1.List:有序(存入和取出的顺序一致),元素都有 ...

  5. apache启动报错:the requested operation has failed解决办法

    原因一:80端口占用 例如IIS,另外就是迅雷.我的apache服务器就是被迅雷害得无法启用! 原因二:软件冲突 装了某些软件会使apache无法启动如Dr.com 你打开网络连接->TcpIp ...

  6. APP-随身听

    简单到复杂听你的专属音响界,听金融.听物业,听新闻和其他节目专辑,简要介绍了新的音频应用,给你不一样的聆听体验.还记得老歌做?这里有.您留声机的一部分!很简单的音频应用,随时随地与此应用程序来听你的私 ...

  7. GitHub上整理

    GitHub上整理 技术站点 Hacker News:非常棒的针对编程的链接聚合网站 Programming reddit:同上 MSDN:微软相关的官方技术集中地,主要是文档类 infoq:企业级应 ...

  8. c#分部类型详解

    一.先看代码来理解 代码一 class ClassA { void A(){;} void B(){;} } 代码二 partial class ClassA { void A(){;} } part ...

  9. AJAX入门——工作原理

    同步和异步交互,了解互动 对于一个样本:一般B/S模式(同步)       AJAX技术(异步)        *  同步:       提交请求->等待server处理->处理完成返回 ...

  10. 批处理中set截取字符具体解释

    set截取字符具体解释  在批处理中,set的功能有点繁杂:设置变量.显示环境变量的名及值.做算术运算.等待用户的输入.字符串截取.替换字符串,是我们经常使用的命令之中的一个. 在字符串截取方面,新手 ...