"***************************************************************************** "** Name: greputil.vim - simplifies usage of 'grep' ** "** ** "** Type: global VIM plugin ** "** ** "** Author: Christian Habermann ** "** christian (at) habermann-net (point) de ** "** ** "** Copyright: (c) 2002 by Christian Habermann ** "** ** "** License: GNU General Public License 2 (GPL 2) or later ** "** ** "** This program is free software; you can redistribute it ** "** and/or modify it under the terms of the GNU General Public ** "** License as published by the Free Software Foundation; either ** "** version 2 of the License, or (at your option) any later ** "** version. ** "** ** "** This program is distributed in the hope that it will be ** "** useful, but WITHOUT ANY WARRANTY; without even the implied ** "** warrenty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ** "** PURPOSE. ** "** See the GNU General Public License for more details. ** "** ** "** Version: 1.0.0 ** "** tested under Linux and Win32, VIM 6.1 ** "** ** "** History: 1.0.0; 2. Dec. 2002: ** "** same as 0.2.0 but first release ** "** ** "** 0.2.0; 1. Dec. 2002: ** "** - documentation rewritten ** "** - prefix of plugin changed from gut_ to gru_ ** "** - minor renamings in code ** "** - key-mappings are now configurable ** "** - g:gru_grepOptions added ** "** - g:gru_flagUseNavi added ** "** - g:gru_flagUseHistoryNavi added ** "** not released ** "** ** "** 0.1.2; 3. Nov. 2002: ** "** - mapping added to prompt for search string ga ** "** (means (g)rep (a)sk) ** "** - search pattern is now customizable ** "** (see g:gut_searchPattern) ** "** not released ** "** ** "** 0.1.1; 17. Jan. 2002: ** "** added prompt for search string if there is no word ** "** under cursor ** "** not released ** "** ** "** 0.1.0; 16. Jan. 2002: ** "** initial version, not released ** "** ** "***************************************************************************** "** Description: ** "** This script simplifies usage of the :grep-command and the navigation ** "** through search results and search history. ** "** ** "** To start search for the word under the cursor or for the visually ** "** selected text press gr. If there is no word under the cursor, ** "** you will be prompted for a search-string. To be prompted for a ** "** search-string anyway pressing ga will do it. ** "** ** "** Memory aid: gr: (g)(r)ep ** "** ga: (g)rep (a)sk for string ** "** ** "** Note: by default is \, so press \gr, \ga to start search ** "** ** "** Files will be searched in the actual directory. The file pattern ** "** can be defined by a global variable, it's default is ** "** "*.c *.h *.cpp *.hpp" (yes, this script is primarily for ** "** programmers :-) ) ** "** ** "** To show search-results open quickfix-window with :copen. ** "** To navigate through the occurrences press or . ** "** To bring back results of older or newer search-sessions press ** "** or . ** "** ** "** Summary: ** "** gr: search word under cursor or visually selected text ** "** in all files selected by search pattern in the ** "** current directory ** "** ga: prompt for search string and search in all files ** "** selected by search pattern in the current directory ** "** : goto next occurrence ** "** : goto previous occurence ** "** : open newer search-session ** "** : open older search-session ** "** use :copen to show list of search results ** "** ** "** This script uses VIM's quickfix window to show search results. It's ** "** the same window which is used to view compilation-errors after a ** "** ':make' command. This means, if you have already mappings to navigate ** "** through the list of compilation-errors you don't need additional ** "** mappings for the navigation through search results - just do it like ** "** for compiling... ** "** Therefore it's possible to disable the navigation-feature of GrepUtil ** "** (see Configuration section for more details; g:gru_flagUseNavi, ** "** g:gru_useHistoryNavi). ** "** ** "** ** "** Installation: ** "** To use this script copy it into your local plugin-directory ** "** (Unix: ~/.vim/plugin). After starting VIM this script is sourced ** "** automatically. ** "** By default 'grep' is used for searching, so you need it too. It's ** "** available for close to all systems. Look for ports, if it is not ** "** installed already. ** "** ** "** ** "** Configuration: ** "** Make some settings in your .vimrc file to configure this script: ** "** - gru_filePattern: ** "** defines which files should be searched ** "** Default is "*.c *.h *.cpp *.hpp" ** "** e.g. let g:gru_filePattern = "*.c *.h *.cpp *.hpp" ** "** ** "** - g:gru_grepOptions: ** "** defines additional options of 'grep' ** "** Default is "" (none) ** "** e.g. let g:gru_grepOptions = "-r" ** "** ** "** - g:gru_flagUseNavi ** "** If you don't want to let GrepUtil make mappings for navigation ** "** through search results, set this to 0 ** "** (useful if you have already mappings to do this for your ** "** compilation-errors - they will work for GrepUtil too). ** "** Default is 1 (active) ** "** e.g. let g:gru_flagUseNavi = 0 ** "** ** "** - g:gru_flagUseHistoryNavi ** "** If you don't want to let GrepUtil make mappings for navigation ** "** through history of search sessions, set this to 0 ** "** (useful if you have already mappings to do this for your ** "** compilation-errors - they will work for GrepUtil too). ** "** Default is 1 (active) ** "** e.g. let g:gru_flagUseHistoryNavi = 0 ** "** ** "** - 'grepprg', 'grepformat' ** "** To configure grep, use these VIM-variables. ** "** See ** "** :help 'grepprg' ** "** :help 'grepformat' ** "** for further information. ** "** ** "** ** "** Known limitations: ** "** - GrepUtil can't handle very well pattern containing double quotes. ** "** The only way it works is to enter the string manually in prompt- ** "** mode (ga) and set a '\' before each double quote. ** "** - Metacharacters of regular expressions introduced by a '\' ** "** (e.g. GNU grep's \(...\), \| ) will not work in visual mode. Do ** "** it in prompt-mode instead (ga). ** "** - VIM expands the search pattern like when used in a command-line. ** "** E.g. searching for "#include" will not do what you expect since ** "** '#' is expanded to the alternate buffer name. ** "** ** "** Known bugs: ** "** none ** "** ** "** Happy vimming.... ** "***************************************************************************** " allow user to avoid loading this plugin and prevent loading twice if exists ("loaded_greputil") finish endif let loaded_greputil = 1 "***************************************************************************** "************************** C O N F I G U R A T I O N ************************ "***************************************************************************** if !exists('g:gru_filePattern') " has user set file pattern? let g:gru_filePattern = "*.c *.h *.cpp *.hpp" " no => take default endif if !exists('g:gru_grepOptions') " has user set additional grep-options? let g:gru_grepOptions = "" " no => take default endif if !exists('g:gru_flagUseNavi') " default: make mapping for navigation let g:gru_flagUseNavi = 1 " through search results endif if !exists('g:gru_flagUseHistoryNavi') " default: make mapping for navigation let g:gru_flagUseHistoryNavi = 1 " through history of search sessions endif "*** the mappings *** " mappings to grep if !hasmapto('GRU_GrepNormal') nmap gr GRU_GrepNormal endif if !hasmapto('GRU_GrepVisual') vmap gr GRU_GrepVisual endif if !hasmapto('GRU_GrepAsk') map ga GRU_GrepAsk endif " assign mappings to functions for grepping nmap