Search don't scroll - Vim tip 2 of 3
New day and a new Vim post. This time it's all about how to find what you are looking for!
Requirements:
In this post we'll look on:
Text search in a directoryA lot of times you would like to find an occurrence of a pattern in some files. And grep is PERFECT for that. I prefer to use GNU grep. Vim 7 has built in grep, but it's much slower than GNU Grep. This is very simple, you basically do this on the command line: :grep -R "wiki_filter" ~/Desktop/skeletonz_svn/ This will do a recursive search for wiki_filter in ~/Desktop/skeletonz_svn/. You could do the same in a terminal... But in the terminal you can't visit the files in a neat way. Vim will parse the results and remember them. You can then browse them in a quickfix window. The commandsThere are some quickfix commands that you'll need to use in order to browse the grep results:
The mappingsOf course, you'll want mappings for those. Here are mine: map <leader>n :cn<cr> map <leader>p :cp<cr> map <leader>c :botright cw 10<cr> Experiment :) Moving in a document without scrollingThe way I move in a document is by search! Mostly I am looking for something, it could be a method, a variable or some specific text. How to searchI hope you know how to do a search, if you don't here are the two most important normal-mode keys:
Those keys are "ok", but you can be a lot faster by having these maps: map <space> / map <c-space> ? I.e. pressing SPACE in normal mode will bring me in search mode. OptionsThese options are essential and should be placed in your .vimrc: set ignorecase set incsearch set hlsearch Explanation:
Moving around on a lineVim can search for you on a line. Trust me: it's very efficient and you should use this. An exampleLet's say that we are on current line and # is where the cursor is placed: def #checkLoginInfo(self, username, password): Now we would like to add a new parameter called time. Here is what I would press:
Efficient, yes sir! Normal mode keys to rememberHere are the keys to remember:
10. Aug 2006
•
VIM Editor
|
|