Linux command in vim editor

vim

  Features: a powerful text editor
   syntax: vim [option] / path / filename command text format: vi [options] [filename]
   + num open a file to jump directly to num lines
   -b in a binary way open files, binary files for editing
   -R open the file in read-only

A .VIM basis using
    vim editor There are three operating modes

command line mainly do replace, delete, copy, and so on. input mode mainly to do content editors
last line mode used for file editing operations such as saving files

   Switching between different modes

II. Command Mode

       When command mode operation is executed first to move the cursor to where you want to execute commands and then execute the command,

How to move the cursor it?

   Move the cursor down j 
   k cursor up 
   move the cursor to the left h 
   l cursor to the right

If you remember that these can also be used on the less convenient keypad ← ↑ → ↓ instead of G (shift + g) is directly moved to the end of file

 gg move directly to the file header
  0 (numeric key) to move directly to the line head
  ^ (Shift + 6) directly to the line head
  $ directly move the end to the line
  PageUp turned up a
  PageDown scroll down a
  H Move the cursor to the current screen uppermost M move the cursor to the middle of the current screen L move the cursor to the lowest current screen
  zz the cursor to the current behavior of the reference in the middle of the screen x delete the cursor position character
  position before cursor to delete X a character D from the cursor to the beginning to the end of the line Remove all
  line dw a word dd after the cursor is deleted to delete the cursor
  in front db delete the cursor one word
  dG delete the cursor line to the end of the file of all the content dgg all content dk delete the cursor line to the file header of the cursor to delete rows and the top line
  dj delete the cursor line and the following line
  u undo earlier operations, continuous use U undo all operations in a row
  ctrl + r cancel the revocation of content
  ctrl + g to display information about the current edit the file, such as file name, a total of the number of rows, like the current percentage of the total number of information
  % to move the cursor symbol pair as (Type% can be automatically moved to a paired) similarly applicable [] and {} which is especially useful when programming in
  . The point, the function of this key is a command repeat the last execution
  g ~ this is very interesting, g ~ can the case of the current row conversion
  function J is the key to the current and next line cursor merge Note: this key can not be digitally
 r replacement character cursor 
 R successive replacement 
 y replication, such as a copy yw copy word line yy 
 p paste (after the cursor) P attached (before the cursor)

 

V basis using a VIM command line key: This key is used instead of the mouse used. v means 'visible' means, through the press key v later can use arrow keys to select the text above as a mouse, may then operate on the selected text.
Uppercase V key: This key is used to select a row
ctrl + v to select a column

(1) Find the VIM
    in command mode, press / to enter the search mode search here using regular expressions, if you are looking for. * [] ^% / \? ~ $ These characters have special meaning needs before those characters plus \ escape character. Exact search
   such as the need to use / \ <the \> to continue the search to find down by n,
   by N return a search.

(2) mode switching command input mode
  

    After inserting a cursor starts (corresponding insert key) 
    I began to be inserted before the cursor 
    A is initially inserted into the end of the cursor line 
    I in the first row to start inserting o O cursor row is inserted at the cursor line is inserted into the cursor line on the line into the replacement mode R 
    s after the start editing cursor row s delete start character editing cursor after replacing

  

(3) line mode last line mode
    in command mode Press: (shift +;) button, to enter the line mode.
   

    :w 保存文件
    :q 退出 vi 编辑
    :wq 保存文件并退出 vi 编辑器 ( 无论是否修改了文件 )
    :x 保存退出
    ZZ 保存退出
    :e 不离开 VI ,开始编辑一个新的文件
    :w <filename-new> 存储当前编辑的文件到一个新的文件(另存 为)
    :x 文件仅被修改时才写入 并退出 , 未写入则直接退出
    :q! 这个 ! 具有强制的作用 , 因为在 vi 中默认不保存文件是无法 退出 vi 编辑器的 , 主要为了防止意外退出。
    :w! 强制保存 , 有的时候文件是只读属性的时候 ,可以用这个方式 来保存 , 当然前提是文件所有者必需是当前用户。

 

(4)末行模式 查找和替换 查找格式
    :范围 命令/查找字串/替换字串/ 参数
    查找范围:
    % 所有的行
    $ 文件最后一行
    . 光标所在行
    1,50 1-50行

命令:
  查找的命令全称是 substitute但为了方便期间可以使用简写 sub 或者干脆用 s 这三个单词都可以用做查找的命令查找。查找的内 容中可以使用正则表达式 , 这样可以让查找方式非常灵活多变 替换的内容当然就是替换的内容了最后的参数有很多 , 可以同时 使用多个参数
  g 替换所有查找到的内容
  c 每次替换的时候都手工确认 y 同意 n不同意仍然继续替换, q 退出替换
  i 忽略大小写
  I 不忽略大小写
  e 不显示出错信息

  示例:

 :% s/root/--linux--/g
 :% s/\/usr\/bin/\/home/g
 :% s/^/linux/g
 :% s/$/s/g

精确查找替换     :% s/\<bin\>/----------------/g

 :set nu 显示行号 , 打开这个功能以后会在每一行的最左面显示 行号 , 行号不算在文件本身
 :set nonu 关闭显示行号的功能
 :set nohlsearch 消除搜索的记号
 :set ic 忽略大小写 , 主要是为了方便搜索
 :set noic 不忽略大小写
 :syntax on 打开色彩支持 , 在 linux 中编辑文件和编辑程序源代 码等工作都是在 vim 中完成的 , 打开色彩支持可以在查看或编写 程序的时候发现语法等错误
 :syntax off 关闭色彩支持

  

 

Guess you like

Origin www.cnblogs.com/t-ym/p/11617420.html