What are the dark corners of Vim your mom never to

2019-01-09 20:21发布

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.

标签: unix vim editor vi
30条回答
聊天终结者
2楼-- · 2019-01-09 21:09

:%TOhtml

Creates an html rendering of the current file.

查看更多
来,给爷笑一个
3楼-- · 2019-01-09 21:09
imap jj <esc>
查看更多
爷、活的狠高调
4楼-- · 2019-01-09 21:09

Map F5 to quickly ROT13 your buffer:

map <F5> ggg?G``

You can use it as a boss key :).

查看更多
可以哭但决不认输i
5楼-- · 2019-01-09 21:10

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

查看更多
时光不老,我们不散
6楼-- · 2019-01-09 21:10

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

cd %:h
查看更多
Juvenile、少年°
7楼-- · 2019-01-09 21:11

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.

查看更多
登录 后发表回答