vim operation backup

vim is a very powerful editor

You can open multiple files at the same time under vim

1. You can open multiple files at the same time in the vim editor. The basic commands are as follows:

Suppose you now want to edit file a.txt and file b.txt

1)vi   a.txt    b.txt 

2): n  next file;

3): previous file;

4): wq!  save all and exit;

5): split  (abbreviation: sp ) sets the horizontal split screen;

6): vsplit (abbreviation: vsp ) to set vertical split screen;

7): only  cancel split screen;

8) ctrl + ww  the next file, Ctrl + wp  the previous file, in fact, you can use one of the commands to switch.

 Replenish:

 Split screen starts Vim
 with an uppercase O parameter to split the screen vertically.
 vim -On file1 file2 ...
 uses the lowercase o parameter to split the screen horizontally.
 vim -on file1 file2 ...
 Note: n is a number, indicating that it is divided into several screens.

 Close split screen 
 closes the current window.
 Ctrl+W c
 closes the current window, and if there is only one left, exits Vim.
 Ctrl+W q
 Split screen
 to split the currently open file up and down.
 Ctrl+W s
 to split up and down and open a new file.
 :sp filename
 splits the currently open file left and right. 
 Ctrl+W v
 split left and right, and open a new file.
 :vsp filename
 Move the cursor
 The cursor keys in Vi are h, j, k, l. To switch between screens, just press Ctrl+W


 to move the cursor to the screen on the right.
 Ctrl+W l Move
 the cursor to the left screen.
 Ctrl+W h
 moves the cursor to the upper screen.
 Ctrl+W k
 moves the cursor to the lower screen.
 Ctrl+W j
 moves the cursor to the next screen. .
 Ctrl+W w
 move split screen
 This function still uses Vim's cursor keys, but they are all uppercase. Of course, if your split screen is messy and complicated, this feature can have some very strange symptoms.


 move to the right.
 Ctrl+WL
 move left 
 Ctrl+WH
 move up 
 Ctrl+WK
 move down 
 Ctrl+WJ
 Screen size
 Below are some operations to change the size, mainly height, for width you can use Ctrl+W < or >, but this may The latest version is required for support.

 Make all screens the same height.
 Ctrl+W =
 Increase height.
 Ctrl+W +
 Decrease height.
 Ctrl+W -


2. Copy and paste  

  1. Copy the content to the selection buffer.

    • With line numbers, use the mouse to select the content area.
    • No line numbers, use "yny to copy n lines or select in visual mode. If the copy is successful, you will be prompted to copy several lines.
  2. Paste the contents of the selection buffer into the vim file: press "p" in normal mode 

  3. Cut a file command mv, copy a file command cp;

3. Querying the dynamic link library depends on which file:

       dnf   whatprovides libz.so.1

    zlib-1.2.8-3.fc20.i686 : The compression and decompression library
    source: fedora
    match source:
    provide: libz.so.1

    从打印信息中得知缺少库zlib-1.2.8-3.fc20.i686
     dnf install zlib-1.2.8-3.fc20.i686

四、linux多个文件压缩打包到一个压缩文件 

   多个文件压缩打包 tar czvf my.tar.gz file1 file2,...(file*)

五、在vim下搜索关键字

/[关键字]

按(shift +8)表示从上向下搜索

按(shift + 3)表示从下向上搜索


六、关于折叠操作

set foldmethod=indent "set default foldmethod


  zi 打开关闭折叠(打开关闭所有折叠)
zv 查看此行
zm 关闭折叠
zM 关闭所有
zr 打开
zR 打开所有
zc 折叠当前行
zo 打开当前折叠
zd 删除折叠
zD 删除所有折叠


七 、通过该种方式可非常方便各文件内容之间的复制与剪切操作,这里顺便简单提一下复制,剪切与粘贴操作命令

yy     复制光标所在行

dd     剪切光标所在行

5yy    复制从光标所在行开始计数的下五行文本

5dd    剪切从光标所在行开始计数的下五行文本

v(小写)      visual模式,通过上下左右键选择光标“扫过”的所有字符

V (大写)    visual line 模式,通过上下键选择光标“扫过”的所有行

ctrl + v        visual block 模式,通过上下左右键选择一个矩形文本

y    复制在visual模式, visual line模式和visual block 模式下选择的文本

d    剪切在visual模式, visual line模式和visual block 模式下 选择的文本

p(小写)  粘贴,  粘贴位置为光标所在行的下一行

P(大写)  粘贴,  粘贴位置为光标所在行的上一行

u: 撤销操作

r: 重做操作


八、如果你想在当前目录下 查找"hello,world!"字符串,可以这样: 

grep -rn "hello,world!" * 

* : 表示当前目录所有文件,也可以是某个文件名

-r 是递归查找

-n 是显示行号

-R 查找所有文件包含子目录

-i 忽略大小写


下面是一些有意思的命令行参数: 

grep -i pattern files :不区分大小写地搜索。默认情况区分大小写, 

grep -l pattern files :只列出匹配的文件名, 

grep -L pattern files :列出不匹配的文件名, 

grep -w pattern files :只匹配整个单词,而不是字符串的一部分(如匹配‘magic’,而不是‘magical’), 

grep -C number pattern files :匹配的上下文分别显示[number]行, 

grep pattern1 | pattern2 files :显示匹配 pattern1 或 pattern2 的行, 

grep pattern1 files | grep pattern2 :显示既匹配 pattern1 又匹配 pattern2 的行。


九、杀死一个进程

kill -s 9 进程号

Guess you like

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