Linux vim use and iconv garbled solution

target content
Use of vim editor and
Garbled solution


1. Use of vim editor and
check whether the system has VIM tool installed
[root@xuegod72 ~]# rpm -qf `which vim`
[root@xuegod72 ~]# rpm -qf `which vi`
[root@xuegod72 ~]# cd /media/Packages/
[root@xuegod72 Packages]# rpm -ivh vim-
vim-common-7.4.160-1.el7.x86_64.rpm
vim-enhanced-7.4.160-1.el7.x86_64.rpm
vim- filesystem-7.4.160-1.el7.x86_64.rpm
vim-minimal-7.4.160-1.el7.x86_64.rpm
vim-X11-7.4.160-1.el7.x86_64.rpm
to install
[root@xuegod72 Packages ]# rpm -ivh vim-enhanced-7.4.160-1.el7.x86_64.rpm
Q: Are vi and vim installed in the same software package?
A: No, vim is an enhanced version of vi, the most obvious difference is Vim can syntax highlight, it is fully compatible with vi

vim mode switch
to enter the file for the first time ---- command mode
appears Insert ---- edit mode
input " : " ---- command line mode

A: How to switch from edit mode to command line mode?
Edit mode->esc->command mode->:->command line mode
B: Character operation (how to enter edit mode?)
Enter edit mode aio AIO
Description:
 i current Insert before character (before cursor)
 I Insert at beginning of line (beginning of line) 
a Insert after current character (behind cursor)
 A Insert at end of line (end of line)
 o Insert at next line (start from new line)
 O Insert at previous line (Insert previous line)
 x delete one character backward is equivalent to delete
 X delete one character forward    
 u undo one step undo one step at a time
 r replace

line
operation type home key or ^ (shift +6) to move cursor Go to the beginning of the current line
Enter  end key or $ (shift +4) to move the cursor to the end of the current line to

delete the line
dd Delete a line of numbers + dd Delete multiple lines 
Delete the entire content after the cursor d+G 

Display the line number: set nu

Copy and paste
yy Copy a line of numbers + yy Copy N lines
p Paste the

copied 38-42 to line 44
: 38,42 co 44

Expansion: cut
Delete first, then paste
Delete to the beginning of the line d + HOME or ^ (shift+6)
Delete to the end of the line d + END or $ (shift+4)

V mode
to enter v mode to move the cursor to select the area,
multi-line programming is required Comment:
1), ctrl+v to enter column editing mode
2), move the cursor down or up
3), mark the beginning of the line that needs to be commented
4), then press uppercase I
5), and then insert a comment, such as "#"
6), press Esc again, all comments will be

deleted Delete : press ctrl+v again to enter the column editing mode; move the cursor down or up; select the comment part, and then press d, the comment symbol will be deleted.

Command line mode operation
 :w save save
 :q do not make any changes, exit quit
 :q! make changes, do not save, force exit
 :wq save and exit
 :wq! force save and exit
 :x save and exit

Calling an external file or command
Hypothesis: I want to edit and write the address of my network card, but I forgot, I want to check, I am currently editing the document in vim
What should I do? Do you want to exit the document? This is so troublesome.
In command line mode The following operations:
 :!ifconfig call system command
 !+command

substitution (command line mode)
Format: % all content s replace old content new content 
defaults to the first matching word of each line (/g all)

:% s/a/b the first a of each line is replaced by b
:% s/a/b/g Replace all a's in the text with b's

and only replace certain lines of content
: 2,3 s/a/b
/g all
#replace 2 to 3 lines of a

How do we know if it's the second line or What about the third line?
:set nu #Display line number
:set nonu #Do not display line number

Search
/forward search: /san n search down, N search up


Locate
a line in vim:
operate in command mode gg locates the first line of the file and operates
in the command mode G locates the end of the file
in the command line mode: # locates a certain line (# indicates the line number)
to the command mode and operates 10gg


reads other files
in the command line mode
: r /etc/passwd
save and exit :wq

display the line number when outputting the contents of the file:
[root@xuegod72 ~]# nl
b.txt [root@xuegod72 ~]# cat -n b.txt

vim opens multiple files:
[root@xuegod72 ~]# vim -o /etc/passwd /etc/hosts
[root@xuegod72 ~]# vim -O /etc/passwd /etc/hosts

ctrl+ww switch between files,
uppercase O, left and right split screen , lowercase o upper and lower split screen
Compare file content
vimdiff File A File B


garbled solution
Use garbled solution tool iconv
[root@xuegod60 ~]# rpm -qf `which iconv`
glibc-common-2.17-105.el7.x86_64

If not installed , use the following command to install
[root@xuegod60 ~]# rpm -ihv /mnt/Packages/glibc-common-2.17-105.el7.x86_64.rpm

Transcode
input/output format specification by iconv command:
 -f, - -from-code=Name original text encoding
-o, --output=FILE output
file -l, --list list all known character sets
Note: GB2312 encoding is suitable for Chinese character processing

[root@xuegod60 ~]# iconv -f gb2312 test.txt -o new.txt

[root@xuegod60 ~]#echo $LANG
[root@xuegod60 ~]#LANG=zh_CN.UTF-8

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326275408&siteId=291194637