Vim special character's read and write detailed _linux

Source: Internet
Author: User


First, view special characters



Special characters visible in Vim are displayed directly, and invisible special characters are displayed as the characters are entered on the command line, for example, \ r appears as ^m. Through: Help Digraph-table can see all the special characters that can be entered in vim, the first page of the document is as follows:


Char digraph hex  Dec  official name
^@   NU   0x00  0  NULL  (NUL)
^a   SH   0x01  1  START of HEADING (SOH)
^b   SX   0x02  2  START of TEXT (STX)
^c   EX   0x03  3 end of  TEXT (ETX)
^d   ET   0x04  4 end of  transmission (EOT)
^e   EQ   0x05  5  Enquiry (ENQ)
^f   AK   0x06  6  Acknowledge (ACK)
^g   BL   0x07  7  BELL (BEL)
^h   BS   0x08  8  BACKSPACE (BS)
^i   HT   0x09  9  CHARACTER Tabulation (HT)
^@   LF   0x0a  Ten line  FEED (LF)
^k   VT   0x0b  Line  Tabulation (VT)
^l   FF   0x0c  FORM FEED (FF)
^m   cr   0x0d  carriage return (CR)


The first column is a special character, the second column is digraph (see below), the third column is hexadecimal, and the fourth is in decimal notation, and the official name of the character is listed.



Displays the binary encoding of the current file to enter:%!xxdThis command replaces the contents of the file! Recovery::%!xdd -r.



Second, through the digraph input



Vim obviously does not have any special character selection tools, but it provides two ways to enter special characters:



1. Enter a special character (digraph) by two characters.



2, directly through the encoded value (ASCII or Unicode) input.



Where digraph is a kind of double spell method, the continuous input two characters to represent a special character. You need to press the leading key <ctrl-k>, for example, in edit mode:


<ctrl-k>rg


The ® character will appear, where "Rg" is the character's digraph (double spell). All digraph can be done by:help digraph-tablequery.



Three, through the character encoding input



In addition to digraph, you can also enter it directly by character encoding, which does not need to be in the digraph-table of vim. This is also done in insert mode, which requires you to press the leader key<Ctrl-V>(Windows <Ctrl-Q>) first.



there are the following 5 ways:



Decimal value ascii:^vnnn (<= nnn <= 255)



Octal value: ^vonnn or ^vonnn (<= nnn <= 377)



Hexadecimal value: ^vxnn or ^vxnn (<= nn <= FF)



hexadecimal BMP unicode:^vunnnn (0000 <= nnnn <= FFFF)



Hexadecimal any unicode:^vunnnnnnnn (00000000 <= nnnnnnnn <= 7FFFFFFF)



All of these actions are performed under Unicode character encoding settings. For example:


<ctrl-v>065


A character will be output, 65 is its ASCII encoding, and Unicode is compatible with ASCII.



Iv. Search/replace/input for line wrapping



The behavior of the newline in Vim is very special and not consistent enough to be discussed separately.



First distinguish between \ R and \ n:



The former is enter (carriage return), in Vim can be entered through <C-K>CR, shown as ^m.



The latter is newline (New line), in Vim through the <CR> (enter) key input, display for carriage return and line;



So for Windows style wrap (\ r \ n) in Vim, the ^m is displayed at the end of each line.



Replace



Note Use \ r (equivalent to enter) instead of \ n when replacing with a newline (New line) using the: S command. For example, replace all commas with a newline:


:%s/,/\r/g


If you use \ n, the target is replaced with a null character null (shown as ^@).



Converting a DOS-style newline (\ r \ n) file into a Unix-style newline (\ n) is simply not necessary to manually find replacements:


: Set Fileformat=unix 
: w


Search



You should still use the \ n character when searching for a new line in search mode (/), because Vim's wrapping (Unix style) is indeed \ n rather than \ r \ n. For example:


/foo\nbar


Can be matched to all:


Foo
Bar


V. View invisible characters



In addition to special characters, there are a large number of invisible characters in the ASCII character, such as a Space carriage return tab. These characters can be controlled by the list variable to see whether they are displayed or not:


Show hidden characters
: Set list
does not show hidden characters
: Set nolist
displays which hidden characters: set
listchars=eol:$,tab:>-,trail:~, extends:>,precedes:<


Summarize



The above is the entire content of this article, I hope the content of this article for everyone's study or work can help, if there is doubt you can message exchange.


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.