*tips.txt* Nvim
VIM REFERENCE MANUAL by Bram Moolenaar
Tips and ideas for using Vim *tips*
These are just a few that we thought would be helpful for many users.
You can find many more tips on the wiki. The URL can be found on
https://www.vim.org
Don't forget to browse the user manual, it also contains lots of useful tips
|usr_toc.txt|.
Type |gO| to see the table of contents.
==============================================================================
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:
|usr_29.txt| Moving through programs chapter in the user manual.
|usr_30.txt| Editing programs chapter in the user manual.
|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 the |:grep| command. 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.
Using the GNU id-tools:
What you need:
- The GNU id-tools installed (mkid is needed to create ID and lid is needed to
use the macros).
- An identifier database file called "ID" in the current directory. You can
create it with the shell command "mkid file1 file2 ..".
Put this in your |init.vim|: >
map _u :call ID_search()<Bar>execute "/\\<" .. g:word .. "\\>"<CR>
map _n :n<Bar>execute "/\\<" .. g:word .. "\\>"<CR>
function! ID_search()
let g:word = expand("<cword>")
let x = system("lid --key=none " .. g:word)
let x = substitute(x, "\n", " ", "g")
execute "next " .. x
endfun
To use it, place the cursor on a word, type "_u" and vim will load the file
that contains the word. Search for the next occurrence of the word in the
same file with "n". Go to the next file with "_n".
This has been tested with id-utils-3.2 (which is the name of the id-tools
archive file on your closest gnu-ftp-mirror).
[the idea for this comes from Andreas Kutschera]
==============================================================================
Scrolling