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
`s jump to the original position of the cursor
For something more advanced see |winsaveview()| and |winrestview()|.
==============================================================================
Renaming files *rename-files*
Say I have a directory with the following files in them (directory picked at
random :-):
buffer.c
charset.c
digraph.c
...
and I want to rename `*.c` `*.bla`. I'd do it like this: >
$ vim
:r !ls *.c
:%s/\(.*\).c/mv & \1.bla
:w !sh
:q!
==============================================================================
Change a name in multiple files *change-name*
Example for using a script file to change a name in several files:
Create a file "subs.vim" containing substitute commands and a :update
command: >
:%s/Jones/Smith/g
:%s/Allen/Peter/g
:update
<
Execute Vim on all files you want to change, and source the script for
each argument: >
vim *.let
argdo source subs.vim
See |:argdo|.
==============================================================================
Speeding up external commands *speed-up*
In some situations, execution of an external command can be very slow. This
can also slow down wildcard expansion on Unix. Here are a few suggestions to
increase the speed.
If your .cshrc (or other file, depending on the shell used) is very long, you
should separate it into a section for interactive use and a section for
non-interactive use (often called secondary shells). When you execute a
command from Vim like ":!ls", you do not need the interactive things (for
example, setting the prompt). Put the stuff that is not needed after these
lines: >
if ($?prompt == 0) then
exit 0
endif
Another way is to include the "-f" flag in the 'shell' option, e.g.: >
:set shell=csh\ -f
(the backslash is needed to include the space in the option).
This will make csh completely skip the use of the .cshrc file. This may cause
some things to stop working though.
==============================================================================
Useful mappings *useful-mappings*
Here are a few mappings that some people like to use.
*map-backtick* >
:map ' `
Make the single quote work like a backtick. Puts the cursor on the column of
a mark, instead of going to the first non-blank character in the line.
*emacs-keys*
For Emacs-style editing on the command-line: >
" start of line
:cnoremap <C-A> <Home>
" back one character
:cnoremap <C-B> <Left>
" delete character under cursor
:cnoremap <C-D> <Del>
" end of line
:cnoremap <C-E> <End>
" forward one character
:cnoremap <C-F> <Right>
" recall newer command-line
:cnoremap <C-N> <Down>
" recall previous (older) command-line
:cnoremap <C-P> <Up>
" back one word
:cnoremap <Esc><C-B> <S-Left>
" forward one word
:cnoremap <Esc><C-F> <S-Right>
<
*format-bullet-list*
This mapping will format any bullet list. It requires that there is an empty
line above and below each list entry. The expression commands