words_tools.vim


Ⅰ. 插件描述

Alternatives to expand(

Ⅱ. 基本信息

创建日期:  2001-11-13
使用用户:  1
Github星:  1
插件作者:  Luc Hermitte

Ⅲ. 安装方法

使用Vundle管理器安装

在你的.vimrc下添加:
Plugin '/words-tools-vim'
… 然后在Vim中运行以下命令:
:source %
:PluginInstall

对于Vundle版本 < 0.10.2,请用上面的Bundle替换Plugin。

使用NeoBundle管理器安装

在你的.vimrc下添加:
NeoBundle '/words-tools-vim'
… 然后在Vim中运行以下命令:
:source %
:NeoBundleInstall

使用VimPlug管理器安装

在你的.vimrc下添加:
Plug '/words-tools-vim'
… 然后在Vim中运行以下命令:
:source %
:PlugInstall

使用Pathogen管理器安装

在终端中运行以下命令:
cd ~/.vim/bundle
git clone https://github.com/vim-scripts/words_tools.vim

Ⅳ. 文档说明

A tip would have been more accurate regarding what I am presenting here. But as some functions proposed are needed by another script of mine, here is a script file containing the definitions of three functions that can be used instead of expand("<cword>").

expand("<cword>") is a nice feature in VIM, but it is not very helpful when we have to deal with automatic completion -- you know : when you hit <tab> within VIM's command line or your favourite shell. Indeed, "<cword>" refers to the word under/after the cursor, while we need the word under/before the cursor.

So, here is three functions :

  • GetPreviousWord() that returns the word preceding the cursor ; the word is either truncated at the cursor's position or completed by as many spaces as needed to reach this position. I call a word, a sequence of keyword characters ('k', see :h isk).
      It is handy, in C programming, to test what precedes the cursor when we hit '(', and then expand C control-structures (for, if, else, elif, switch, etc.) to anything desired.
  • GetCurrentWord() returns the word which is either stricly under the cursor or just before -- if the cursor is preceded by a space, an empty string is returned. Here, a word is a sequence of non white space characters : 'S' -- in order to expand regular expressions.
      Cf. http://vim.sourceforge.net/scripts/script.php?script_id=46 v2.2
  • GetNearestWord() returns the word ('S') either under, just before or just after the cursor.

You can take a look at a table showing the different returned values by this functions in equivalent contexts : http://hermitte.free.fr/vim/general.php3#expl_words_tools

As I said before, a tip would have been more appropriate. These functions are just examples of want could be done on this topic. They fulfill some specific needs I had.

添加新评论