la sintaxis de la parte de búsqueda y la pieza de repuesto son arbitrariamente diferente. Algunos de los mismos códigos se vuelven a usar para significar cosas diferentes. Sí, es confuso.
| How to type | In search, means: | In replacement, means:
----------------------------------------------------------------------------
\n | \n | End-of-line | <Nul> 0x0
^@ | CTRL-V CTRL-J | <Nul> 0x0 | <Nul> 0x0
\r | \r | Carriage return 0xD | "Break the line here"
^M | CTRL-Enter | Carriage return 0xD | "Break the line here"
\^M | \ CTRL-V CTRL-ENTER | \ + carriage return 0xD | Carriage return 0xD
Durante la búsqueda, dependiendo de la plataforma, la 0xD
puede estar oculto parte, considerado de "salto de línea", así que sí ... siempre se puede devolver la cordura a sus archivos y obligar a todos los retornos de carro mostrados por abrir un archivo y hacer:
:e ++ff=unix
De forma similar, cuando se reemplaza, "romper la línea aquí" hace cosas diferentes dependiendo de su plataforma. Se podría insertar 0xA
o 0xD 0xA
etc.
En caso de que esto no es todo ya bastante malo:
Technical detail: *NL-used-for-Nul*
<Nul> characters in the file are stored as <NL> in memory. In the display
they are shown as "^@". The translation is done when reading and writing
files. To match a <Nul> with a search pattern you can just enter [email protected] or
"CTRL-V 000". This is probably just what you expect. Internally the
character is replaced with a <NL> in the search pattern. What is unusual is
that typing CTRL-V CTRL-J also inserts a <NL>, thus also searches for a <Nul>
in the file. {Vi cannot handle <Nul> characters in the file at all}
*CR-used-for-NL*
When 'fileformat' is "mac", <NL> characters in the file are stored as <CR>
characters internally. In the text they are shown as "^J". Otherwise this
works similar to the usage of <NL> for a <Nul>.
When working with expression evaluation, a <NL> character in the pattern
matches a <NL> in the string. The use of "\n" (backslash n) to match a <NL>
doesn't work there, it only works to match text in the buffer.
A no ser que se trata de literales o 0x0
0xD
caracteres, es claramente la perfecta regla general a pegarse siempre con \n
para la búsqueda y \r
para el reemplazo, como probablemente haya averiguado.
Consulte también:
:h /\n
:h /\r
:h s/\n
:h s/\r
:h s/\<CR>
usted piensa que es extraño? La forma en que solía corregir el problema de retorno de carro/alimentación de línea al moverme entre Unix y Windows es hacer ':% s/^ V^M/^ V^M/g' –
@Paul Siento que esto está relacionado problema. Como mostrar una cosa, buscar contra otra cosa y escribir una tercera. – tzenes