你妈妈从未告诉过你的 Vim 的阴暗角落是什么?

发布于 2024-07-16 18:33:24 字数 353 浏览 5 评论 0原文

人们在很多问题中谈论常见技巧,特别是“Vim+ctags 提示和技巧”。

不过,我并不是指 Vim 新手会觉得很酷的常用快捷键。 我说的是一个经验丰富的 Unix 用户(无论是开发人员、管理员还是两者兼而有之),他们认为自己知道一些我们 99% 的人从未听说过或梦想过的东西。 这不仅让他们的工作变得更轻松,而且很酷且hackish。 毕竟,Vim 位于世界上最黑暗角落的操作系统中,因此它应该具有只有少数特权人士知道并愿意与我们分享的复杂性。

There are a plethora of questions where people talk about common tricks, notably "Vim+ctags tips and tricks".

However, I don't refer to commonly used shortcuts that someone new to Vim would find cool. I am talking about a seasoned Unix user (be they a developer, administrator, both, etc.), who thinks they know something 99% of us never heard or dreamed about. Something that not only makes their work easier, but also is COOL and hackish. After all, Vim resides in the most dark-corner-rich OS in the world, thus it should have intricacies that only a few privileged know about and want to share with us.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(30

离笑几人歌 2024-07-23 18:33:25

宏可以调用其他宏,也可以调用自身。

例如:

qq0dwj@qq@q

...将从每一行中删除第一个单词,直到文件末尾。

这是一个非常简单的例子,但它展示了 vim 的一个非常强大的功能

Macros can call other macros, and can also call itself.

eg:

qq0dwj@qq@q

...will delete the first word from every line until the end of the file.

This is quite a simple example but it demonstrates a very powerful feature of vim

ぽ尐不点ル 2024-07-23 18:33:25

假设您编译了 Perl 和/或 Ruby 支持,:rubydo:perldo 将在范围内的每一行上运行 Ruby 或 Perl 单行代码(默认为整个行) buffer),其中 $_ 绑定到当前行的文本(减去换行符)。 操作 $_ 将更改该行的文本。

您可以使用它来完成某些在脚本语言中很容易完成但使用 Vim 内置函数则不那么明显的事情。 例如,反转一行中单词的顺序:

:perldo $_ = join ' ', reverse split

在每行末尾插入 8 个字符 (AZ) 的随机字符串:

:rubydo $_ += ' ' + (1..8).collect{('A'..'Z').to_a[rand 26]}.join

您只能一次只处理一行,并且无法添加换行符。

Assuming you have Perl and/or Ruby support compiled in, :rubydo and :perldo will run a Ruby or Perl one-liner on every line in a range (defaults to entire buffer), with $_ bound to the text of the current line (minus the newline). Manipulating $_ will change the text of that line.

You can use this to do certain things that are easy to do in a scripting language but not so obvious using Vim builtins. For example to reverse the order of the words in a line:

:perldo $_ = join ' ', reverse split

To insert a random string of 8 characters (A-Z) at the end of every line:

:rubydo $_ += ' ' + (1..8).collect{('A'..'Z').to_a[rand 26]}.join

You are limited to acting on one line at a time and you can't add newlines.

扎心 2024-07-23 18:33:25

^O 和 ^I

转到旧/新位置。
当您在文件中移动时(通过搜索、移动命令等),vim 会记住这些“跳转”,因此您可以重复这些向后跳转(^O - O 表示旧)和向前跳转(^I - 就在键盘上的 I 旁边) )。 我发现它在编写代码和执行大量搜索时非常有用。

gi

转到插入模式最后停止的位置。
我发现自己经常编辑然后搜索一些东西。 要返回编辑位置,请按 gi。

gf

将光标放在文件名上(例如包含头文件),按 gf 键,文件将打开

gF

与 gf 类似,但可识别格式“[文件名]:[行号” ]”。 按 gF 将打开 [文件名] 并将光标设置到 [行号]。

^P 和 ^N

编辑时自动完成文本(^P - 上一个匹配项和 ^N 下一个匹配项)

^X^L

编辑时自动完成到同一行(对于编程)。
您编写代码,然后您想起文件中的某处有相同的代码。 只需按 ^X^L 即可完成整行

^X^F

完整文件名。
你写“/etc/pass”嗯。 您忘记了文件名。 只需按 ^X^F 即可完成文件名

^Z 或 :sh

将临时文件移至 shell。 如果您需要快速攻击:

  • 按 ^Z (将 vi 置于后台)返回原始 shell,然后按 fg 返回 vim 返回,
  • 按 :sh 转到子 shell,然后按 ^D/exit 返回 vi 返回

^O and ^I

Go to older/newer position.
When you are moving through the file (by searching, moving commands etc.) vim rember these "jumps", so you can repeat these jumps backward (^O - O for old) and forward (^I - just next to I on keyboard). I find it very useful when writing code and performing a lot of searches.

gi

Go to position where Insert mode was stopped last.
I find myself often editing and then searching for something. To return to editing place press gi.

gf

put cursor on file name (e.g. include header file), press gf and the file is opened

gF

similar to gf but recognizes format "[file name]:[line number]". Pressing gF will open [file name] and set cursor to [line number].

^P and ^N

Auto complete text while editing (^P - previous match and ^N next match)

^X^L

While editing completes to the same line (useful for programming).
You write code and then you recall that you have the same code somewhere in file. Just press ^X^L and the full line completed

^X^F

Complete file names.
You write "/etc/pass" Hmm. You forgot the file name. Just press ^X^F and the filename is completed

^Z or :sh

Move temporary to the shell. If you need a quick bashing:

  • press ^Z (to put vi in background) to return to original shell and press fg to return to vim back
  • press :sh to go to sub shell and press ^D/exit to return to vi back
自由如风 2024-07-23 18:33:25

键入 == 将根据上面的行更正当前行的缩进。

实际上,您可以执行一个 = 符号,然后执行任何移动命令。 ={movement}

例如,您可以使用在匹配大括号之间移动的 % 移动。 将光标定位在以下代码中的 { 上:

if (thisA == that) {
//not indented
if (some == other) {
x = y;
}
}

然后按 =% 立即得到:

if (thisA == that) {
    //not indented
    if (some == other) {
        x = y;
    }
}

或者,您可以在代码块中执行 =a{,而不是定位你自己就在 { 字符上。

Typing == will correct the indentation of the current line based on the line above.

Actually, you can do one = sign followed by any movement command. ={movement}

For example, you can use the % movement which moves between matching braces. Position the cursor on the { in the following code:

if (thisA == that) {
//not indented
if (some == other) {
x = y;
}
}

And press =% to instantly get this:

if (thisA == that) {
    //not indented
    if (some == other) {
        x = y;
    }
}

Alternately, you could do =a{ within the code block, rather than positioning yourself right on the { character.

此生挚爱伱 2024-07-23 18:33:25
" insert range ip's
"
"          ( O O )
" =======oOO=(_)==OOo======

:for i in range(1,255) | .put='10.0.0.'.i | endfor
" insert range ip's
"
"          ( O O )
" =======oOO=(_)==OOo======

:for i in range(1,255) | .put='10.0.0.'.i | endfor
下雨或天晴 2024-07-23 18:33:25

这是一个用不同编码重新打开当前文件的好技巧:

:e ++enc=cp1250 %:p

当您必须使用旧编码时很有用。 encoding-values 下的表中列出了支持的编码(请参阅help encoding-values)。 类似的事情也适用于 ++ff,这样,如果您第一次出错,您可以使用 Windows/Unix 行结尾重新打开文件(请参阅 help ff)。

This is a nice trick to reopen the current file with a different encoding:

:e ++enc=cp1250 %:p

Useful when you have to work with legacy encodings. The supported encodings are listed in a table under encoding-values (see help encoding-values). Similar thing also works for ++ff, so that you can reopen file with Windows/Unix line ends if you get it wrong for the first time (see help ff).

小瓶盖 2024-07-23 18:33:25
imap jj <esc>
imap jj <esc>
只怪假的太真实 2024-07-23 18:33:25

让我们看看一些漂亮的小型 IDE 编辑器如何进行列转置。

:%s/\(.*\)^I\(.*\)/\2^I\1/

解释

\(\) 是如何记住正则表达式领域的内容。 \1\2 等是如何检索记住的东西。

>>> \(.*\)^I\(.*\)

记住所有内容,然后是 ^I(制表符),然后是所有内容。

>>> \2^I\1

将上面的内容替换为“你记得的第二件事”,然后是“你记得的第一件事”——本质上是进行转置。

Let's see some pretty little IDE editor do column transposition.

:%s/\(.*\)^I\(.*\)/\2^I\1/

Explanation

\( and \) is how to remember stuff in regex-land. And \1, \2 etc is how to retrieve the remembered stuff.

>>> \(.*\)^I\(.*\)

Remember everything followed by ^I (tab) followed by everything.

>>> \2^I\1

Replace the above stuff with "2nd stuff you remembered" followed by "1st stuff you remembered" - essentially doing a transpose.

捂风挽笑 2024-07-23 18:33:25

不完全是一个黑暗的秘密,但我喜欢将以下映射放入我的 .vimrc 文件中,这样我就可以随时点击“-”(减号)来打开文件资源管理器以显示与我刚刚编辑的文件相邻的文件 /em>. 在文件资源管理器中,我可以点击另一个“-”来上移一个目录,提供复杂目录结构的无缝浏览(就像现在 MVC 框架使用的目录结构):

map - :Explore<cr>

这些可能对某些人也很有用。 我喜欢滚动屏幕并同时前进光标:

map <c-j> j<c-e>
map <c-k> k<c-y>

选项卡导航 - 我喜欢选项卡,我需要在它们之间轻松移动:

map <c-l> :tabnext<enter>
map <c-h> :tabprevious<enter>

仅在 Mac OS X 上: 类似 Safari 的选项卡导航:

map <S-D-Right> :tabnext<cr>
map <S-D-Left> :tabprevious<cr>

Not exactly a dark secret, but I like to put the following mapping into my .vimrc file, so I can hit "-" (minus) anytime to open the file explorer to show files adjacent to the one I just edit. In the file explorer, I can hit another "-" to move up one directory, providing seamless browsing of a complex directory structures (like the ones used by the MVC frameworks nowadays):

map - :Explore<cr>

These may be also useful for somebody. I like to scroll the screen and advance the cursor at the same time:

map <c-j> j<c-e>
map <c-k> k<c-y>

Tab navigation - I love tabs and I need to move easily between them:

map <c-l> :tabnext<enter>
map <c-h> :tabprevious<enter>

Only on Mac OS X: Safari-like tab navigation:

map <S-D-Right> :tabnext<cr>
map <S-D-Left> :tabprevious<cr>
心病无药医 2024-07-23 18:33:25

通常,我喜欢在编辑时更改当前目录 - 因此我必须较少指定路径。

cd %:h

Often, I like changing current directories while editing - so I have to specify paths less.

cd %:h
我很坚强 2024-07-23 18:33:25

我喜欢使用“sudo bash”,但我的系统管理员讨厌这个。 他锁定了“sudo”,因此它只能与少数命令(ls、chmod、chown、vi 等)一起使用,但无论如何我都可以使用 vim 来获取 root shell:

bash$ sudo vi +'silent !bash' +q
Password: ******
root#

I like to use 'sudo bash', and my sysadmin hates this. He locked down 'sudo' so it could only be used with a handful of commands (ls, chmod, chown, vi, etc), but I was able to use vim to get a root shell anyway:

bash$ sudo vi +'silent !bash' +q
Password: ******
root#
月竹挽风 2024-07-23 18:33:25

当我处理一个项目时,我经常使用许多窗口,有时我需要调整它们的大小。 这是我使用的:

map + <C-W>+
map - <C-W>-

这些映射允许增加和减小当前窗口的大小。 这很简单,但速度很快。

I often use many windows when I work on a project and sometimes I need to resize them. Here's what I use:

map + <C-W>+
map - <C-W>-

These mappings allow to increase and decrease the size of the current window. It's quite simple but it's fast.

梦巷 2024-07-23 18:33:25

这不是一个晦涩的功能,但非常有用且节省时间。

如果您想保存打开的缓冲区、选项卡、标记和其他设置的会话,您可以发出以下命令:

mksession session.vim

您可以使用以下命令打开会话:

vim -S session.vim

Not an obscure feature, but very useful and time saving.

If you want to save a session of your open buffers, tabs, markers and other settings, you can issue the following:

mksession session.vim

You can open your session using:

vim -S session.vim
活泼老夫 2024-07-23 18:33:25
:r! <command>

将外部命令的输出粘贴到缓冲区中。

做一些数学计算并直接在文本中得到结果:

:r! echo $((3 + 5 + 8))

在编写 Makefile 时获取要编译的文件列表:

:r! ls *.c

不要查找您在维基百科上读到的事实,将其直接粘贴到您正在编写的文档中:

:r! lynx -dump http://en.wikipedia.org/wiki/Whatever
:r! <command>

pastes the output of an external command into the buffer.

Do some math and get the result directly in the text:

:r! echo $((3 + 5 + 8))

Get the list of files to compile when writing a Makefile:

:r! ls *.c

Don't look up that fact you read on wikipedia, have it directly pasted into the document you are writing:

:r! lynx -dump http://en.wikipedia.org/wiki/Whatever
划一舟意中人 2024-07-23 18:33:25

将 F5 映射到快速 ROT13 您的缓冲区:

map <F5> ggg?G``

您可以将其用作老板键:)。

Map F5 to quickly ROT13 your buffer:

map <F5> ggg?G``

You can use it as a boss key :).

只涨不跌 2024-07-23 18:33:25

我几乎使用 vim 进行任何文本编辑,因此我经常使用复制和粘贴。 问题是 vim 默认情况下经常会扭曲通过粘贴导入的文本。 阻止这种情况的方法是

:set paste

在粘贴数据之前使用。 这可以防止事情变得混乱。

请注意,您必须发出 :set nopaste 才能恢复自动缩进。 粘贴预格式化文本的替代方法是剪贴板寄存器(*+)和 :r!cat(您必须结束使用 ^D 粘贴的片段)。

有时打开高对比度配色方案也很有帮助。 我注意到

:color blue

它并不适用于我使用的所有 vim 版本,但它适用于大多数版本。

I use vim for just about any text editing I do, so I often times use copy and paste. The problem is that vim by default will often times distort imported text via paste. The way to stop this is to use

:set paste

before pasting in your data. This will keep it from messing up.

Note that you will have to issue :set nopaste to recover auto-indentation. Alternative ways of pasting pre-formatted text are the clipboard registers (* and +), and :r!cat (you will have to end the pasted fragment with ^D).

It is also sometimes helpful to turn on a high contrast color scheme. This can be done with

:color blue

I've noticed that it does not work on all the versions of vim I use but it does on most.

草莓酥 2024-07-23 18:33:25

我今天刚刚通过 NSFAQ 找到了这个:

注释代码块。

按 CTRL-V 进入块视觉模式。

标记您要评论的块。

点击 I(大写 I)并在该行的开头输入您的注释字符串。 (// 对于 C++)

按 ESC 键,所有选定的行都会在行的前面添加//。

I just found this one today via NSFAQ:

Comment blocks of code.

Enter Blockwise Visual mode by hitting CTRL-V.

Mark the block you wish to comment.

Hit I (capital I) and enter your comment string at the beginning of the line. (// for C++)

Hit ESC and all lines selected will have // prepended to the front of the line.

陪你到最终 2024-07-23 18:33:24

可能不是 99% 的 Vim 用户不知道,但这是我每天使用的东西,任何 Linux+Vim 高级用户都必须知道。

基本命令,但非常有用。

:w !sudo tee %

我经常忘记在编辑没有写权限的文件之前使用 sudo。 当我要保存该文件并收到权限错误时,我只需发出该 vim 命令即可保存该文件,而不需要将其保存到临时文件,然后再次将其复制回来。

显然,您必须在安装了 sudo 的系统上并且拥有 sudo 权限。

Might not be one that 99% of Vim users don't know about, but it's something I use daily and that any Linux+Vim poweruser must know.

Basic command, yet extremely useful.

:w !sudo tee %

I often forget to sudo before editing a file I don't have write permissions on. When I come to save that file and get a permission error, I just issue that vim command in order to save the file without the need to save it to a temp file and then copy it back again.

You obviously have to be on a system with sudo installed and have sudo rights.

超可爱的懒熊 2024-07-23 18:33:24

我最近发现了一些我认为非常酷的东西:

:earlier 15m

将文档恢复到 15 分钟前的状态。 可以采用各种参数来确定要回滚的时间量,并且取决于撤消级别。 可以用相反的命令 :later 反转

Something I just discovered recently that I thought was very cool:

:earlier 15m

Reverts the document back to how it was 15 minutes ago. Can take various arguments for the amount of time you want to roll back, and is dependent on undolevels. Can be reversed with the opposite command :later

|煩躁 2024-07-23 18:33:24

<代码>:! [command] 在 Vim 中执行外部命令。

但在冒号后面加一个点,:.! [command],它会将命令的输出转储到当前窗口中。 那是<代码>:。 !

例如:

:.! ls

我经常使用它来将当前日期添加到我正在输入的文档中:

:.! date

:! [command] executes an external command while you're in Vim.

But add a dot after the colon, :.! [command], and it'll dump the output of the command into your current window. That's : . !

For example:

:.! ls

I use this a lot for things like adding the current date into a document I'm typing:

:.! date
捂风挽笑 2024-07-23 18:33:24

并不完全晦涩,但是有几个非常有用的“删除”命令,例如..

  • diw 删除当前单词
  • di( 删除当前括号内的
  • < code>di" 删除引号之间的文本

其他内容可以在 <代码>:帮助文本对象

Not exactly obscure, but there are several "delete in" commands which are extremely useful, like..

  • diw to delete the current word
  • di( to delete within the current parens
  • di" to delete the text between the quotes

Others can be found on :help text-objects

究竟谁懂我的在乎 2024-07-23 18:33:24

de 按 删除单词末尾之前的所有内容。 随心所欲。

ci(xyz[Esc] -- 这是一个奇怪的。这里,'i' 并不意味着插入模式。而是意味着在括号内。所以这个序列会剪切括号内的文本。 re 站在并用“xyz”替换它。它也适用于方括号和数字括号内 - 只需相应地执行 ci[ 或 ci{ 当然,您可以执行 di (如果您只想删除所有文本而不输入任何内容。您如果您还想删除括号而不仅仅是其中的文本,也可以使用 a 而不是 i

- 剪切文本 。在当前引号中

ciw - 剪切当前单词,除了 ( 被替换为 w

C。 - 剪切该行的其余部分并切换到

ZZ - 保存并关闭当前文件(比 Ctrl-F4 关闭当前选项卡快得多!)

ddp。 - 将当前行向下移动一行

xp - 将当前字符向右移动一位

U - 大写,因此 viwU 大写单词

~ - 切换大小写,因此 viw~ 将反转整个单词的大小写

Ctrl+u / Ctrl+d 将页面滚动半个- 屏幕向上或向下。 这似乎比通常的全屏分页更有用,因为它可以更轻松地查看两个屏幕的相关性。 对于那些仍然想一次滚动整个屏幕的人,可以使用 Ctrl+f 向前滚动,按 Ctrl+b 向后滚动。 Ctrl+Y 和 Ctrl+E 一次向下或向上滚动一行。

疯狂但非常有用的命令是 zz - 它滚动屏幕以使该行出现在中间。 这非常适合将您正在处理的代码置于您的注意力中心。 兄弟命令 - zt 和 zb - 使这一行成为屏幕上的顶部或底部,这不太有用。

% 查找并跳转到匹配的括号。

de -- 从光标处删除到单词末尾(也可以执行 dE 删除直到下一个空格)

bde -- 删除当前单词,从左到右分隔符

df[space] -- 删除直到并包括下一个空格

dt. -- 删除直到下一个点

dd< /strong> -- 删除整行

ye(或 yE) -- 将文本从此处拉至单词末尾

ce - 切入单词末尾

< strong>bye -- 复制当前单词(让我想知道“hi”做了什么!)

yy -- 复制当前行

cc -- 剪切当前行行,您也可以使用 S 来代替。 还有小写的 s 可以剪切当前字符并切换到插入模式。

viwy 或 viwc。 猛拉或更改当前单词。 多次点击 w 继续选择每个后续单词,使用 b 向后移动

vi{ - 选择数字括号中的所有文本。 va{ - 选择包括 {} 在内的所有文本

vi(p - 突出显示 () 内的所有内容并替换为粘贴的文本

b 和 e 逐字移动光标,类似地与通常使用 Ctrl+箭头 的方式不同,单词的定义略有不同,因为如果您从一个单词的中间开始,则按 b 总是会转到下一个单词。当前单词的开头,每个连续的 b 将跳转到下一个单词的开头 类似地,并且易于记住,e 将光标移动到当前单词和每个后续单词的末尾。 .

类似于b/e,大写的BE逐字移动光标仅使用空格作为分隔符。

大写 D(深呼吸) 删除光标右侧的行的其余部分,与普通编辑器中的 Shift+End/Del 相同(注意2 次按键 -- Shift+D -- 而不是 3 次)

de Delete everything till the end of the word by pressing . at your heart's desire.

ci(xyz[Esc] -- This is a weird one. Here, the 'i' does not mean insert mode. Instead it means inside the parenthesis. So this sequence cuts the text inside parenthesis you're standing in and replaces it with "xyz". It also works inside square and figure brackets -- just do ci[ or ci{ correspondingly. Naturally, you can do di (if you just want to delete all text without typing anything. You can also do a instead of i if you want to delete the parentheses as well and not just text inside them.

ci" - cuts the text in current quotes

ciw - cuts the current word. This works just like the previous one except that ( is replaced with w.

C - cut the rest of the line and switch to insert mode.

ZZ -- save and close current file (WAY faster than Ctrl-F4 to close the current tab!)

ddp - move current line one row down

xp -- move current character one position to the right

U - uppercase, so viwU upercases the word

~ - switches case, so viw~ will reverse casing of entire word

Ctrl+u / Ctrl+d scroll the page half-a-screen up or down. This seems to be more useful than the usual full-screen paging as it makes it easier to see how the two screens relate. For those who still want to scroll entire screen at a time there's Ctrl+f for Forward and Ctrl+b for Backward. Ctrl+Y and Ctrl+E scroll down or up one line at a time.

Crazy but very useful command is zz -- it scrolls the screen to make this line appear in the middle. This is excellent for putting the piece of code you're working on in the center of your attention. Sibling commands -- zt and zb -- make this line the top or the bottom one on the sreen which is not quite as useful.

% finds and jumps to the matching parenthesis.

de -- delete from cursor to the end of the word (you can also do dE to delete until the next space)

bde -- delete the current word, from left to right delimiter

df[space] -- delete up until and including the next space

dt. -- delete until next dot

dd -- delete this entire line

ye (or yE) -- yanks text from here to the end of the word

ce - cuts through the end of the word

bye -- copies current word (makes me wonder what "hi" does!)

yy -- copies the current line

cc -- cuts the current line, you can also do S instead. There's also lower cap s which cuts current character and switches to insert mode.

viwy or viwc. Yank or change current word. Hit w multiple times to keep selecting each subsequent word, use b to move backwards

vi{ - select all text in figure brackets. va{ - select all text including {}s

vi(p - highlight everything inside the ()s and replace with the pasted text

b and e move the cursor word-by-word, similarly to how Ctrl+Arrows normally do. The definition of word is a little different though, as several consecutive delmiters are treated as one word. If you start at the middle of a word, pressing b will always get you to the beginning of the current word, and each consecutive b will jump to the beginning of the next word. Similarly, and easy to remember, e gets the cursor to the end of the current, and each subsequent, word.

similar to b/e, capital B and E move the cursor word-by-word using only whitespaces as delimiters.

capital D (take a deep breath) Deletes the rest of the line to the right of the cursor, same as Shift+End/Del in normal editors (notice 2 keypresses -- Shift+D -- instead of 3)

﹏雨一样淡蓝的深情 2024-07-23 18:33:24

我在大多数 Vim 教程中很少找到,但它非常有用(至少对我来说),就是

g; 和 g,

在变更列表中移动(向前、向后)。

让我展示一下我如何使用它。 有时我需要复制并粘贴一段代码或字符串,比如CSS文件中的十六进制颜色代码,所以我搜索,跳转(不关心匹配在哪里),复制它,然后跳回(g;)到哪里我正在编辑代码,最后粘贴它。 无需创建标记。 更简单。

只是我的2分钱。

One that I rarely find in most Vim tutorials, but it's INCREDIBLY useful (at least to me), is the

g; and g,

to move (forward, backward) through the changelist.

Let me show how I use it. Sometimes I need to copy and paste a piece of code or string, say a hex color code in a CSS file, so I search, jump (not caring where the match is), copy it and then jump back (g;) to where I was editing the code to finally paste it. No need to create marks. Simpler.

Just my 2cents.

安静 2024-07-23 18:33:24
:%!xxd

让vim成为一个十六进制编辑器。

:%!xxd -r

恢复。

警告:如果您不使用二进制 (-b) 进行编辑,则可能会损坏文件。 – Josh Lee 在评论中。

:%!xxd

Make vim into a hex editor.

:%!xxd -r

Revert.

Warning: If you don't edit with binary (-b), you might damage the file. – Josh Lee in the comments.

画中仙 2024-07-23 18:33:24
gv

重新选择最后的视觉选择。

gv

Reselects last visual selection.

瞳孔里扚悲伤 2024-07-23 18:33:24

有时 .vimrc 中的设置会被插件或自动命令覆盖。 要调试此问题,一个有用的技巧是将 :verbose 命令与 :set 结合使用。 例如,要找出 cindent 设置/取消设置的位置:

:verbose set cindent?

这将输出类似以下内容:

cindent
    Last set from /usr/share/vim/vim71/indent/c.vim

这也适用于地图和高亮显示。 (感谢 joeytwiddle 指出了这一点。)例如:

:verbose nmap U
n  U             <C-R>
        Last set from ~/.vimrc

:verbose highlight Normal
Normal         xxx guifg=#dddddd guibg=#111111 font=Inconsolata Medium 14
        Last set from ~/src/vim-holodark/colors/holodark.vim

Sometimes a setting in your .vimrc will get overridden by a plugin or autocommand. To debug this a useful trick is to use the :verbose command in conjunction with :set. For example, to figure out where cindent got set/unset:

:verbose set cindent?

This will output something like:

cindent
    Last set from /usr/share/vim/vim71/indent/c.vim

This also works with maps and highlights. (Thanks joeytwiddle for pointing this out.) For example:

:verbose nmap U
n  U             <C-R>
        Last set from ~/.vimrc

:verbose highlight Normal
Normal         xxx guifg=#dddddd guibg=#111111 font=Inconsolata Medium 14
        Last set from ~/src/vim-holodark/colors/holodark.vim
放血 2024-07-23 18:33:24

:%TOhtml

创建当前文件的 html 呈现。

:%TOhtml

Creates an html rendering of the current file.

吃颗糖壮壮胆 2024-07-23 18:33:24

不确定这是否算作黑暗角落,但我才刚刚了解到它......

:g/match/y A

将把所有包含“match”的行猛拉(复制)到 “a/@a 寄存器。(A 的大写使得 vim append 复制而不是替换以前的寄存器内容。)我最近在制作 Internet 时经常使用它。资源管理器样式表。

Not sure if this counts as dark-corner-ish at all, but I've only just learnt it...

:g/match/y A

will yank (copy) all lines containing "match" into the "a/@a register. (The capitalization as A makes vim append yankings instead of replacing the previous register contents.) I used it a lot recently when making Internet Explorer stylesheets.

橙幽之幻 2024-07-23 18:33:24

想查看您的 :命令历史记录吗?

q:

然后浏览、编辑,最后执行命令。

曾经对两个文件进行过类似的更改并在它们之间来回切换吗? (比如,源文件和头文件?)

:set hidden
:map <TAB> :e#<CR>

然后在这些文件之间来回切换。

Want to look at your :command history?

q:

Then browse, edit and finally to execute the command.

Ever make similar changes to two files and switch back and forth between them? (Say, source and header files?)

:set hidden
:map <TAB> :e#<CR>

Then tab back and forth between those files.

錯遇了你 2024-07-23 18:33:24

Vim 会打开一个 URL,例如Nice。

vim http://stackoverflow.com/

当你需要提取页面源代码以供参考时,

Vim will open a URL, for example

vim http://stackoverflow.com/

Nice when you need to pull up the source of a page for reference.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文