(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 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: >
:inoremap <C-E> <C-X><C-E>
:inoremap <C-Y> <C-X><C-Y>
You then lose the ability to copy text from the line above/below the cursor
|i_CTRL-E|.
Also consider setting 'scrolloff' to a larger value, so that you can always see
some context around the cursor. If 'scrolloff' is bigger than half the window
height, the cursor will always be in the middle and the text is scrolled when
the cursor is moved up/down.
==============================================================================
Smooth scrolling *scroll-smooth*
If you like the scrolling to go a bit smoother, you can use these mappings: >
:map <C-U> <C-Y><C-Y><C-Y><C-Y><C-Y><C-Y><C-Y><C-Y><C-Y><C-Y><C-Y><C-Y><C-Y><C-Y><C-Y><C-Y>
:map <C-D> <C-E><C-E><C-E><C-E><C-E><C-E><C-E><C-E><C-E><C-E><C-E><C-E><C-E><C-E><C-E><C-E>
==============================================================================
Correcting common typing mistakes *type-mistakes*
When there are a few words that you keep on typing in the wrong way, make
abbreviations that correct them. For example: >
:ab teh the
:ab fro for
==============================================================================
Counting words, lines, etc. *count-items*
To count how often any pattern occurs in the current buffer use the substitute
command and add the 'n' flag to avoid the substitution. The reported number
of substitutions is the number of items. Examples: >
:%s/./&/gn characters
:%s/\i\+/&/gn words
:%s/^//n lines
:%s/the/&/gn "the" anywhere
:%s/\<the\>/&/gn "the" as a word
You might want to reset 'hlsearch' or do ":nohlsearch".
Add the 'e' flag if you don't want an error when there are no matches.
An alternative is using |v_g_CTRL-G| in Visual mode.
If you want to find matches in multiple files use |:vimgrep|.
*count-bytes*
If you want to count bytes, you can use this:
Visually select the characters (block is also possible)
Use "y" to yank the characters
Use the strlen() function: >
:echo strlen(@")
A line break is counted for one byte.
==============================================================================
Restoring the cursor position *restore-position*
Sometimes you want to write a mapping that makes a change somewhere in the
file and restores the cursor position, without scrolling the text. For
example, to change the date mark in a file: >
:map <F2> msHmtgg/Last [cC]hange:\s*/e+1<CR>"_D"=strftime("%Y %b %d")<CR>p'tzt`s
Breaking up saving the position:
ms store cursor position in the 's' mark
H go to the first line in the window
mt store this position in the 't' mark
Breaking up restoring the position:
't go to the line previously at the top of the window
zt scroll to move this line to the top of the window