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. Web文件(图片)上传方法

    在开放Web应用程序的时候经常会遇到图片或者是文件上传的模块,这里就是该模块的实现的后台方法 上传图片方法 /// <summary> /// 功能:上传图片方法 /// </sum ...

  2. c/cpp中怎样切割字符串,相似于split的功能

    在python中,假设要求当前时间的unix时间戳,我特别喜欢这么用: import time timestr = time.time() timestamp = int(timestr.split( ...

  3. Linux C/C++计划Shell命令大杂烩(1)

    1, 请参见发行信息 cat /etc/issue 2, 查看内核版本号 uname -r 查看内核版本号 uname -p 查看处理器类型32bit/64bit uname -n 查看网络主机名(o ...

  4. python解析Yahoo的XML格式的天气预报,获取当天和近期几天的天气:

    下面是接口xml格式数据: <rss xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0" xmlns:geo=& ...

  5. JavaScript中,关于new的那些事

    这篇文章是自己对new学习过程中的一些理解,有不对的地方希望指出,接受组织的批评教育. 导火线,前段时间学习jQuery的时候,看到源码中有这样一段: jQuery = function(select ...

  6. 財智V6.0(完美破解序列号特别版)

    財智V6.0(完美破解序列号特别版)               財智V6.0(完美破解序列号特别版)   財智6是眼下唯一在中央台报道的.比較成熟的国产理財软件.能全面管理家庭的日常收入.消费.储蓄 ...

  7. Pointers to classes (From the note of my firend)

     Pointers to classes Objects can also be pointed to by pointers: Once declared, a class becomes a ...

  8. jQuery的ready方法实现原理分析

    jQuery中的ready方法实现了当页面加载完成后才执行的效果,但他并不是window.onload或者doucment.onload的封装,而是使用 标准W3C浏览器DOM隐藏api和IE浏览器缺 ...

  9. c# 播放器 支持所有格式

    原文:c# 播放器 支持所有格式 ---恢复内容开始--- 直接上代码 internal static class LibVlcAPI { internal struct PointerToArray ...

  10. ViewPaper实现轮播广告条

    使用V4包中的viewPaper组件自己定义轮播广告条效果. 实现viewpaper的滑动切换和定时自己主动切换效果. 上效果图 布局文件 <RelativeLayout xmlns:andro ...