日本熟妇hd丰满老熟妇,中文字幕一区二区三区在线不卡 ,亚洲成片在线观看,免费女同在线一区二区

Vim常用操作

Vim是從vi發展而來的文本編輯器,可以用顏色或底線等方式來顯示一些特殊的信息。Vim是Linux中必不可少的工具,搭建網站修改配置文件時經常用到。本教程介紹Vim編輯器的基本命令和常用操作。

背景信息

Vim的各個模式介紹如下表所示:

模式

作用

模式轉換

普通模式

(Normal Mode)

在該模式下,您可以復制、粘貼、刪除字符或行。

  • 運行vim <文件名>打開文件時,即進入普通模式。

  • 在其他四個模式下,按Esc鍵即進入普通模式。

插入模式

(Insert Mode)

在該模式下,您可以插入字符。

在普通模式下,按i,I,a,A,o,O中任一字符即進入插入模式。

說明

進入插入模式后,編輯器左下角會顯示-- INSERT --

替換模式

(Replace Mode)

在該模式下,您可以替換字符。

在普通模式下,按R即進入替換模式。

說明

進入替換模式后,編輯器左下角會顯示-- REPLACE --。

可視模式

(Visual Mode)

在該模式下,您可以選擇文本。命令(如,復制、替換、刪除等)僅作用于選中的文檔。

在普通模式下,按v即進入可視模式。

說明

進入可視模式后,編輯器左下角會顯示-- VISUAL --

命令模式

(Command Mode)

在該模式下,您可以查找字符串、替換字符串、顯示行號、保存修改、退出編輯器等。

在普通模式下,按:即進入命令模式。

Vim的常用操作包括以下三種:

插入

基本命令:

  • i:在當前字符的左邊插入。

  • I:在當前行的行首插入 。

  • a:在當前字符的右邊插入。

  • A:在當前行的行尾插入。

  • o:在當前行下面插入一個新行。

  • O:在當前行上面插入一個新行。

本示例中使用的example.conf文件,如下所示:

# To be able to use the functionality of a module which was built as a DSO you
# have to place corresponding `LoadModule' lines at this location so the
# directives contained in it are actually available _before_ they are used.
# Statically compiled modules (those listed by `httpd -l') do not need
# to be loaded here.
#
# Example:
# LoadModule foo_module modules/mod_foo.so
#
Include conf.modules.d/*.conf            
  • 示例一:在配置文件example.conf的第一行,插入Location。步驟如下:

    1. 運行vim example.conf命令打開文件,進入普通模式。

    2. i進入插入模式。

    3. 輸入Location。

    4. 按回車鍵換行。

    5. Esc鍵退出插入模式。

    6. 輸入:wq保存文件并退出。

      插入完成后,example.conf文件如下所示:

      Location
      # To be able to use the functionality of a module which was built as a DSO you
      # have to place corresponding `LoadModule' lines at this location so the
      # directives contained in it are actually available _before_ they are used.
      # Statically compiled modules (those listed by `httpd -l') do not need
      # to be loaded here.
      #
      # Example:
      # LoadModule foo_module modules/mod_foo.so
      #
      Include conf.modules.d/*.conf            
  • 示例二:在配置文件example.conf第十行的行首,插入#。步驟如下:

    1. 運行vim example.conf命令打開文件,進入普通模式。

    2. :10將光標定位到第10行。

    3. I進入插入模式。

    4. 輸入#。

    5. Esc鍵退出插入模式。

    6. 輸入:wq保存文件并退出。

      插入操作完成后,example.conf文件如下所示:

      # To be able to use the functionality of a module which was built as a DSO you
      # have to place corresponding `LoadModule' lines at this location so the
      # directives contained in it are actually available _before_ they are used.
      # Statically compiled modules (those listed by `httpd -l') do not need
      # to be loaded here.
      #
      # Example:
      # LoadModule foo_module modules/mod_foo.so
      #
      #Include conf.modules.d/*.conf        
  • 示例三:在配置文件example.conf中,在Include conf.modules.d/*.conf行的下一行插入LoadModule rewrite_module modules/mod_rewrite.so。步驟如下:

    1. 運行vim example.conf命令打開文件,進入普通模式。

    2. 運行/Include conf.modules.d/*.conf找到目標行。

    3. o進入插入模式。

    4. 輸入LoadModule rewrite_module modules/mod_rewrite.so

    5. Esc鍵退出插入模式。

    6. :wq保存文件并退出。

      插入完成后,example.conf文件如下所示:

      # To be able to use the functionality of a module which was built as a DSO you
      # have to place corresponding `LoadModule' lines at this location so the
      # directives contained in it are actually available _before_ they are used.
      # Statically compiled modules (those listed by `httpd -l') do not need
      # to be loaded here.
      #
      # Example:
      # LoadModule foo_module modules/mod_foo.so
      #
      Include conf.modules.d/*.conf
      LoadModule rewrite_module modules/mod_rewrite.so                            

替換

基本命令:

R:替換光標高亮的字符,直至按下Esc鍵退出替換模式。

本示例使用的example.conf文件,如下所示:

# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
#   Options FileInfo AuthConfig Limit
#
AllowOverride None                

示例:將配置文件example.conf中的AllowOverride None更改為AllowOverride All。

  1. 運行vim example.conf命令打開文件,進入普通模式。

  2. 運行/AllowOverride None找到目標。

  3. 移動光標至None的首字母。

  4. R進入替換模式。

  5. 輸入All和一個空格。

    說明

    None中共包含4個字符,而All只包含3個字符,因此輸入All之后,需再輸入一個空格。

  6. Esc鍵退出替換模式。

  7. 輸入:wq保存文件并退出。

    更改后的example.conf文件,如下所示:

    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   Options FileInfo AuthConfig Limit
    #
    AllowOverride All                            

刪除

基本命令:

  • x:刪除光標高亮的那一個字符。

  • nx(n為數字): 刪除光標高亮的字符及其后面的n-1個字符。

  • dd:刪除光標所在的那一行。

  • ndd(n為數字):刪除光標所在行及其下面的n-1行。

本示例中使用的example.conf文件如下所示:

# Listen: Allows you to bind Apache to specific IP addresses and/or
# ports, instead of the default. See also the <VirtualHost>
# directive.
#
# Change this to Listen on specific IP addresses as shown below to
# prevent Apache from glomming onto all bound IP addresses.
#
#Listen 12.34.XX:XX:80
Listen 80                
  • 示例一:在配置文件example.conf中,將#Listen 12.34.XX:XX:80行首的#刪除。步驟如下:

    1. 運行vim example.conf命令打開文件,進入普通模式。

    2. 運行/#Listen 12.34.XX:XX:80找到目標,光標此時定位在#字符上。

    3. x刪除#

    4. 輸入:wq保存文件并退出。

      刪除完成后,example.conf文件如下所示:

      # Listen: Allows you to bind Apache to specific IP addresses and/or
      # ports, instead of the default. See also the <VirtualHost>
      # directive.
      #
      # Change this to Listen on specific IP addresses as shown below to
      # prevent Apache from glomming onto all bound IP addresses.
      #
      Listen 12.34.XX:XX:80  
      Listen 80                        
  • 示例二:在配置文件example.conf中,將#Listen 12.34.XX:XX:80行和下一行的內容刪掉。步驟如下:

    1. 運行vim example.conf命令打開文件,進入普通模式。

    2. 運行/#Listen 12.34.XX:XX:80找到目標。

    3. 2dd刪除以下內容。

      #Listen 12.34.XX:XX:80
      Listen 80
    4. :wq保存文件并退出。

      刪除完成后,example.conf文件如下所示:

      # Listen: Allows you to bind Apache to specific IP addresses and/or
      # ports, instead of the default. See also the <VirtualHost>
      # directive.
      #
      # Change this to Listen on specific IP addresses as shown below to
      # prevent Apache from glomming onto all bound IP addresses.
      #