In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/03 Report--
1. About Vim
Vim is my favorite editor and the second most powerful editor under linux. Although emacs is recognized as number one in the world, I don't think using emacs is as efficient as editing with vi. If you are a beginner in vi, it is a smart decision to run vimtutor. (if your system environment is not in Chinese and you want to use vimtutor in Chinese, run vimtutor zh)
1.1 several modes of Vim
Normal mode: you can use the shortcut key command, or press: enter the command line.
Insert mode: you can enter text. In normal mode, press I, a, o, etc., you can enter insert mode.
Visual mode: press v in normal mode to enter visual mode, and in visual mode, move the cursor to select text. Press V to enter visual line mode, which is always selected for the whole row. Ctrl+v enters visual block mode.
Replacement mode: in normal mode, press R to enter.
two。 Start Vim
Vim-c cmd file: execute the specified command before opening the file
Vim-r file: restore the file that exited abnormally last time
Vim-R file: open a file read-only, but you can force a save
Vim-M file: open a file as read-only and cannot be forced to save
Vim-y num file: sets the size of the editing window to the num line
Vim + file: start at the end of the file
Vim + num file: start at line num
Vim + / string file: open file and pause the cursor over the first found string.
Vim-- remote file: opens the specified file with an existing vim process. This is useful if you don't want to enable multiple vim sessions. Note, however, that if you use vim, you will look for a server called VIM; if you already have a gvim running, you can use gvim-remote file to open the file in the existing gvim.
3. Document operation
: e file-closes the currently edited file and opens a new one. If changes to the current file are not saved, vi warns you.
: e! File-discard changes to the current file and edit the new file.
: e+file-- start a new file and edit it from the end of the file.
: eRecn file-- start a new file and edit it from line n.
: enew-- compiles a new unnamed document. (CTRL-W n)
: e-- reload the current document.
: e!-- reload the current document and discard the changes you have made.
: e # or ctrl+ ^-- it's useful to go back to the file you just edited.
: F or ctrl+g-- displays the document name, whether to modify it, and the cursor location.
F filename-- change the name of the edited file, and save it at this time is equivalent to saving as
Gf-- Open a file with the file name of the string where the cursor is located.
W-- Save the changes.
N1 filename-selectively saves content from one N1 line to another N2 line.
: wq-- Save and exit.
ZZ-- Save and exit.
: X-- Save and exit.
Q [uit]-- exits the current window. (CTRL-W Q or CTRL-W CTRL-Q)
: saveas newfilename-- Save as
: browse e-opens a file browser that allows you to select a file to edit. If it is in the terminal, the file browsing window of netrw will be opened; if it is gvim, a browsing window of graphical interface will be opened. In fact: after browse, you can follow any command to edit the document, such as sp, etc. The starting directory opened with browse can be set by browsedir:
: set browsedir=last-- use the last visited directory (default)
: set browsedir=buffer-- use the directory where the current file is located
: set browsedir=current-- use the current working directory
Sex-split a window horizontally to browse the file system
Vex-split a window vertically and browse the file system
4. Movement of the cursor 4.1 basic movement
The following moves are all in normal mode.
H or backspace: move one character to the left
L or space: move one character to the right
J: move down one line
K: move up one line
Gj: move to the next line within a paragraph
Gk: move to the previous line within a paragraph
+ or Enter: move the cursor to the first non-white space character on the next line.
Move the cursor to the first non-white space character on the previous line.
W: move forward one word and the cursor stops at the beginning of the next word
W: move the beginning of the next word, but ignore some punctuation
E: move forward one word and the cursor stops at the end of the next word
E: move to the end of the next word, or if there is punctuation at the end of the word, move to punctuation
B: move back one word and the cursor stops at the beginning of the previous word
B: move to the beginning of the previous word and ignore some punctuation
Ge: move back one word, and the cursor stops at the end of the previous word.
GE: the same as ge, but the word contains punctuation adjacent to the word.
(: move forward 1 sentence.
): move back 1 sentence.
{: move forward 1 paragraph.
}: move back 1 paragraph.
Fc: move the cursor to the next c character on the same line
Fc: move the cursor to the previous c character on the same line
Tc: move the cursor before the next c character on the same line
Tc: move the cursor after the last c character on the same line
;: use it with f & t, repeat it
Use it with f & t and repeat it in reverse
All of the above operations can be used with n, for example, enter 3h in normal mode (described below) and the cursor moves 3 characters to the left.
0: move to the beginning of the line.
G0: move to the beginning of the screen line where the cursor is located.
^: move to the first non-white space character on this line.
G ^: same as ^, but move to the first non-empty character in the current screen line.
$: move to the end of the line.
Move: move the end of the screen line where the cursor is located.
N |: move the cursor over the n column.
NG: to the nth line of the file.
: n move to line nth.
Move $to the last line.
H: move the cursor to the top line of the screen.
M: move the cursor to the middle line of the screen.
L: move the cursor to the bottom line of the screen.
Gg: to the file header.
G: to the end of the file.
4.2 flipping the screen
Ctrl+f: flip down one screen.
Ctrl+b: flip up the screen.
Ctrl+d: flip down half the screen.
Ctrl+u: flip half of the screen up.
Ctrl+e: scroll down one line.
Ctrl+y: scroll up one line.
N%: to the location of the file n%.
Zz: moves the current line to the center of the screen.
Zt: moves the current line to the top of the screen.
Zb: moves the current line to the bottom of the screen.
4.3 Mark
Use tags to move quickly. When the mark is reached, you can use Ctrl+o to return to the original location. Ctrl+o and Ctrl+i are a lot like backwards and forwards on browsers.
M {a murz}: marks the location of the cursor, local markup, and is used only for the current file.
M {Amurz}: Mark the location of the cursor, the global tag. After the tag, exit Vim, restart, and the tag is still valid.
`{amurz}: move to the tag location.
'{amurz}: move to the beginning of the tag line.
`{0-9}: return to the last position you left when you closed vim for the last [2-10] times.
``: move to the last edited location.'' Yes, but ``accurate to the column and''to the row.
`": move to the place where you left last time.
`.: move to the last change.
: marks displays all tags.
: delmarks a b-- delete tags an and b.
: delmarks a murc-- delete the tags a, b and c.
: delmarks a cmurf-- delete the markers a, c, d, e, f.
: delmarks!-- removes all tags from the current buffer.
Help mark-motions to see more knowledge about mark
5. Insert text 5.1 basic insert
I: insert in front of the cursor; a tip: press 8, press I, enter insert mode, enter =, press esc to enter command mode, there will be 8 =. This is very useful when inserting splitters, such as 30i + with 36 + splitters.
I: insert before the first non-empty character in the current line
GI: insert in the first column of the current row
A: insert after the cursor
A: insert at the end of the current line
O: create a new row below to insert
O: create a new row above to insert
R filename inserts the contents of another file at the current location.
: [n] r filename inserts the contents of another file on line n.
R! date inserts the current date and time at the cursor. Similarly,: r! command can insert the output of other shell commands into the current document.
5.2 overwrite insert
C [n] w: 1 (n) words after rewriting the cursor.
C [n] l: n letters after rewriting the cursor.
C [n] h: rewrites the first n letters of the cursor.
[n] cc: modify the current [n] line.
[n] s: replace 1 (n) characters after the cursor with the entered text, which is equivalent to c [n] l.
[n] S: delete the specified number of lines and replace them with the entered text.
Note that a form similar to cnw,dnw,ynw can also be written as ncw,ndw,nyw.
6. Cut copy and register 6.1 cut and copy, paste
[n] x: cut n characters to the right of the cursor, equivalent to d [n] l.
[n] X: cut n characters to the left of the cursor, equivalent to d [n] h.
Y: copy the text selected in visual mode.
Yy or Y: copy the entire line of text.
Y [n] w: copy one (n) word.
Y [n] l: copy 1 (n) characters to the right of the cursor.
Y [n] h: copy 1 (n) characters to the left of the cursor.
Copy: copy from the current position of the cursor to the end of the line.
Y0: copy from the current position of the cursor to the beginning of the line.
: mpenny copy the contents of m lines to n lines.
Y1G or ygg: copy all lines above the cursor.
YG: copy all lines below the cursor.
Yaw and yas: copy a word and a sentence, even if the cursor is not at the beginning of the word and sentence.
D: delete (cut) selected text in visual mode.
D $or D: delete (cut) the content from the current position to the end of the line.
D [n] w: delete (cut) 1 (n) words
D [n] l: delete (cut) 1 (n) characters to the right of the cursor.
D [n] h: delete (cut) 1 (n) characters to the left of the cursor.
D0: delete (cut) the content from the current position to the beginning of the line
[n] dd: delete (cut) 1 (n) line.
: mdjnd cuts the contents of m lines to n lines.
D1G or dgg: cut all lines above the cursor.
DG: cut all lines below the cursor.
Daw and das: cut a word and a sentence, even if the cursor is not at the beginning of the word and the beginning of the sentence.
Dhand f: this is a more advanced combination command that removes the content from the current location to the next f.
P: paste after the cursor.
P: paste before the cursor.
6.2 text object
Aw: one word
As: one sentence.
Ap: one paragraph.
Ab: a piece (enclosed in parentheses).
Y, d, c, v can all follow text objects.
6.3 register
"ayy puts the contents of the current line in register a.
Amurz: use uppercase letters to index registers, and you can append content to registers. For example, "Ayy appends the contents of the current line to the a register.
: reg displays the contents of all registers.
"": the register used by default when no register index is added.
"*: current selection buffer," * yy puts the contents of the current line into the current selection buffer.
"+: system clipboard." + yy puts the contents of the current line on the system clipboard.
7. Find and replace 7.1 find
/ something: look for something in the following text.
? something: look for something in the previous text.
/ pattern/+number: pause the cursor over the number line after the line that contains pattern.
/ pattern/-number: pause the cursor over the number in front of the line that contains pattern.
N: look back for the next one.
N: look forward to the next one.
You can use grep or vimgrep to find out where a pattern has appeared
Among them: grep is to call the external grep program, and: vimgrep is vim's own search algorithm.
Usage:: Vim [GREP] / pattern/ [g] [j] files
G means that if a pattern appears multiple times in a line, the line also appears multiple times in the result.
J means that after the end of grep, the result stops at item j, and the default is to stop at the first item.
Vimgrep can be preceded by a number to limit the upper limit of search results, such as
: 1vim/pattern/% only looks for the first occurrence of that pattern in this file.
In fact, vimgrep is particularly useful when reading plain-text e-books and can generate navigation directories.
For example, the title of each section in an e-book is: n. Xxxx. You can do this:
: vim/ ^ d {1,}. /%
Then use: cw or: copen to view the results. You can use Cmurw H to move the quickfix window to the left.
It's more like a catalog.
7.2 replace
: s/old/new-replaces the first old in the current line with new.
: s/old/new/g-replaces all old in the current line with new.
: N1 new n2sAccord new old g-replace all the Lines N1 to N2 of the file with Universe.
:% s/old/new/g-replace all old in the file with new.
:% s / ^ / xxx/g-insert xxx at the beginning of each line, and ^ represents the beginning of the line.
:% s/$/xxx/g-insert xxx,$ at the end of each line to indicate the end of the line.
Add c at the end of all replacement commands, and each replacement will require user confirmation. For example:% s/old/new/gc, plus I ignores case (ignore).
There is also a more flexible way than replacing, which is to execute a command after matching to a certain pattern.
The syntax is: [range] g/pattern/command
For example:% g / ^ xyz/normal dd.
Indicates that the dd command in normal mode is executed for lines that begin with a space and xyz.
The regulations on range are:
If range is not specified, it represents the current line.
M line n: from m lines to n lines.
0: the first line (probably so).
$: last line
.: current line
%: all Lin
7.3 regular expression
Regular expressions are used for advanced lookup replacements.
\ d: represents a decimal number (my guess)
\ s: represents a space
\ s: non-null character
\ a: English alphabet
\ |: indicates or
\. Means.
{mdirection n}: indicates m to n characters. This should be used in conjunction with\ s and\ a, for example,\ a\ {mrecoery n} denotes m to n letters.
{m,}: represents m to an infinite number of characters.
* *: all subdirectories under the current directory.
Help pattern gets more help.
8. Typesetting 8.1 basic typesetting
Indent a shiftwidth to the right
: ce (nter) text on this line is centered
: le (ft) text on this line to the left
: ri (ght) text on this line to the right
Gq rearranges the selected text, that is, breaks the long text.
Gqq reschedule the current line
Gqnq reschedule n lines
Gqap reschedule current segment
Gqnap rearranging n segments
Gqnj rearranges the current line and the following n lines
GqQ rearranges the current paragraph to the end of the article
J splices the current line and the next line
GJ is the same as J, but no spaces are left after the merger.
8.2 spell check
Set spell- enables the spell check function
Set nospell- turns off the spell check function
] s-move to the next misspelled word
[s-works similar to the previous command, but it searches in the opposite direction
Zoning-displays a list of misspelled words from which you can choose
Zg- tells the spelling checker that the word is spelled correctly
Zw-, contrary to the previous command, tells the spelling checker that the word is misspelled
8.3 word count
G ^ g can count the number of characters and lines of a document. Place the cursor over the last character and use the number of characters minus the number of lines to roughly count the number of words in a Chinese document. The above applies to Mac or Unix file formats. For Windows file format (that is, the newline character has two bytes), the word count method is: number of characters-number of lines * 2.
9. Edit multiple Files 9.1 Edit multiple files at a time
We can open multiple files at a time, such as
Vi a.txt b.txt c.txt
Use: next (: n) to edit the next file.
: 2n edit the next 2 files.
Use: previous or: n to edit the previous file.
Use: wnext, save the current file, and edit the next file.
Use: wprevious, save the current file, and edit the previous file.
Use: args to display a list of files.
: n filenames or: args filenames specifies a new file list.
Vi-o filenames edits multiple files in multiple windows split horizontally.
Vi-O filenames edits multiple files in vertically split windows.
9.2 Multi-tag editing
Vim-p files: open multiple files, each occupying a tag page.
: tabe, tabnew-- if you add a file name, open the file in a new tag, otherwise open an empty buffer.
W gf-opens the file specified in the path under the cursor in a new tab.
: tabn-- switch to the next tab. Control + PageDown is also possible.
: tabp-- switch to the previous tab. Control + PageUp is also possible.
[n] gt-- switch to the next tab. If n is added in front of it, switch to the nth label. The serial number of the first label is 1.
: tab split-- opens the contents of the current buffer in a new tab.
: tabc [lose]-closes the current tab.
: tabo [nly]-- close other tabs.
: tabs-lists all tabs and the windows they contain.
: tabm [ove] [N]-- move the tab after the nth tab. For example, the current tab of tabm 0 becomes the first tab.
9.3 buffer
: buffers or: ls or: files displays a list of buffers.
Ctrl+ ^: toggles between the last two buffers.
: bn-- next buffer.
: bp-- the last buffer.
: bl-the last buffer.
: B [n] or: [n] b-- switch to the nth buffer.
: nbw (ipeout)-- completely delete the nth buffer.
: nbd (elete)-- deletes the nth buffer, which is not really deleted, and is still in the unlisted list.
Ba [ll]-- opens all buffers in the current page, each occupying a window.
10. Split-screen editing
Vim-o file1 file2: split the window horizontally, opening both file1 and file2
Vim-O file1 file2: split the window vertically and open both file1 and file2
10.1 split horizon
: split (: sp)-- split the current window horizontally into two windows. (CTRL-W s or CTRL-W CTRL-S) Note that if CTRL-S may freeze the terminal under the terminal, press CTRL-Q to continue.
: split filename-split the window horizontally and display another file in the new window.
: nsplit (: nsp)-split horizontally into a window that is n rows high.
[n] new-split an N-line high window horizontally and edit a new file. (CTRL-W n or CTRL-W CTRL-N)
Ctrl+w f-split a window horizontally and open a file with the name of the cursor in the new window.
Cmurw C-^-split a window horizontally and open the file you just edited.
10.2 Vertical split
: vsplit (: vsp)-- splits the current window into two horizontally distributed windows. (CTRL-W v or CTRL CTRL-V)
[n] vne [w]-- split a new window vertically.
Vertical horizontal split command: the corresponding vertical split.
10.3 close the child window
: qall-- close all windows and exit vim.
: wall-- saves all modified windows.
: only-- keep only the current window and close other windows. (CTRL-W o)
: close-- close the current window, CTRL-W c can achieve the same function. (for example: Q: X also works)
10.4 resize the window
Ctrl+w +-the current window is one line higher. You can also use n to increase n lines.
Ctrl+w-the current window is reduced by one line. You can also use n to decrease n lines.
Ctrl+w _-- the current window expands to as large as possible. You can also set the number of rows with n.
: resize n-- the current window has n rows high.
Ctrl+w =-- all windows are the same height.
N ctrl+w _-the height of the current window is set to n rows.
Ctrl+w
< --当前窗口减少一列。也可以用n减少n列。 ctrl+w >The current window widens by one column. You can also widen n columns with n.
Ctrl+w |-the current window is as wide as possible. You can also set the number of columns with n.
10.5 switch and move window
If the mouse is supported, it is easy to switch and resize the child window.
Ctrl+w ctrl+w: switch to the next window. Or ctrl+w w.
Ctrl+w p: switch to the previous window.
Ctrl+w h (ljjjjjjjjk): switch to the left (right, bottom, top) window.
Ctrl+w t (b): switch to the window on the top (bottom) face.
Ctrl+w H (LMagneKPerry J): moves the current window to the leftmost (right, top, bottom) face.
Ctrl+w r: the position of the rotation window.
Ctrl+w T: moves the current window to a new tab.
11. Quick edit 11.1 change case
~: reverses the case of the character in which the cursor is located.
U or u in visual mode: changes the selected text to uppercase or lowercase.
Gu (U) with a range (such as $, or G) that converts all letters from the current position of the cursor to the specified position to lowercase or uppercase. GgguG, for example, lowercase all the letters from the beginning to the last line. Another example is gu5j, which lowercase the current line and the following four lines.
11.2 replacement (normal mode)
R: replace the characters at the cursor and also support Chinese characters.
R: enter replacement mode and press esc to return to normal mode.
Undo and redo (normal mode)
[n] u: cancel one (n) changes.
: undo 5-undo 5 changes.
: undolist-- your revocation history.
Ctrl + r: remake the last changes.
U: cancels all changes in the current line.
: earlier 4m-- go back to 4 minutes ago
: later 55s-- 55 seconds ahead
11.4 Macro
. -- repeat the previous editing action
Qa: start recording macro a (keyboard operation record)
Q: stop recording
@ a: play the macro a
twelve。 Edit special file 12.1 file encryption and decryption
Vim-x file: start editing an encrypted file.
: X-- sets the password for the current file.
: set key=-- removes the password of the file.
12.2 Encoding of Files
: e + + enc=utf8 filename, let vim open the file with utf-8 encoding.
W + + enc=gbk, no matter what encoding the current file is, save it to gbk encoding.
: set fenc or: set fileencoding to view the encoding of the current file.
Adding set fileencoding=ucs-bom,utf-8,cp936,vim to vimrc selects the appropriate encoding based on the file you want to open. Note: do not leave spaces between codes. Cp936 corresponds to gbk encoding. Ucs-bom corresponds to the file format under windows.
Making vim handle the file format and encoding correctly depends on the correct configuration of ~ / .vimrc.
12.3 file format
There are roughly three file formats: unix, dos, mac. The difference between the three formats mainly lies in the coding of the enter key: enter plus newline under dos, newline only under unix, and carriage return only under mac.
: e + + ff=dos filename, let vim open the file in dos format.
W + + ff=mac filename, which stores this file in mac format.
: set ff, which displays the format of the current file
Add set fileformats=unix,dos,mac to vimrc to let vim automatically recognize the file format.
13. Programming assist 13.1 some keys
Gd: jump to the definition of a local variable
GD: jump to the definition of the global variable and start the search at the beginning of the current file
GTX: the last modified place
Gmail: the next place to be modified
[: jump to the start of the previous function block, you need to have a separate line of {.
]]: jump to the start of the next function block, which requires a separate line of {.
[]: jump to the end of the previous function block, which requires a separate line}.
[: jump to the end of the next function block, which requires a separate line}.
[{: jump to the beginning of the current block
]}: jump to the end of the current block
[/: jump to the beginning of the current comment block
] /: jump to the end of the current comment block
%: can not only move to the matching (), {} or [], but also jump between # if,#else, # endif.
The parenthesis matching below is useful for programming.
Ci', di', yi': modifies, cuts, or copies the content between'.
Ca', da', ya': modifies, cuts or copies the contents between', including'.
Ci ", di", yi ": modify, cut or copy".
Ca ", da", ya ": modify, cut or copy the content between, including".
Ci (, di (, yi (: modify, cut or copy the content between ().
Ca (, da), ya (: modify, cut or copy the contents between (), including ().
Ci [, di [, yi [: modify, cut or copy the content between [].
Ca [, da [, ya [: modify, cut or copy the content between [], including [].
Ci {, di {, yi {: modify, cut or copy the content between {}.
Ca {, da {, ya {: modify, cut or copy the content between {}, including {}.
Ci
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.