Skip to content

vim101

Updated: at 20:45

普通模式

复制

缩进

> , <=

重复操作

移动

单词默认由字母、数字和下划线组成(程序变量),而使用大写 WE 的移动方式,单词由空白字符分隔。

action + text object

action

text object

字符串(map (+) (“foo”)),光标在第一个 o 的位置

Scrolling relative to cursor

缓存

当使用 vim 编辑器时,vim 会在被编辑的文件目录下,建立一个名为 .filename.swap 的文件

buffers

Summary:
- A buffer is the in-memory text of a file.
- A window is a viewport on a buffer.
    - A tab page is a collection of windows.

同 buffer

不同 buffers

删除 buffer

多窗口

窗口间移动

标签页间移动

在普通模式下,使用快捷键 <ctrl-w>t,可以将一个 buffer 文件在另一个标签页中打开。

会话 session

使用命令 :mksession ~/.mysession.vim ( :mks is ok) 保存已经打开的多窗口文件。 如果文件重复,vim 默认会报错,使用 :mksession! ~/.mysession.vim 代替。打开保存的会话

vim -S ~/.mysession.vim

Quickfix

what a quick fix list is effectively what a quick fix list is a series of entries in which point to a specific file and location.

A lot of times they’re associated with errors links or search results.

quickfix

location-list

:ldo

Power of g

:h g

The global command :g is very useful - multiple repeats

:[range]g[lobal]/{pattern}/[cmd]

Example:

:normal! !

Replace

:%s/https\?.*/[&](&)/g

Search and replace | Vim Tips Wiki | Fandom

Repeat the last substitution

Developing efficient workflows in Vim is all about repetition, first and foremost by using . to repeat the last command. But Vim can also repeat your last substitution. Here’s a few options with subtle differences:

:%s/something/newthing/g
:%&g

vim 的环境配置和记录

.viminfo 主动记录你曾经做过的操作记录,以便你下次可以轻松地作业。

环境配置

  1. 在一般模式下输入 :set all 查看所有的参数设置值。
  2. :set 显示与系统默认值不同的设置参数,一般来说就是自定变动过的设置参数。
  3. :syntax on 打开语法高亮

DOS 与 Linux 的换行符

字符转换命令

registers

To find out what’s stored in each register, simply use Vim’s :registers command, or :reg for short.

Marks

Use m{capital letter} to make a global mark. Close and reopen VIm, and press '{capital letter} to open the file w/ the global mark.

args

https://vimtricks.com/p/vimtrick-edit-files-sequentially/ - Edit files sequentially

Tips

Copying and pasting lines

The shortcut keyboards in insert mode

The undo tree usr_32.txt

Change the case of characters with ~, u and U.

Sort lines in Vim:

sort-motion plugin - The primary interface to this plugin is via the gs mapping, for sorting based on a text object or motion.

Examples:

Vim has some built in options:

There are ways to sort elements of a single line in vanilla vim as well, as detailed in this StackExchange response, but they will involve some regex.

Jump between changes

:norm

The command allows you to execute normal mode operations from the command line. By combining with % , we can run a sequence of operations on an entire file.

Examples:

`character

Others

  1. You can edit your visual selection by using o to bounce your cursor to the opposite end of the selection. Adjust the top bound as needed, then press o to return to the bottom.

  2. Use gv in Vim to reselect the last visual selection

  3. filename-modifiers关于Unix:在Vim中打开与当前文件相同的文件夹中的文件

    :p Make file name a full path, :h expand, :wildcards

  4. Use ea to append to the end of the current word.

  5. Swap two characters in Vim with xp

  6. Put from the "% register to put the name of the current file.

  7. To make it easier to navigate conflict markers, you could tweak the built-in matchit plugin: stackoverflow.com/a/71676129/853…

  8. Multiple cursor support

  9. Open the quickfix window with :cwin and see the results. Next we do another search. To get back to our previous, older quickfix window, we use :colder. Then, we can return to the most recent search results with :cnewer.

Ex Command-line

Helps

References

Learning Vim