annotate runtime/doc/usr_23.txt @ 5569:1b09d6792520 v7.4.132

updated for version 7.4.132 Problem: Win32: flags and inherit_handles arguments mixed up. Solution: Swap the argument. (cs86661)
author Bram Moolenaar <bram@vim.org>
date Sun, 05 Jan 2014 13:29:26 +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 *usr_23.txt* For Vim version 7.4. Last change: 2006 Apr 24
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3 VIM USER MANUAL - by Bram Moolenaar
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5 Editing other files
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8 This chapter is about editing files that are not ordinary files. With Vim you
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9 can edit files that are compressed or encrypted. Some files need to be
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
10 accessed over the internet. With some restrictions, binary files can be
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
11 edited as well.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
12
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
13 |23.1| DOS, Mac and Unix files
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
14 |23.2| Files on the internet
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
15 |23.3| Encryption
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
16 |23.4| Binary files
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
17 |23.5| Compressed files
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
18
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
19 Next chapter: |usr_24.txt| Inserting quickly
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
20 Previous chapter: |usr_22.txt| Finding the file to edit
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
21 Table of contents: |usr_toc.txt|
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
22
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
23 ==============================================================================
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
24 *23.1* DOS, Mac and Unix files
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
25
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
26 Back in the early days, the old Teletype machines used two characters to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
27 start a new line. One to move the carriage back to the first position
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
28 (carriage return, <CR>), another to move the paper up (line feed, <LF>).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
29 When computers came out, storage was expensive. Some people decided that
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
30 they did not need two characters for end-of-line. The UNIX people decided
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
31 they could use <Line Feed> only for end-of-line. The Apple people
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
32 standardized on <CR>. The MS-DOS (and Microsoft Windows) folks decided to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
33 keep the old <CR><LF>.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
34 This means that if you try to move a file from one system to another, you
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
35 have line-break problems. The Vim editor automatically recognizes the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
36 different file formats and handles things properly behind your back.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
37 The option 'fileformats' contains the various formats that will be tried
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
38 when a new file is edited. The following command, for example, tells Vim to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
39 try UNIX format first and MS-DOS format second: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
40
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
41 :set fileformats=unix,dos
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
42
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
43 You will notice the format in the message you get when editing a file. You
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
44 don't see anything if you edit a native file format. Thus editing a Unix file
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
45 on Unix won't result in a remark. But when you edit a dos file, Vim will
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
46 notify you of this:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
47
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
48 "/tmp/test" [dos] 3L, 71C ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
49
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
50 For a Mac file you would see "[mac]".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
51 The detected file format is stored in the 'fileformat' option. To see
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
52 which format you have, execute the following command: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
53
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
54 :set fileformat?
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
55
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
56 The three names that Vim uses are:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
57
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
58 unix <LF>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
59 dos <CR><LF>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
60 mac <CR>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
61
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
62
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
63 USING THE MAC FORMAT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
64
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
65 On Unix, <LF> is used to break a line. It's not unusual to have a <CR>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
66 character halfway a line. Incidentally, this happens quite often in Vi (and
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
67 Vim) scripts.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
68 On the Macintosh, where <CR> is the line break character, it's possible to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
69 have a <LF> character halfway a line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
70 The result is that it's not possible to be 100% sure whether a file
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
71 containing both <CR> and <LF> characters is a Mac or a Unix file. Therefore,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
72 Vim assumes that on Unix you probably won't edit a Mac file, and doesn't check
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
73 for this type of file. To check for this format anyway, add "mac" to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
74 'fileformats': >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
75
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
76 :set fileformats+=mac
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
77
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
78 Then Vim will take a guess at the file format. Watch out for situations where
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
79 Vim guesses wrong.
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 OVERRULING THE FORMAT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
83
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
84 If you use the good old Vi and try to edit an MS-DOS format file, you will
237
73354c21f1e4 updated for version 7.0066
vimboss
parents: 7
diff changeset
85 find that each line ends with a ^M character. (^M is <CR>). The automatic
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
86 detection avoids this. Suppose you do want to edit the file that way? Then
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
87 you need to overrule the format: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
88
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
89 :edit ++ff=unix file.txt
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
90
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
91 The "++" string is an item that tells Vim that an option name follows, which
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
92 overrules the default for this single command. "++ff" is used for
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
93 'fileformat'. You could also use "++ff=mac" or "++ff=dos".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
94 This doesn't work for any option, only "++ff" and "++enc" are currently
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
95 implemented. The full names "++fileformat" and "++encoding" also work.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
96
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
97
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
98 CONVERSION
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
99
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
100 You can use the 'fileformat' option to convert from one file format to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
101 another. Suppose, for example, that you have an MS-DOS file named README.TXT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
102 that you want to convert to UNIX format. Start by editing the MS-DOS format
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
103 file: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
104 vim README.TXT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
105
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
106 Vim will recognize this as a dos format file. Now change the file format to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
107 UNIX: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
108
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
109 :set fileformat=unix
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
110 :write
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
111
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
112 The file is written in Unix format.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
113
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
114 ==============================================================================
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
115 *23.2* Files on the internet
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
116
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
117 Someone sends you an e-mail message, which refers to a file by its URL. For
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
118 example:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
119
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
120 You can find the information here: ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
121 ftp://ftp.vim.org/pub/vim/README ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
122
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
123 You could start a program to download the file, save it on your local disk and
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
124 then start Vim to edit it.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
125 There is a much simpler way. Move the cursor to any character of the URL.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
126 Then use this command: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
127
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
128 gf
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
129
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
130 With a bit of luck, Vim will figure out which program to use for downloading
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
131 the file, download it and edit the copy. To open the file in a new window use
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
132 CTRL-W f.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
133 If something goes wrong you will get an error message. It's possible that
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
134 the URL is wrong, you don't have permission to read it, the network connection
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
135 is down, etc. Unfortunately, it's hard to tell the cause of the error. You
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
136 might want to try the manual way of downloading the file.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
137
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
138 Accessing files over the internet works with the netrw plugin. Currently URLs
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
139 with these formats are recognized:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
140
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
141 ftp:// uses ftp
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
142 rcp:// uses rcp
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
143 scp:// uses scp
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
144 http:// uses wget (reading only)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
145
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
146 Vim doesn't do the communication itself, it relies on the mentioned programs
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
147 to be available on your computer. On most Unix systems "ftp" and "rcp" will
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
148 be present. "scp" and "wget" might need to be installed.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
149
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
150 Vim detects these URLs for each command that starts editing a new file, also
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
151 with ":edit" and ":split", for example. Write commands also work, except for
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
152 http://.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
153
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
154 For more information, also about passwords, see |netrw|.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
155
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
156 ==============================================================================
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
157 *23.3* Encryption
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
158
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
159 Some information you prefer to keep to yourself. For example, when writing
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
160 a test on a computer that students also use. You don't want clever students
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
161 to figure out a way to read the questions before the exam starts. Vim can
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
162 encrypt the file for you, which gives you some protection.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
163 To start editing a new file with encryption, use the "-x" argument to start
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
164 Vim. Example: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
165
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
166 vim -x exam.txt
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
167
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
168 Vim prompts you for a key used for encrypting and decrypting the file:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
169
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
170 Enter encryption key: ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
171
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
172 Carefully type the secret key now. You cannot see the characters you type,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
173 they will be replaced by stars. To avoid the situation that a typing mistake
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
174 will cause trouble, Vim asks you to enter the key again:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
175
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
176 Enter same key again: ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
177
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
178 You can now edit this file normally and put in all your secrets. When you
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
179 finish editing the file and tell Vim to exit, the file is encrypted and
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
180 written.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
181 When you edit the file with Vim, it will ask you to enter the same key
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
182 again. You don't need to use the "-x" argument. You can also use the normal
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
183 ":edit" command. Vim adds a magic string to the file by which it recognizes
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
184 that the file was encrypted.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
185 If you try to view this file using another program, all you get is garbage.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
186 Also, if you edit the file with Vim and enter the wrong key, you get garbage.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
187 Vim does not have a mechanism to check if the key is the right one (this makes
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
188 it much harder to break the key).
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 SWITCHING ENCRYPTION ON AND OFF
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
192
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
193 To disable the encryption of a file, set the 'key' option to an empty string:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
194 >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
195 :set key=
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
196
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
197 The next time you write the file this will be done without encryption.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
198 Setting the 'key' option to enable encryption is not a good idea, because
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
199 the password appears in the clear. Anyone shoulder-surfing can read your
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
200 password.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
201 To avoid this problem, the ":X" command was created. It asks you for an
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
202 encryption key, just like the "-x" argument did: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
203
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
204 :X
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
205 Enter encryption key: ******
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
206 Enter same key again: ******
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
207
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
208
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
209 LIMITS ON ENCRYPTION
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
210
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
211 The encryption algorithm used by Vim is weak. It is good enough to keep out
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
212 the casual prowler, but not good enough to keep out a cryptology expert with
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
213 lots of time on his hands. Also you should be aware that the swap file is not
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
214 encrypted; so while you are editing, people with superuser privileges can read
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
215 the unencrypted text from this file.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
216 One way to avoid letting people read your swap file is to avoid using one.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
217 If the -n argument is supplied on the command line, no swap file is used
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
218 (instead, Vim puts everything in memory). For example, to edit the encrypted
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
219 file "file.txt" without a swap file use the following command: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
220
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
221 vim -x -n file.txt
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
222
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
223 When already editing a file, the swapfile can be disabled with: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
224
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
225 :setlocal noswapfile
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
226
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
227 Since there is no swapfile, recovery will be impossible. Save the file a bit
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
228 more often to avoid the risk of losing your changes.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
229
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
230 While the file is in memory, it is in plain text. Anyone with privilege can
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
231 look in the editor's memory and discover the contents of the file.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
232 If you use a viminfo file, be aware that the contents of text registers are
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
233 written out in the clear as well.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
234 If you really want to secure the contents of a file, edit it only on a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
235 portable computer not connected to a network, use good encryption tools, and
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
236 keep the computer locked up in a big safe when not in use.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
237
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
238 ==============================================================================
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
239 *23.4* Binary files
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
240
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
241 You can edit binary files with Vim. Vim wasn't really made for this, thus
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
242 there are a few restrictions. But you can read a file, change a character and
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
243 write it back, with the result that only that one character was changed and
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
244 the file is identical otherwise.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
245 To make sure that Vim does not use its clever tricks in the wrong way, add
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
246 the "-b" argument when starting Vim: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
247
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
248 vim -b datafile
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
249
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
250 This sets the 'binary' option. The effect of this is that unexpected side
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
251 effects are turned off. For example, 'textwidth' is set to zero, to avoid
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
252 automatic formatting of lines. And files are always read in Unix file format.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
253
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
254 Binary mode can be used to change a message in a program. Be careful not to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
255 insert or delete any characters, it would stop the program from working. Use
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
256 "R" to enter replace mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
257
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
258 Many characters in the file will be unprintable. To see them in Hex format: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
259
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
260 :set display=uhex
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
261
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
262 Otherwise, the "ga" command can be used to see the value of the character
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
263 under the cursor. The output, when the cursor is on an <Esc>, looks like
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
264 this:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
265
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
266 <^[> 27, Hex 1b, Octal 033 ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
267
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
268 There might not be many line breaks in the file. To get some overview switch
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
269 the 'wrap' option off: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
270
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
271 :set nowrap
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
272
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
273
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
274 BYTE POSITION
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
275
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
276 To see on which byte you are in the file use this command: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
277
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
278 g CTRL-G
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
279
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
280 The output is verbose:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
281
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
282 Col 9-16 of 9-16; Line 277 of 330; Word 1806 of 2058; Byte 10580 of 12206 ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
283
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
284 The last two numbers are the byte position in the file and the total number of
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
285 bytes. This takes into account how 'fileformat' changes the number of bytes
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
286 that a line break uses.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
287 To move to a specific byte in the file, use the "go" command. For
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
288 example, to move to byte 2345: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
289
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
290 2345go
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
291
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
292
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
293 USING XXD
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
294
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
295 A real binary editor shows the text in two ways: as it is and in hex format.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
296 You can do this in Vim by first converting the file with the "xxd" program.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
297 This comes with Vim.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
298 First edit the file in binary mode: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
299
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
300 vim -b datafile
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
301
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
302 Now convert the file to a hex dump with xxd: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
303
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
304 :%!xxd
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
305
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
306 The text will look like this:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
307
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
308 0000000: 1f8b 0808 39d7 173b 0203 7474 002b 4e49 ....9..;..tt.+NI ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
309 0000010: 4b2c 8660 eb9c ecac c462 eb94 345e 2e30 K,.`.....b..4^.0 ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
310 0000020: 373b 2731 0b22 0ca6 c1a2 d669 1035 39d9 7;'1.".....i.59. ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
311
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
312 You can now view and edit the text as you like. Vim treats the information as
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
313 ordinary text. Changing the hex does not cause the printable character to be
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
314 changed, or the other way around.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
315 Finally convert it back with:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
316 >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
317 :%!xxd -r
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
318
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
319 Only changes in the hex part are used. Changes in the printable text part on
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
320 the right are ignored.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
321
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
322 See the manual page of xxd for more information.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
323
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
324 ==============================================================================
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
325 *23.5* Compressed files
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
326
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
327 This is easy: You can edit a compressed file just like any other file. The
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
328 "gzip" plugin takes care of decompressing the file when you edit it. And
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
329 compressing it again when you write it.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
330 These compression methods are currently supported:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
331
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
332 .Z compress
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
333 .gz gzip
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
334 .bz2 bzip2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
335
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
336 Vim uses the mentioned programs to do the actual compression and
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
337 decompression. You might need to install the programs first.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
338
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
339 ==============================================================================
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
340
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
341 Next chapter: |usr_24.txt| Inserting quickly
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
342
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
343 Copyright: see |manual-copyright| vim:tw=78:ts=8:ft=help:norl: