byodian's blog

vim tips

·

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

Search

Power of g

The global command :g is very useful - multiple repeats

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

For example:

Copying and pasting lines

The shortcut keyboards in insert mode

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.

DOS 与 Linux 的换行符

字符转换命令

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.

` character

Ex Command-line

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 "%p 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.

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

  11. 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.

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

  13. . 小数点可以重复上一次的命令

  14. N<command> 重复某个命令 N 次

  15. args

    • :args /path/*
    • :wn

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

Helps