annotate runtime/doc/tips.txt @ 5504:ec5d11403c19 v7.4.101

updated for version 7.4.101 Problem: Using \1 in pattern goes one line too far. (Bohr Shaw, John Little) Solution: Only advance the match end for the matched characters in the last line.
author Bram Moolenaar <bram@vim.org>
date Thu, 21 Nov 2013 17:13:00 +0100
parents 359743c1f59a
children 9f48eab77d62
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5294
359743c1f59a release version 7.4
Bram Moolenaar <bram@vim.org>
parents: 5247
diff changeset
1 *tips.txt* For Vim version 7.4. Last change: 2009 Nov 07
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4 VIM REFERENCE MANUAL by Bram Moolenaar
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7 Tips and ideas for using Vim *tips*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8
2033
de5a43c5eedc Update documentation files.
Bram Moolenaar <bram@zimbu.org>
parents: 1702
diff changeset
9 These are just a few that we thought would be helpful for many users.
de5a43c5eedc Update documentation files.
Bram Moolenaar <bram@zimbu.org>
parents: 1702
diff changeset
10 You can find many more tips on the wiki. The URL can be found on
de5a43c5eedc Update documentation files.
Bram Moolenaar <bram@zimbu.org>
parents: 1702
diff changeset
11 http://www.vim.org
de5a43c5eedc Update documentation files.
Bram Moolenaar <bram@zimbu.org>
parents: 1702
diff changeset
12
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
13 Don't forget to browse the user manual, it also contains lots of useful tips
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
14 |usr_toc.txt|.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
15
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
16 Editing C programs |C-editing|
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
17 Finding where identifiers are used |ident-search|
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
18 Switching screens in an xterm |xterm-screens|
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
19 Scrolling in Insert mode |scroll-insert|
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
20 Smooth scrolling |scroll-smooth|
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
21 Correcting common typing mistakes |type-mistakes|
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
22 Counting words, lines, etc. |count-items|
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
23 Restoring the cursor position |restore-position|
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
24 Renaming files |rename-files|
2033
de5a43c5eedc Update documentation files.
Bram Moolenaar <bram@zimbu.org>
parents: 1702
diff changeset
25 Change a name in multiple files |change-name|
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
26 Speeding up external commands |speed-up|
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
27 Useful mappings |useful-mappings|
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
28 Compressing the help files |gzip-helpfile|
2033
de5a43c5eedc Update documentation files.
Bram Moolenaar <bram@zimbu.org>
parents: 1702
diff changeset
29 Executing shell commands in a window |shell-window|
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
30 Hex editing |hex-editing|
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
31 Using <> notation in autocommands |autocmd-<>|
667
9090f866cd57 updated for version 7.0197
vimboss
parents: 246
diff changeset
32 Highlighting matching parens |match-parens|
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
33
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
34 ==============================================================================
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
35 Editing C programs *C-editing*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
36
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
37 There are quite a few features in Vim to help you edit C program files. Here
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
38 is an overview with tags to jump to:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
39
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
40 |usr_29.txt| Moving through programs chapter in the user manual.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
41 |usr_30.txt| Editing programs chapter in the user manual.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
42 |C-indenting| Automatically set the indent of a line while typing
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
43 text.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
44 |=| Re-indent a few lines.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
45 |format-comments| Format comments.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
46
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
47 |:checkpath| Show all recursively included files.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
48 |[i| Search for identifier under cursor in current and
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
49 included files.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
50 |[_CTRL-I| Jump to match for "[i"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
51 |[I| List all lines in current and included files where
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
52 identifier under the cursor matches.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
53 |[d| Search for define under cursor in current and included
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
54 files.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
55
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
56 |CTRL-]| Jump to tag under cursor (e.g., definition of a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
57 function).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
58 |CTRL-T| Jump back to before a CTRL-] command.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
59 |:tselect| Select one tag out of a list of matching tags.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
60
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
61 |gd| Go to Declaration of local variable under cursor.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
62 |gD| Go to Declaration of global variable under cursor.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
63
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
64 |gf| Go to file name under the cursor.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
65
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
66 |%| Go to matching (), {}, [], /* */, #if, #else, #endif.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
67 |[/| Go to previous start of comment.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
68 |]/| Go to next end of comment.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
69 |[#| Go back to unclosed #if, #ifdef, or #else.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
70 |]#| Go forward to unclosed #else or #endif.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
71 |[(| Go back to unclosed '('
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
72 |])| Go forward to unclosed ')'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
73 |[{| Go back to unclosed '{'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
74 |]}| Go forward to unclosed '}'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
75
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
76 |v_ab| Select "a block" from "[(" to "])", including braces
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
77 |v_ib| Select "inner block" from "[(" to "])"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
78 |v_aB| Select "a block" from "[{" to "]}", including brackets
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
79 |v_iB| Select "inner block" from "[{" to "]}"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
80
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
81 ==============================================================================
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
82 Finding where identifiers are used *ident-search*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
83
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
84 You probably already know that |tags| can be used to jump to the place where a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
85 function or variable is defined. But sometimes you wish you could jump to all
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
86 the places where a function or variable is being used. This is possible in
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
87 two ways:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
88 1. Using the |:grep| command. This should work on most Unix systems,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
89 but can be slow (it reads all files) and only searches in one directory.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
90 2. Using ID utils. This is fast and works in multiple directories. It uses a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
91 database to store locations. You will need some additional programs for
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
92 this to work. And you need to keep the database up to date.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
93
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
94 Using the GNU id-tools:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
95
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
96 What you need:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
97 - The GNU id-tools installed (mkid is needed to create ID and lid is needed to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
98 use the macros).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
99 - An identifier database file called "ID" in the current directory. You can
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
100 create it with the shell command "mkid file1 file2 ..".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
101
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
102 Put this in your .vimrc: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
103 map _u :call ID_search()<Bar>execute "/\\<" . g:word . "\\>"<CR>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
104 map _n :n<Bar>execute "/\\<" . g:word . "\\>"<CR>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
105
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
106 function! ID_search()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
107 let g:word = expand("<cword>")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
108 let x = system("lid --key=none ". g:word)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
109 let x = substitute(x, "\n", " ", "g")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
110 execute "next " . x
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
111 endfun
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
112
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
113 To use it, place the cursor on a word, type "_u" and vim will load the file
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
114 that contains the word. Search for the next occurrence of the word in the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
115 same file with "n". Go to the next file with "_n".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
116
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
117 This has been tested with id-utils-3.2 (which is the name of the id-tools
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
118 archive file on your closest gnu-ftp-mirror).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
119
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
120 [the idea for this comes from Andreas Kutschera]
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
121
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
122 ==============================================================================
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
123 Switching screens in an xterm *xterm-screens* *xterm-save-screen*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
124
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
125 (From comp.editors, by Juergen Weigert, in reply to a question)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
126
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
127 :> Another question is that after exiting vim, the screen is left as it
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
128 :> was, i.e. the contents of the file I was viewing (editing) was left on
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
129 :> the screen. The output from my previous like "ls" were lost,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
130 :> ie. no longer in the scrolling buffer. I know that there is a way to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
131 :> restore the screen after exiting vim or other vi like editors,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
132 :> I just don't know how. Helps are appreciated. Thanks.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
133 :
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
134 :I imagine someone else can answer this. I assume though that vim and vi do
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
135 :the same thing as each other for a given xterm setup.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
136
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
137 They not necessarily do the same thing, as this may be a termcap vs.
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 170
diff changeset
138 terminfo problem. You should be aware that there are two databases for
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
139 describing attributes of a particular type of terminal: termcap and
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 170
diff changeset
140 terminfo. This can cause differences when the entries differ AND when of
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
141 the programs in question one uses terminfo and the other uses termcap
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
142 (also see |+terminfo|).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
143
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
144 In your particular problem, you are looking for the control sequences
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 170
diff changeset
145 ^[[?47h and ^[[?47l. These switch between xterms alternate and main screen
4707450c2b33 updated for version 7.0066
vimboss
parents: 170
diff changeset
146 buffer. As a quick workaround a command sequence like >
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
147 echo -n "^[[?47h"; vim ... ; echo -n "^[[?47l"
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 170
diff changeset
148 may do what you want. (My notation ^[ means the ESC character, further down
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
149 you'll see that the databases use \E instead).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
150
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
151 On startup, vim echoes the value of the termcap variable ti (terminfo:
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 170
diff changeset
152 smcup) to the terminal. When exiting, it echoes te (terminfo: rmcup). Thus
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
153 these two variables are the correct place where the above mentioned control
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
154 sequences should go.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
155
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
156 Compare your xterm termcap entry (found in /etc/termcap) with your xterm
1121
e63691e7c504 updated for version 7.1a
vimboss
parents: 874
diff changeset
157 terminfo entry (retrieved with "infocmp -C xterm"). Both should contain
e63691e7c504 updated for version 7.1a
vimboss
parents: 874
diff changeset
158 entries similar to: >
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
159 :te=\E[2J\E[?47l\E8:ti=\E7\E[?47h:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
160
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
161 PS: If you find any difference, someone (your sysadmin?) should better check
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
162 the complete termcap and terminfo database for consistency.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
163
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
164 NOTE 1: If you recompile Vim with FEAT_XTERM_SAVE defined in feature.h, the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
165 builtin xterm will include the mentioned "te" and "ti" entries.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
166
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
167 NOTE 2: If you want to disable the screen switching, and you don't want to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
168 change your termcap, you can add these lines to your .vimrc: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
169 :set t_ti= t_te=
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
170
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
171 ==============================================================================
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
172 Scrolling in Insert mode *scroll-insert*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
173
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
174 If you are in insert mode and you want to see something that is just off the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
175 screen, you can use CTRL-X CTRL-E and CTRL-X CTRL-Y to scroll the screen.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
176 |i_CTRL-X_CTRL-E|
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
177
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
178 To make this easier, you could use these mappings: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
179 :inoremap <C-E> <C-X><C-E>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
180 :inoremap <C-Y> <C-X><C-Y>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
181 (Type this literally, make sure the '<' flag is not in 'cpoptions').
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
182 You then lose the ability to copy text from the line above/below the cursor
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
183 |i_CTRL-E|.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
184
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
185 Also consider setting 'scrolloff' to a larger value, so that you can always see
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
186 some context around the cursor. If 'scrolloff' is bigger than half the window
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
187 height, the cursor will always be in the middle and the text is scrolled when
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
188 the cursor is moved up/down.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
189
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
190 ==============================================================================
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
191 Smooth scrolling *scroll-smooth*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
192
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
193 If you like the scrolling to go a bit smoother, you can use these mappings: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
194 :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>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
195 :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>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
196
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
197 (Type this literally, make sure the '<' flag is not in 'cpoptions').
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
198
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
199 ==============================================================================
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
200 Correcting common typing mistakes *type-mistakes*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
201
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
202 When there are a few words that you keep on typing in the wrong way, make
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
203 abbreviations that correct them. For example: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
204 :ab teh the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
205 :ab fro for
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
206
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
207 ==============================================================================
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
208 Counting words, lines, etc. *count-items*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
209
170
8c60f65311fa updated for version 7.0052
vimboss
parents: 7
diff changeset
210 To count how often any pattern occurs in the current buffer use the substitute
8c60f65311fa updated for version 7.0052
vimboss
parents: 7
diff changeset
211 command and add the 'n' flag to avoid the substitution. The reported number
8c60f65311fa updated for version 7.0052
vimboss
parents: 7
diff changeset
212 of substitutions is the number of items. Examples: >
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
213
170
8c60f65311fa updated for version 7.0052
vimboss
parents: 7
diff changeset
214 :%s/./&/gn characters
8c60f65311fa updated for version 7.0052
vimboss
parents: 7
diff changeset
215 :%s/\i\+/&/gn words
8c60f65311fa updated for version 7.0052
vimboss
parents: 7
diff changeset
216 :%s/^//n lines
8c60f65311fa updated for version 7.0052
vimboss
parents: 7
diff changeset
217 :%s/the/&/gn "the" anywhere
8c60f65311fa updated for version 7.0052
vimboss
parents: 7
diff changeset
218 :%s/\<the\>/&/gn "the" as a word
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
219
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
220 You might want to reset 'hlsearch' or do ":nohlsearch".
170
8c60f65311fa updated for version 7.0052
vimboss
parents: 7
diff changeset
221 Add the 'e' flag if you don't want an error when there are no matches.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
222
170
8c60f65311fa updated for version 7.0052
vimboss
parents: 7
diff changeset
223 An alternative is using |v_g_CTRL-G| in Visual mode.
8c60f65311fa updated for version 7.0052
vimboss
parents: 7
diff changeset
224
8c60f65311fa updated for version 7.0052
vimboss
parents: 7
diff changeset
225 If you want to find matches in multiple files use |:vimgrep|.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
226
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
227 *count-bytes*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
228 If you want to count bytes, you can use this:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
229
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
230 Visually select the characters (block is also possible)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
231 Use "y" to yank the characters
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
232 Use the strlen() function: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
233 :echo strlen(@")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
234 A line break is counted for one byte.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
235
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
236 ==============================================================================
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
237 Restoring the cursor position *restore-position*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
238
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
239 Sometimes you want to write a mapping that makes a change somewhere in the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
240 file and restores the cursor position, without scrolling the text. For
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
241 example, to change the date mark in a file: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
242 :map <F2> msHmtgg/Last [cC]hange:\s*/e+1<CR>"_D"=strftime("%Y %b %d")<CR>p'tzt`s
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
243
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
244 Breaking up saving the position:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
245 ms store cursor position in the 's' mark
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
246 H go to the first line in the window
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
247 mt store this position in the 't' mark
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
248
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
249 Breaking up restoring the position:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
250 't go to the line previously at the top of the window
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
251 zt scroll to move this line to the top of the window
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
252 `s jump to the original position of the cursor
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
253
2033
de5a43c5eedc Update documentation files.
Bram Moolenaar <bram@zimbu.org>
parents: 1702
diff changeset
254 For something more advanced see |winsaveview()| and |winrestview()|.
de5a43c5eedc Update documentation files.
Bram Moolenaar <bram@zimbu.org>
parents: 1702
diff changeset
255
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
256 ==============================================================================
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
257 Renaming files *rename-files*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
258
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
259 Say I have a directory with the following files in them (directory picked at
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
260 random :-):
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
261
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
262 buffer.c
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
263 charset.c
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
264 digraph.c
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
265 ...
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
266
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
267 and I want to rename *.c *.bla. I'd do it like this: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
268
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
269 $ vim
246
c8fd241d3cdd updated for version 7.0068
vimboss
parents: 236
diff changeset
270 :r !ls *.c
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
271 :%s/\(.*\).c/mv & \1.bla
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
272 :w !sh
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
273 :q!
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
274
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
275 ==============================================================================
2033
de5a43c5eedc Update documentation files.
Bram Moolenaar <bram@zimbu.org>
parents: 1702
diff changeset
276 Change a name in multiple files *change-name*
de5a43c5eedc Update documentation files.
Bram Moolenaar <bram@zimbu.org>
parents: 1702
diff changeset
277
de5a43c5eedc Update documentation files.
Bram Moolenaar <bram@zimbu.org>
parents: 1702
diff changeset
278 Example for using a script file to change a name in several files:
de5a43c5eedc Update documentation files.
Bram Moolenaar <bram@zimbu.org>
parents: 1702
diff changeset
279
de5a43c5eedc Update documentation files.
Bram Moolenaar <bram@zimbu.org>
parents: 1702
diff changeset
280 Create a file "subs.vim" containing substitute commands and a :update
de5a43c5eedc Update documentation files.
Bram Moolenaar <bram@zimbu.org>
parents: 1702
diff changeset
281 command: >
de5a43c5eedc Update documentation files.
Bram Moolenaar <bram@zimbu.org>
parents: 1702
diff changeset
282 :%s/Jones/Smith/g
de5a43c5eedc Update documentation files.
Bram Moolenaar <bram@zimbu.org>
parents: 1702
diff changeset
283 :%s/Allen/Peter/g
de5a43c5eedc Update documentation files.
Bram Moolenaar <bram@zimbu.org>
parents: 1702
diff changeset
284 :update
de5a43c5eedc Update documentation files.
Bram Moolenaar <bram@zimbu.org>
parents: 1702
diff changeset
285 <
de5a43c5eedc Update documentation files.
Bram Moolenaar <bram@zimbu.org>
parents: 1702
diff changeset
286 Execute Vim on all files you want to change, and source the script for
de5a43c5eedc Update documentation files.
Bram Moolenaar <bram@zimbu.org>
parents: 1702
diff changeset
287 each argument: >
de5a43c5eedc Update documentation files.
Bram Moolenaar <bram@zimbu.org>
parents: 1702
diff changeset
288
de5a43c5eedc Update documentation files.
Bram Moolenaar <bram@zimbu.org>
parents: 1702
diff changeset
289 vim *.let
de5a43c5eedc Update documentation files.
Bram Moolenaar <bram@zimbu.org>
parents: 1702
diff changeset
290 argdo source subs.vim
de5a43c5eedc Update documentation files.
Bram Moolenaar <bram@zimbu.org>
parents: 1702
diff changeset
291
de5a43c5eedc Update documentation files.
Bram Moolenaar <bram@zimbu.org>
parents: 1702
diff changeset
292 See |:argdo|.
de5a43c5eedc Update documentation files.
Bram Moolenaar <bram@zimbu.org>
parents: 1702
diff changeset
293
de5a43c5eedc Update documentation files.
Bram Moolenaar <bram@zimbu.org>
parents: 1702
diff changeset
294 ==============================================================================
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
295 Speeding up external commands *speed-up*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
296
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
297 In some situations, execution of an external command can be very slow. This
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
298 can also slow down wildcard expansion on Unix. Here are a few suggestions to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
299 increase the speed.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
300
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
301 If your .cshrc (or other file, depending on the shell used) is very long, you
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
302 should separate it into a section for interactive use and a section for
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
303 non-interactive use (often called secondary shells). When you execute a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
304 command from Vim like ":!ls", you do not need the interactive things (for
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
305 example, setting the prompt). Put the stuff that is not needed after these
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
306 lines: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
307
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
308 if ($?prompt == 0) then
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
309 exit 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
310 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
311
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
312 Another way is to include the "-f" flag in the 'shell' option, e.g.: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
313
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
314 :set shell=csh\ -f
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
315
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
316 (the backslash is needed to include the space in the option).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
317 This will make csh completely skip the use of the .cshrc file. This may cause
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
318 some things to stop working though.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
319
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
320 ==============================================================================
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
321 Useful mappings *useful-mappings*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
322
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
323 Here are a few mappings that some people like to use.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
324
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
325 *map-backtick* >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
326 :map ' `
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
327 Make the single quote work like a backtick. Puts the cursor on the column of
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
328 a mark, instead of going to the first non-blank character in the line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
329
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
330 *emacs-keys*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
331 For Emacs-style editing on the command-line: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
332 " start of line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
333 :cnoremap <C-A> <Home>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
334 " back one character
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
335 :cnoremap <C-B> <Left>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
336 " delete character under cursor
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
337 :cnoremap <C-D> <Del>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
338 " end of line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
339 :cnoremap <C-E> <End>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
340 " forward one character
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
341 :cnoremap <C-F> <Right>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
342 " recall newer command-line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
343 :cnoremap <C-N> <Down>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
344 " recall previous (older) command-line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
345 :cnoremap <C-P> <Up>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
346 " back one word
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
347 :cnoremap <Esc><C-B> <S-Left>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
348 " forward one word
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
349 :cnoremap <Esc><C-F> <S-Right>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
350
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
351 NOTE: This requires that the '<' flag is excluded from 'cpoptions'. |<>|
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
352
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
353 *format-bullet-list*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
354 This mapping will format any bullet list. It requires that there is an empty
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
355 line above and below each list entry. The expression commands are used to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
356 be able to give comments to the parts of the mapping. >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
357
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
358 :let m = ":map _f :set ai<CR>" " need 'autoindent' set
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
359 :let m = m . "{O<Esc>" " add empty line above item
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
360 :let m = m . "}{)^W" " move to text after bullet
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
361 :let m = m . "i <CR> <Esc>" " add space for indent
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
362 :let m = m . "gq}" " format text after the bullet
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
363 :let m = m . "{dd" " remove the empty line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
364 :let m = m . "5lDJ" " put text after bullet
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
365 :execute m |" define the mapping
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
366
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
367 (<> notation |<>|. Note that this is all typed literally. ^W is "^" "W", not
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
368 CTRL-W. You can copy/paste this into Vim if '<' is not included in
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 170
diff changeset
369 'cpoptions'.)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
370
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
371 Note that the last comment starts with |", because the ":execute" command
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
372 doesn't accept a comment directly.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
373
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
374 You also need to set 'textwidth' to a non-zero value, e.g., >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
375 :set tw=70
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
376
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
377 A mapping that does about the same, but takes the indent for the list from the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
378 first line (Note: this mapping is a single long line with a lot of spaces): >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
379 :map _f :set ai<CR>}{a <Esc>WWmmkD`mi<CR><Esc>kkddpJgq}'mJO<Esc>j
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
380 <
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
381 *collapse*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
382 These two mappings reduce a sequence of empty (;b) or blank (;n) lines into a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
383 single line >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
384 :map ;b GoZ<Esc>:g/^$/.,/./-j<CR>Gdd
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
385 :map ;n GoZ<Esc>:g/^[ <Tab>]*$/.,/[^ <Tab>]/-j<CR>Gdd
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
386
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
387 ==============================================================================
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
388 Compressing the help files *gzip-helpfile*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
389
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
390 For those of you who are really short on disk space, you can compress the help
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
391 files and still be able to view them with Vim. This makes accessing the help
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
392 files a bit slower and requires the "gzip" program.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
393
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
394 (1) Compress all the help files: "gzip doc/*.txt".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
395
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
396 (2) Edit "doc/tags" and change the ".txt" to ".txt.gz": >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
397 :%s=\(\t.*\.txt\)\t=\1.gz\t=
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
398
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
399 (3) Add this line to your vimrc: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
400 set helpfile={dirname}/help.txt.gz
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
401
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
402 Where {dirname} is the directory where the help files are. The |gzip| plugin
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
403 will take care of decompressing the files.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
404 You must make sure that $VIMRUNTIME is set to where the other Vim files are,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
405 when they are not in the same location as the compressed "doc" directory. See
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
406 |$VIMRUNTIME|.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
407
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
408 ==============================================================================
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
409 Executing shell commands in a window *shell-window*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
410
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
411 There have been questions for the possibility to execute a shell in a window
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
412 inside Vim. The answer: you can't! Including this would add a lot of code to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
413 Vim, which is a good reason not to do this. After all, Vim is an editor, it
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
414 is not supposed to do non-editing tasks. However, to get something like this,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
415 you might try splitting your terminal screen or display window with the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
416 "splitvt" program. You can probably find it on some ftp server. The person
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
417 that knows more about this is Sam Lantinga <slouken@cs.ucdavis.edu>.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
418 An alternative is the "window" command, found on BSD Unix systems, which
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
419 supports multiple overlapped windows. Or the "screen" program, found at
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
420 www.uni-erlangen.de, which supports a stack of windows.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
421
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
422 ==============================================================================
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
423 Hex editing *hex-editing* *using-xxd*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
424
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
425 See section |23.4| of the user manual.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
426
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
427 If one has a particular extension that one uses for binary files (such as exe,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
428 bin, etc), you may find it helpful to automate the process with the following
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
429 bit of autocmds for your <.vimrc>. Change that "*.bin" to whatever
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
430 comma-separated list of extension(s) you find yourself wanting to edit: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
431
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
432 " vim -b : edit binary using xxd-format!
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
433 augroup Binary
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
434 au!
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
435 au BufReadPre *.bin let &bin=1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
436 au BufReadPost *.bin if &bin | %!xxd
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
437 au BufReadPost *.bin set ft=xxd | endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
438 au BufWritePre *.bin if &bin | %!xxd -r
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
439 au BufWritePre *.bin endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
440 au BufWritePost *.bin if &bin | %!xxd
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
441 au BufWritePost *.bin set nomod | endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
442 augroup END
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
443
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
444 ==============================================================================
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
445 Using <> notation in autocommands *autocmd-<>*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
446
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
447 The <> notation is not recognized in the argument of an :autocmd. To avoid
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
448 having to use special characters, you could use a self-destroying mapping to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
449 get the <> notation and then call the mapping from the autocmd. Example:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
450
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
451 *map-self-destroy* >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
452 " This is for automatically adding the name of the file to the menu list.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
453 " It uses a self-destroying mapping!
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
454 " 1. use a line in the buffer to convert the 'dots' in the file name to \.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
455 " 2. store that in register '"'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
456 " 3. add that name to the Buffers menu list
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
457 " WARNING: this does have some side effects, like overwriting the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
458 " current register contents and removing any mapping for the "i" command.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
459 "
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
460 autocmd BufNewFile,BufReadPre * nmap i :nunmap i<CR>O<C-R>%<Esc>:.g/\./s/\./\\./g<CR>0"9y$u:menu Buffers.<C-R>9 :buffer <C-R>%<C-V><CR><CR>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
461 autocmd BufNewFile,BufReadPre * normal i
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
462
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
463 Another method, perhaps better, is to use the ":execute" command. In the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
464 string you can use the <> notation by preceding it with a backslash. Don't
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
465 forget to double the number of existing backslashes and put a backslash before
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
466 '"'.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
467 >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
468 autocmd BufNewFile,BufReadPre * exe "normal O\<C-R>%\<Esc>:.g/\\./s/\\./\\\\./g\<CR>0\"9y$u:menu Buffers.\<C-R>9 :buffer \<C-R>%\<C-V>\<CR>\<CR>"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
469
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
470 For a real buffer menu, user functions should be used (see |:function|), but
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
471 then the <> notation isn't used, which defeats using it as an example here.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
472
667
9090f866cd57 updated for version 7.0197
vimboss
parents: 246
diff changeset
473 ==============================================================================
9090f866cd57 updated for version 7.0197
vimboss
parents: 246
diff changeset
474 Highlighting matching parens *match-parens*
9090f866cd57 updated for version 7.0197
vimboss
parents: 246
diff changeset
475
9090f866cd57 updated for version 7.0197
vimboss
parents: 246
diff changeset
476 This example shows the use of a few advanced tricks:
9090f866cd57 updated for version 7.0197
vimboss
parents: 246
diff changeset
477 - using the |CursorMoved| autocommand event
9090f866cd57 updated for version 7.0197
vimboss
parents: 246
diff changeset
478 - using |searchpairpos()| to find a matching paren
674
4b8583e82cb8 updated for version 7.0201
vimboss
parents: 671
diff changeset
479 - using |synID()| to detect whether the cursor is in a string or comment
667
9090f866cd57 updated for version 7.0197
vimboss
parents: 246
diff changeset
480 - using |:match| to highlight something
9090f866cd57 updated for version 7.0197
vimboss
parents: 246
diff changeset
481 - using a |pattern| to match a specific position in the file.
9090f866cd57 updated for version 7.0197
vimboss
parents: 246
diff changeset
482
9090f866cd57 updated for version 7.0197
vimboss
parents: 246
diff changeset
483 This should be put in a Vim script file, since it uses script-local variables.
674
4b8583e82cb8 updated for version 7.0201
vimboss
parents: 671
diff changeset
484 It skips matches in strings or comments, unless the cursor started in string
4b8583e82cb8 updated for version 7.0201
vimboss
parents: 671
diff changeset
485 or comment. This requires syntax highlighting.
699
2af8de31a3a8 updated for version 7.0211
vimboss
parents: 674
diff changeset
486
2af8de31a3a8 updated for version 7.0211
vimboss
parents: 674
diff changeset
487 A slightly more advanced version is used in the |matchparen| plugin.
667
9090f866cd57 updated for version 7.0197
vimboss
parents: 246
diff changeset
488 >
9090f866cd57 updated for version 7.0197
vimboss
parents: 246
diff changeset
489 let s:paren_hl_on = 0
9090f866cd57 updated for version 7.0197
vimboss
parents: 246
diff changeset
490 function s:Highlight_Matching_Paren()
9090f866cd57 updated for version 7.0197
vimboss
parents: 246
diff changeset
491 if s:paren_hl_on
9090f866cd57 updated for version 7.0197
vimboss
parents: 246
diff changeset
492 match none
9090f866cd57 updated for version 7.0197
vimboss
parents: 246
diff changeset
493 let s:paren_hl_on = 0
9090f866cd57 updated for version 7.0197
vimboss
parents: 246
diff changeset
494 endif
9090f866cd57 updated for version 7.0197
vimboss
parents: 246
diff changeset
495
9090f866cd57 updated for version 7.0197
vimboss
parents: 246
diff changeset
496 let c_lnum = line('.')
9090f866cd57 updated for version 7.0197
vimboss
parents: 246
diff changeset
497 let c_col = col('.')
9090f866cd57 updated for version 7.0197
vimboss
parents: 246
diff changeset
498
9090f866cd57 updated for version 7.0197
vimboss
parents: 246
diff changeset
499 let c = getline(c_lnum)[c_col - 1]
9090f866cd57 updated for version 7.0197
vimboss
parents: 246
diff changeset
500 let plist = split(&matchpairs, ':\|,')
9090f866cd57 updated for version 7.0197
vimboss
parents: 246
diff changeset
501 let i = index(plist, c)
9090f866cd57 updated for version 7.0197
vimboss
parents: 246
diff changeset
502 if i < 0
9090f866cd57 updated for version 7.0197
vimboss
parents: 246
diff changeset
503 return
9090f866cd57 updated for version 7.0197
vimboss
parents: 246
diff changeset
504 endif
9090f866cd57 updated for version 7.0197
vimboss
parents: 246
diff changeset
505 if i % 2 == 0
9090f866cd57 updated for version 7.0197
vimboss
parents: 246
diff changeset
506 let s_flags = 'nW'
9090f866cd57 updated for version 7.0197
vimboss
parents: 246
diff changeset
507 let c2 = plist[i + 1]
9090f866cd57 updated for version 7.0197
vimboss
parents: 246
diff changeset
508 else
9090f866cd57 updated for version 7.0197
vimboss
parents: 246
diff changeset
509 let s_flags = 'nbW'
9090f866cd57 updated for version 7.0197
vimboss
parents: 246
diff changeset
510 let c2 = c
9090f866cd57 updated for version 7.0197
vimboss
parents: 246
diff changeset
511 let c = plist[i - 1]
9090f866cd57 updated for version 7.0197
vimboss
parents: 246
diff changeset
512 endif
9090f866cd57 updated for version 7.0197
vimboss
parents: 246
diff changeset
513 if c == '['
9090f866cd57 updated for version 7.0197
vimboss
parents: 246
diff changeset
514 let c = '\['
9090f866cd57 updated for version 7.0197
vimboss
parents: 246
diff changeset
515 let c2 = '\]'
9090f866cd57 updated for version 7.0197
vimboss
parents: 246
diff changeset
516 endif
674
4b8583e82cb8 updated for version 7.0201
vimboss
parents: 671
diff changeset
517 let s_skip ='synIDattr(synID(line("."), col("."), 0), "name") ' .
856
8cd729851562 updated for version 7.0g
vimboss
parents: 842
diff changeset
518 \ '=~? "string\\|comment"'
8cd729851562 updated for version 7.0g
vimboss
parents: 842
diff changeset
519 execute 'if' s_skip '| let s_skip = 0 | endif'
667
9090f866cd57 updated for version 7.0197
vimboss
parents: 246
diff changeset
520
674
4b8583e82cb8 updated for version 7.0201
vimboss
parents: 671
diff changeset
521 let [m_lnum, m_col] = searchpairpos(c, '', c2, s_flags, s_skip)
667
9090f866cd57 updated for version 7.0197
vimboss
parents: 246
diff changeset
522
9090f866cd57 updated for version 7.0197
vimboss
parents: 246
diff changeset
523 if m_lnum > 0 && m_lnum >= line('w0') && m_lnum <= line('w$')
9090f866cd57 updated for version 7.0197
vimboss
parents: 246
diff changeset
524 exe 'match Search /\(\%' . c_lnum . 'l\%' . c_col .
9090f866cd57 updated for version 7.0197
vimboss
parents: 246
diff changeset
525 \ 'c\)\|\(\%' . m_lnum . 'l\%' . m_col . 'c\)/'
9090f866cd57 updated for version 7.0197
vimboss
parents: 246
diff changeset
526 let s:paren_hl_on = 1
9090f866cd57 updated for version 7.0197
vimboss
parents: 246
diff changeset
527 endif
9090f866cd57 updated for version 7.0197
vimboss
parents: 246
diff changeset
528 endfunction
9090f866cd57 updated for version 7.0197
vimboss
parents: 246
diff changeset
529
671
83a006f81bac updated for version 7.0199
vimboss
parents: 667
diff changeset
530 autocmd CursorMoved,CursorMovedI * call s:Highlight_Matching_Paren()
667
9090f866cd57 updated for version 7.0197
vimboss
parents: 246
diff changeset
531 autocmd InsertEnter * match none
9090f866cd57 updated for version 7.0197
vimboss
parents: 246
diff changeset
532 <
9090f866cd57 updated for version 7.0197
vimboss
parents: 246
diff changeset
533
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
534 vim:tw=78:ts=8:ft=help:norl: