【Vim】

一、什么是Vim?

Vim 是一個歷史悠久的文本編輯器,可以追溯到 qed。 Bram Moolenaar 于 1991 年發布初始版本。Vim 有著悠久的歷史;它起源于 Vi 編輯器(1976 年),至今仍在開發中。(Vim has a rich history; it originated from the Vi editor (1976), and it’s still being developed today.)?

編程時,您大部分時間都花在閱讀/編輯上,而不是寫作上。出于這個原因,Vim 是一個模態編輯器:它有不同的插入文本和操作文本的模式。Vim 是可編程的(使用 Vimscript 和 Python 等其他語言),而 Vim 的界面本身就是一種編程語言:擊鍵(帶有助記詞名稱)是命令,這些命令是可組合的。Vim 避免使用鼠標,因為它太慢了;Vim 甚至避免使用箭頭鍵,因為它需要太多的移動。 最終結果是一個可以匹配您思維速度的編輯器。?

(When programming, you spend most of your time reading/editing, not writing. For this reason, Vim is a?modal?editor: it has different modes for inserting text vs manipulating text. Vim is programmable (with Vimscript and also other languages like Python), and Vim’s interface itself is a programming language: keystrokes (with mnemonic names) are commands, and these commands are composable. Vim avoids the use of the mouse, because it’s too slow; Vim even avoids using the arrow keys because it requires too much movement.

The end result is an editor that can match the speed at which you think.)

二、Vim安裝

①在VScode上的擴展插件中有vim的插件,我們選擇install即可。

②Ubuntu虛擬中,打開終端terminal,鍵入

sudo apt install vim

這里我已經下載完成。(可以用vim -version檢驗一下)

三、vim的編輯模式

  • Normal: for moving around a file and making edits
  • Insert: for inserting text
  • Replace: for replacing text
  • Visual?(plain, line, or block): for selecting blocks of text
  • Command-line: for running a command

擊鍵在不同的操作模式下有不同的含義。例如,在“插入”模式下,字母 x 只會插入一個文字字符“x”,但在“正常”模式下,它將刪除光標下的字符,而在“可視”模式下,它將刪除所選內容。

您可以通過按<ESC>(轉義鍵)從任何模式切換回正常模式來更改模式。從“正常模式”中,使用 i 輸入插入模式,使用 R 輸入替換模式,使用 v 輸入可視模式,使用 V 輸入可視線模式,使用 (<C-v>Ctrl-V,有時也寫入 ^V)進入可視塊模式,使用 : 輸入命令行模式。?

四、vim基礎?

4.1、Inserting text

從正常模式,按 i 進入插入模式。現在,Vim 的行為與任何其他文本編輯器一樣,直到您按<ESC>下返回正常模式。這些,以及上面解釋的基礎知識,就是你開始使用 Vim 編輯文件所需要的一切(盡管不是特別有效,如果你把所有時間都花在插入模式下編輯)。

現在是normal模式:

按i后進入插入模式:

4.2、Buffers, tabs, and windows

Vim 維護著一組打開的文件,稱為 “buffers”。一個 Vim 會話有許多選項卡,每個選項卡都有多個窗口(拆分窗格)。每個窗口顯示一個緩沖區。與您熟悉的其他程序(如 Web 瀏覽器)不同,緩沖區和 Windows 之間沒有一一對應關系;窗戶只是視圖。給定的緩沖區可以在多個窗口中打開,甚至在同一選項卡中也是如此。例如,這非常方便,可以同時查看文件的兩個不同部分。

默認情況下,Vim 打開時只有一個選項卡,其中包含一個窗口。?

(Vim maintains a set of open files, called “buffers”. A Vim session has a number of tabs, each of which has a number of windows (split panes). Each window shows a single buffer. Unlike other programs you are familiar with, like web browsers, there is not a 1-to-1 correspondence between buffers and windows; windows are merely views. A given buffer may be open in?multiple?windows, even within the same tab. This can be quite handy, for example, to view two different parts of a file at the same time.

By default, Vim opens with a single tab, which contains a single window.)

Vim 是一個文本編輯器。每次文本都是作為緩沖區的一部分顯示的。每一份文件都是在他們自己獨有的緩沖區打開的,插件顯示的內容也在它們自己的緩沖區中。

緩沖區有很多屬性,比如這個緩沖區的內容是否可以修改,或者這個緩沖區是否和文件相關聯,是否需要同步保存到磁盤上。

窗口 是緩沖區上一層的視窗。如果你想同時查看幾個文件或者查看同一文件的不同位置,那樣你會需要窗口。

請別把他們叫做 分屏 。你可以把一個窗口分割成兩個,但是這并沒有讓這兩個窗口完全 分離

窗口可以水平或者豎直分割并且現有窗口的高度和寬度都是可以被調節設置的,因此,如果你需要多種窗口布局,請考慮使用標簽。

標簽頁 (標簽)是窗口的集合。因此當你想使用多種窗口布局時候請使用標簽。

簡單的說,如果你啟動 Vim 的時候沒有附帶任何參數,你會得到一個包含著一個呈現一個緩沖區的窗口的標簽。

順帶提一下,緩沖區列表是全局可見的,你可以在任何標簽中訪問任何一個緩沖區。

4.3、Command-line

Command mode can be entered by typing?:?in Normal mode. Your cursor will jump to the command line at the bottom of the screen upon pressing?:. This mode has many functionalities, including opening, saving, and closing files, and?quitting Vim.

在正常模式下,可以通過鍵入":"來進入命令模式。按":",您的光標將跳轉到屏幕底部的命令行。此模式具有許多功能,包括打開、保存和關閉文件,以及退出 Vim。

  • :q?quit (close window) - 退出(關閉窗口)
  • :w?save (“write”) - 保存("寫入")
  • :wq?save and quit - 保存并退出
  • :e {name of file}?open file for editing - {文件名}打開文件進行編輯
  • :ls?show open buffers - 顯示打開的緩沖區
  • :help {topic}?open help
    • :help :w?opens help for the?:w?command
    • :help w?opens help for the?w?movement

五、vim的界面是一種編程語言

Vim 中最重要的思想是 Vim 的界面本身就是一種編程語言。擊鍵(帶有助記詞名稱)是命令,這些命令組成。這樣可以進行有效的移動和編輯,尤其是當命令成為肌肉記憶時。

5.1、Movement

  • Basic movement:?hjkl?(left, down, up, right)
  • Words:?w?(next word),?b?(beginning of word),?e?(end of word)
  • Lines:?0?(beginning of line),?^?(first non-blank character),?$?(end of line)
  • Screen:?H?(top of screen),?M?(middle of screen),?L?(bottom of screen)
  • Scroll:?Ctrl-u?(up),?Ctrl-d?(down)
  • File:?gg?(beginning of file),?G?(end of file)
  • Line numbers:?:{number}<CR>?or?{number}G?(line {number})
  • Misc:?%?(corresponding item)
  • Find:?f{character},?t{character},?F{character},?T{character}
    • find/to forward/backward {character} on the current line
    • ,?/?;?for navigating matches
  • Search:?/{regex},?n?/?N?for navigating matches

5.2、Selection

Visual modes:

  • Visual:?v
  • Visual Line:?V
  • Visual Block:?Ctrl-v

5.3、Edits

  • i?enter Insert mode
    • but for manipulating/deleting text, want to use something more than backspace
  • o?/?O?insert line below / above
  • d{motion}?delete {motion}
    • e.g.?dw?is delete word,?d$?is delete to end of line,?d0?is delete to beginning of line
  • c{motion}?change {motion}
    • e.g.?cw?is change word
    • like?d{motion}?followed by?i
  • x?delete character (equal do?dl)
  • s?substitute character (equal to?cl)
  • Visual mode + manipulation
    • select text,?d?to delete it or?c?to change it
  • u?to undo,?<C-r>?to redo
  • y?to copy / “yank” (some other commands like?d?also copy)
  • p?to paste
  • Lots more to learn: e.g.?~?flips the case of a character

5.4、Counts

您可以將名詞和動詞與計數組合在一起,計數將多次執行給定的動作。

  • 3w?move 3 words forward
  • 5j?move 5 lines down
  • 7dw?delete 7 words

5.5、Modifiers

您可以使用修飾符來更改名詞的含義。一些修飾詞是 i,意思是“內部”或“內部”,以及 a,意思是“周圍”。(You can use modifiers to change the meaning of a noun. Some modifiers are?i, which means “inner” or “inside”, and?a, which means “around”.)

  • ci(?change the contents inside the current pair of parentheses -?更改當前括號對內的內容
  • ci[?change the contents inside the current pair of square brackets -?更改當前方括號對內的內容
  • da'?delete a single-quoted string, including the surrounding single quotes -?刪除單引號字符串,包括周圍的單引號

六、Advanced Vim

Here are a few examples to show you the power of the editor. We can’t teach you all of these kinds of things, but you’ll learn them as you go. A good heuristic: whenever you’re using your editor and you think “there must be a better way of doing this”, there probably is: look it up online.

6.1、Search and replace

:s?(substitute) command (documentation).

  • %s/foo/bar/g
    • replace foo with bar globally in file(全局替換)
  • %s/\[.*\](\(.*\))/\1/g
    • replace named Markdown links with plain URLs

6.2、Multiple windows

  • :sp?/?:vsp?to split windows
  • Can have multiple views of the same buffer.

6.3、Macros(宏)

你可以在 Vim 中錄制一系列按鍵,并把他們存儲到寄存器中。對于一些需要臨時使用多次的一系列操作,把它們作為宏保存起來會顯著地提升效率。對于一些復雜的操作,建議使用 Vim 腳本來實現。

  • q{character}?to start recording a macro in register?{character} -?開始記錄寄存器 {character} 中的宏
  • q?to stop recording
  • @{character}?replays the macro
  • Macro execution stops on error
  • {number}@{character}?executes a macro {number} times -?執行宏 {number} 次
  • Macros can be recursive
    • first clear the macro with?q{character}q -?首先用 q{character}q 清除宏
    • record the macro, with?@{character}?to invoke the macro recursively (will be a no-op until recording is complete) -?記錄宏,使用 @{character} 遞歸調用宏(在錄制完成之前將是一個無操作)
  • Example: convert xml to json (file)
    • Array of objects with keys “name” / “email”
    • Use a Python program?
    • Use sed / regexes
      • g/people/d
      • %s/<person>/{/g
      • %s/<name>\(.*\)<\/name>/"name": "\1",/g
    • Vim commands / macros
      • Gdd,?ggdd?delete first and last lines -?刪除第一行和最后一行
      • Macro to format a single element (register?e)
        • Go to line with?<name>
        • qe^r"f>s": "<ESC>f<C"<ESC>q
      • Macro to format a person
        • Go to line with?<person>
        • qpS{<ESC>j@eA,<ESC>j@ejS},<ESC>q
      • Macro to format a person and go to the next person
        • Go to line with?<person>
        • qq@pjq
      • Execute macro until end of file
        • 999@q
      • Manually remove last?,?and add?[?and?]?delimiters

七、Resources

  • vimtutor?is a tutorial that comes installed with Vim - if Vim is installed, you should be able to run?vimtutor?from your shell
  • Vim Adventures?is a game to learn Vim
  • Vim Tips Wiki
  • Vim Advent Calendar?has various Vim tips
  • Vim Golf?is?code golf, but where the programming language is Vim’s UI
  • Vi/Vim Stack Exchange
  • Vim Screencasts
  • Practical Vim?(book)

八、Exercises

  1. Complete?vimtutor. Note: it looks best in a?80x24?(80 columns by 24 lines) terminal window.
  2. Download our?basic vimrc?and save it to?~/.vimrc. Read through the well-commented file (using Vim!), and observe how Vim looks and behaves slightly differently with the new config.
  3. Install and configure a plugin:?ctrlp.vim.
    1. Create the plugins directory with?mkdir -p ~/.vim/pack/vendor/start
    2. Download the plugin:?cd ~/.vim/pack/vendor/start; git clone https://github.com/ctrlpvim/ctrlp.vim
    3. Read the?documentation?for the plugin. Try using CtrlP to locate a file by navigating to a project directory, opening Vim, and using the Vim command-line to start?:CtrlP.
    4. Customize CtrlP by adding?configuration?to your?~/.vimrc?to open CtrlP by pressing Ctrl-P.
  4. To practice using Vim, re-do the?Demo?from lecture on your own machine.
  5. Use Vim for?all?your text editing for the next month. Whenever something seems inefficient, or when you think “there must be a better way”, try Googling it, there probably is. If you get stuck, come to office hours or send us an email.
  6. Configure your other tools to use Vim bindings (see instructions above).
  7. Further customize your?~/.vimrc?and install more plugins.
  8. (Advanced) Convert XML to JSON (example file) using Vim macros. Try to do this on your own, but you can look at the?macros?section above if you get stuck.

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/web/13380.shtml
繁體地址,請注明出處:http://hk.pswp.cn/web/13380.shtml
英文地址,請注明出處:http://en.pswp.cn/web/13380.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

css+html 愛心?

效果 代碼實現 html <div class"main"><div class"aixin"></div></div>css .main {transform: rotate(-45deg);}.aixin {height: 100px;width: 100px;background-color: red;margin: auto;margin-top: 200px;position: relativ…

MySQL第一次作業(基本操作)

目錄 一、登陸數據庫 二、創建數據庫zoo 三、修改數據庫zoo字符集為gbk 四、選擇當前數據庫為zoo 五、查看創建數據庫zoo信息 六、刪除數據庫zoo 一、登陸數據庫 指令&#xff1a; mysql -u root -p 二、創建數據庫zoo 指令&#xff1a; create database zoo; 三、修改數…

基于PHP+MySQL組合開發的多用戶自定義商城系統源碼 附帶源代碼包以及搭建教程

系統概述 互聯網技術的飛速發展&#xff0c;電子商務已成為人們日常生活中不可或缺的一部分。商城系統作為電子商務的核心&#xff0c;其開發技術和用戶體驗直接影響著電商平臺的競爭力和用戶滿意度。本文旨在介紹一個基于PHPMySQL組合開發的多用戶自定義商城系統&#xff0c;…

C++學習~~string類

1.STL簡單介紹 &#xff08;1&#xff09;標準模版庫&#xff0c;是C里面的標準庫的一部分&#xff0c;C標準庫里面還有其他的東西&#xff0c;但是我們不經常使用&#xff0c;我們經常使用的還是STL這個標準庫部分。 &#xff08;2&#xff09;六大件&#xff1a;仿函數&…

C# WinForm —— 16 MonthCalendar 介紹

1. 簡介 可以選擇單個日期&#xff0c;也可以選擇一段日期&#xff0c;在選擇時間范圍上 比較適用&#xff0c;但不能跨月份選擇日期范圍 在直觀上&#xff0c;可以快速查看、選擇日期/日期范圍 2. 常用屬性 屬性解釋(Name)控件ID&#xff0c;在代碼里引用的時候會用到,一般…

Uni-app基礎知識

uni-app組成和跨端原理 | uni-app官網uni-app,uniCloud,serverless,uni-app組成和跨端原理,基本語言和開發規范,編譯器,運行時&#xff08;runtime&#xff09;,邏輯層和渲染層分離https://uniapp.dcloud.net.cn/tutorial/1.adb連接模擬器 找到adb所在位置&#xff08;一般在hb…

C++ 程序員常用的VScode的插件

vscode中好用的插件 Better CommentsBookmarksC/C ThemeChinese (Simplified) (簡體中文) Language Pack for Visual Studio CodeclangdClang-FormatCodeLLDBCMakeCMake ToolsCode RunnerCode Spell CheckerCodeSnapColor Highlightvscode-mindmapDraw.io IntegrationError Len…

一網打進Linux下那些查找命令

查找是我們每天都在做的事情&#xff0c;早上醒來找下手機&#xff0c;出門之前查下公交&#xff0c;坐下之后查下資料&#xff0c;分析數據查下模式。 查找文件&#xff0c;查找信息&#xff0c;查找錯誤是應用起來更為具體的一些工作&#xff0c;而Linux命令行為我們提供了很…

對稱加密算法的應用場景

隨著信息技術的飛速發展&#xff0c;數據安全成為了至關重要的議題。在保護數據傳輸和存儲的過程中&#xff0c;加密算法扮演著不可或缺的角色。其中&#xff0c;對稱加密算法&#xff0c;由于其高效性和易用性&#xff0c;被廣泛應用于各種場景中。本文將探討對稱加密算法的主…

Kubernets多master集群構建負載均衡

前言 在構建 Kubernetes 多 Master 集群時&#xff0c;實現負載均衡是至關重要的一環。通過多臺 Master 節點配合使用 Nginx 和 Keepalived 等工具&#xff0c;可以有效提高集群的可靠性和穩定性&#xff0c;確保系統能夠高效運行并有效應對故障。接下來將介紹如何配置這些組件…

Kotlin 編譯器和工具鏈:深入解析與實踐案例

Kotlin 編譯器和工具鏈是構建 Kotlin 項目的核心組件&#xff0c;它們負責將 Kotlin 代碼轉換為可在 JVM 或 JavaScript 環境中運行的代碼。本文將詳細介紹 Kotlin 編譯器和工具鏈的工作原理、使用方法&#xff0c;以及在實際開發中的應用案例。 1. 引言 Kotlin 作為一種現代…

JAVA GUI 植物大戰僵尸

公眾號&#xff1a;編程驛站 沒有做太多封裝。難免有冗余。源碼全部放出&#xff0c;有興趣者可以再改之。 1. pea 類 package com.hm;import javax.imageio.ImageIO; import java.awt.*; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOExce…

物業水電抄表系統的全面解析

1.系統概述 物業水電抄表系統是現代物業管理中的重要組成部分&#xff0c;它通過自動化的方式&#xff0c;實時監控和記錄居民或企業的水電使用情況&#xff0c;極大地提高了工作效率&#xff0c;降低了人工抄表的錯誤率。該系統通常包括數據采集、數據傳輸、數據分析和數據展…

鏈表OJ題(移除鏈表元素,反轉鏈表,分割鏈表,環形鏈表(是否成環問題),鏈表中間節點(快慢指針講解),環形鏈表(找入環節點))“題目來源力扣附帶題目鏈接”

目錄 1.移除鏈表元素 2.反轉鏈表 2.1三指針法 2.2頭插法 3.分割鏈表 4.鏈表的中間節點&#xff08;快慢指針&#xff09; 4.1快慢指針 4.2求鏈表的中間節點 5.環形鏈表 5.1環形鏈表是否成環 5.2環形鏈表入環節點 5.3入環節點推論的不完備性說明 1.移除鏈表元素 移除…

Microsoft Threat Modeling Tool 使用(三)

Boundary&#xff08;邊界&#xff09; 本文介紹信任邊界&#xff0c;基于 SDL TM Knowledge Base (Core) 模版&#xff0c;這是一個通用的威脅建模模板&#xff0c;非常適合初學者和大多數威脅建模需求。 這些邊界&#xff08;Boundary&#xff09;在微軟威脅建模工具中用于表…

Java多線程與高并發

1、什么是進程?什么是線程? 進程:進程是程序的基本執行實體;另外一種解釋是進程是一個應用程序(1個進程是一個軟件)。 線程:線程是操作系統能夠進行運算調度的最下單位。它被包含在進程之中,是進程中的實際運作單位;是一個進程中的執行場景/執行單元。 注意:。一個進…

uniapp實現列表拖拽排序+滑動刪除功能

此篇代碼在原插件基礎進行了bug修改與滑動功能的新增 原插件地址 HM-dragSorts.vue組件使用 HM-dragSorts.vue <template><view class""><view class"HM-drag-sort" :style"{height: ListHeightrpx,background-color: listBackground…

魔法方法介紹

【一】什么是魔法方法 在類內部達到指定條件會自動觸發的方法 【二】魔法方法 # 【1】__init__ &#xff1a; 實例化類得到對象的時候會自動觸發 class Student(object):def __init__(self):print(f"實例化類的時候觸發") # 實例化類的時候觸發 ? s Student…

在云服務器上運行StyleGAN3生成偽樣本

首先是傳入數據&#xff0c;這里我們不做贅述。 對于數據格式的裁剪&#xff0c;可以通過以下代碼進行&#xff1a; from glob import glob from PIL import Image import os from tqdm import tqdm from tqdm.std import trangeimg_path glob(r"C:\Users\Administrato…

【Oracle篇】rman物理備份工具的基礎理論概述(第一篇,總共八篇)

??博主介紹??&#xff1a; ?又是一天沒白過&#xff0c;我是奈斯&#xff0c;DBA一名? ???擅長Oracle、MySQL、SQLserver、阿里云AnalyticDB for MySQL(分布式數據倉庫)、Linux&#xff0c;也在擴展大數據方向的知識面??? ??????大佬們都喜歡靜靜的看文章&am…