Rate this post
 *tips.txt* For Vim version 5.4. Last change: 1999 Jul 20 VIM REFERENCE MANUAL by Bram Moolenaar Tips and ideas for using Vim *tips* Editing C programs |C-editing|
Finding where identifiers are used |ident-search|
Editing local HTML files (WWW) |html-editing|
Editing paragraphs without a line break |edit-no-break|
Switching screens in an xterm |xterm-screens|
Scrolling in Insert mode |scroll-insert|
Smooth scrolling |scroll-smooth|
Correcting common typing mistakes |type-mistakes|
Counting words, lines, etc. |count-items|
Renaming files |rename-files|
Speeding up external commands |speed-up|
Useful mappings |useful-mappings|
Compressing the help files |gzip-helpfile|
Executing shell commands in a window |shell-window|
Using  notation in autocommands |autocmd-| ============================================================================== Editing C programs *C-editing* There are quite a few features in Vim to help you edit C program files. Here
is an overview with tags to jump to: |C-indenting| Automatically set the indent of a line while typing text.
|=| Re-indent a few lines.
|format-comments|     Format comments. |:checkpath| Show all recursively included files.
|[i| Search for identifier under cursor in current and included files.
|[_CTRL-I| Jump to match for "[i"
|[I| List all lines in current and included files where identifier under the cursor matches.
|[d| Search for define under cursor in current and included files. |CTRL-]| Jump to tag under cursor (e.g., definition of a function).
|CTRL-T| Jump back to before a CTRL-] command.
|:tselect| Select one tag out of a list of matching tags. |gd| Go to Declaration of local variable under cursor.
|gD| Go to Declaration of global variable under cursor. |gf| Go to file name under the cursor. |%| Go to matching (), {}, [], /* */, #if, #else, #endif.
|[/| Go to previous start of comment.
|]/| Go to next end of comment.
|[#| Go back to unclosed #if, #ifdef, or #else.
|]#| Go forward to unclosed #else or #endif.
|[(| Go back to unclosed '('
|])| Go forward to unclosed ')'
|[{| Go back to unclosed '{'
|]}| Go forward to unclosed '}' |v_ab| Select "a block" from "[(" to "])", including braces
|v_ib| Select "inner block" from "[(" to "])"
|v_aB| Select "a block" from "[{" to "]}", including brackets
|v_iB| Select "inner block" from "[{" to "]}" ============================================================================== Finding where identifiers are used *ident-search* You probably already know that |tags| can be used to jump to the place where a
function or variable is defined. But sometimes you wish you could jump to all
the places where a function or variable is being used. This is possible in
two ways:
1. Using "grep" and quickfix commands. This should work on most Unix systems, but can be slow (it reads all files) and only searches in one directory.
2. Using ID utils. This is fast and works in multiple directories. It uses a database to store locations. You will need some additional programs for this to work. And you need to keep the database up to date. 1. Using grep. Add one long line to your .vimrc:
 map _g :let efsave=&eflet &ef=tempname()exe ':!grep -n -w "" *.[cChH] *.cc *.cpp *.txt >'.&ef:cf:exe ":!rm ".&ef:let &ef=efsaveunlet efsave:cc NOTE: This requires that the '>> ============================================================================== Switching screens in an xterm *xterm-screens* *xterm-save-screen* (From comp.editors, by Juergen Weigert, in reply to a question) :> Another question is that after exiting vim, the screen is left as it
:> was, i.e. the contents of the file I was viewing (editting) was left on
:> the screen. The output from my previous like "ls" were lost,
:> ie. no longer in the scrolling buffer. I know that there is a way to
:> restore the screen after exiting vim or other vi like editors,
:> I just don't know how. Helps are appreciated. Thanks.
:I imagine someone else can answer this. I assume though that vim and vi do
:the same thing as each other for a given xterm setup. They not necessarily do the same thing, as this may be a termcap vs.
terminfo problem. You should be aware that there are two databases for
describing attributes of a particular type of terminal: termcap and
terminfo. This can cause differences when the entries differ AND when of
the programs in question one uses terminfo and the other uses termcap
(also see |+terminfo|). In your particular problem, you are looking for the control sequences
^[[?47h and ^[[?47l. These switch between xterms alternate and main screen
buffer. As a quick workaround a command sequence like
     echo -n "^[[?47h"; vim ... ; echo -n "^[[?47l"
may do what you want. (My notation ^[ means the ESC character, further down
you'll see that the databases use \E instead). On startup, vim echoes the value of the termcap variable ti (terminfo:
smcup) to the terminal. When exiting, it echoes te (terminfo: rmcup). Thus
these two variables are the correct place where the above mentioned control
sequences should go. Compare your xterm termcap entry (found in /etc/termcap) with your xterm
terminfo entry (retrieved with /usr/5bin/infocmp -C xterm). Both should
contain entries similar to:
     :te=\E[2J\E[?47l\E8:ti=\E7\E[?47h: PS: If you find any difference, someone (your sysadmin?) should better check the complete termcap and terminfo database for consistency. NOTE 1: If you recompile Vim with SAVE_XTERM_SCREEN defined in feature.h, the
builtin xterm will include the mentioned "te" and "ti" entries. NOTE 2: If you want to disable the screen switching, and you don't want to
change your termcap, you can add these lines to your .vimrc:
     :set t_ti= t_te= ============================================================================== Scrolling in Insert mode *scroll-insert* If you are in insert mode and you want to see something that is just off the
screen, you can use CTRL-X CTRL-E and CTRL-X CTRL-Y to scroll the screen. |i_CTRL-X_CTRL-E| To make this easier, you could use these mappings:
(Type this literally, make sure the '