vim-A

vim-A

 

软件版本:
  ubuntu10.04
  Linux version 2.6.32-42-generic
  VIM - Vi IMproved 7.2

目录:

  1. 简介
  2. 下载安装
  3. 使用
  4. 我所遇到的问题

1. 简介

  插件 A 的作用是提供一种快速的命令让我们在源码与头文件之间切换。

2. 下载安装

名称: A
下载地址:

http://www.vim.org/scripts/script.php?script_id=31

安装: 把下载下来的 a.vim 放到 $HOME/.vim/plugin 目录下。
帮助: :A switches to the header file corresponding to the current file being edited (or vise versa)
:AS splits and switches
:AV vertical splits and switches
:AT new tab and switches
:AN cycles through matches
:IH switches to file under cursor
:IHS splits and switches
:IHV vertical splits and switches
:IHT new tab and switches
:IHN cycles through matches
<Leader>ih switches to file under cursor
<Leader>is switches to the alternate file of file under cursor (e.g. on  <foo.h> switches to foo.cpp)
<Leader>ihn cycles through matches

3. 使用

  在普通模式下输入一下命令即可在源码与头文件之间进行切换。

  :A 在新 buffer 中切换;
  :AS 水平分割式切换;
  :AV 垂直分割式切换;
  :AT 新建页标签,然后切换;
  :AN 如果在指定目录下有多个同名的 c/h 文件,循环切换;』
  :IH 创建新 buffer 切换到光标下的文件;
  :IHS 同上,且创建水平窗口;
  :IHV 同 :IH,且创建垂直窗口;
  :IHT 同 :IH,切换到新建页标签;
  :IHN 同 :IH,循环切换;
  <Leader>ih 同 :IH;
  <Leader>is 功能相当于是 :IHS + :A 。效果是切换到光标下的头文件对应的源文件中。
  <Leader>ihn 同 :IHN;

  我在用这个插件的时候有一个疑惑,它是怎么搜索我的头和源文件?为此我做了一些的尝试,发现它有时候就能匹配到对应的头文件,但换成其它目录下的文件又不行。查看 a.vim 后找到 g:alternateSearchPath 这个变量,它用来搜索指定搜索目录,默认包括:../source;../src;../include;../inc。巧合的是我的目录结构中又刚好符合这个要求。现在我们可以根据各自的需要在 .vimrc 中通过 g:alternateSearchPath变量控制插件 A 的搜索目录。默认的设置为:

let g:alternateSearchPath = 'sfr:../source,sfr:../src,sfr:../include,sfr:../inc'

   要注意的是,每个目录都必须用 “str: ” 开头;目录间用逗号分割。

4. 我所遇到的问题

  我遇到一个问题,就是 <Leader>is 这个按键已经被 c-support 使用了,原因是我将 g:C_MapLeader 与 mapleader 都设置为“;”。每次启动 [g]vim 都会提示:

Mapping already in use: "<LocalLeader>is", mode "n"
Mapping already in use: "<LocalLeader>is", mode "i"

  所以我将 <Leader>is 改为 <Leader>ihsa 。

posted @ 2012-09-18 15:21  Eddy_He  阅读(1126)  评论(0编辑  收藏  举报