为啥这个vim的命令可以做到排版的作用呢?

43 views
Skip to first unread message

Wizard

unread,
Jan 23, 2015, 3:50:37 AM1/23/15
to shlug
http://stackoverflow.com/questions/3033423/vim-command-to-restructure-force-text-to-80-columns

上面的是原贴, 使用了,确实可以做到让原来超长的行自动换行。
但是没看懂这个是具体怎么实现的。


gqG

g 应该是 global , 说是找到一个模式,然后执行某个命令。
q 说是记录后面的命令到一个register。
G 是到文件末尾


但是合起来我就看不懂怎么能做到排版文件的。。。


--
Wizard

AR

unread,
Jan 23, 2015, 3:55:31 AM1/23/15
to sh...@googlegroups.com
在vim里

:help gq


gq{motion} Format the lines that {motion} moves over.
Formatting is done with one of three methods:
1. If 'formatexpr' is not empty the expression is
evaluated. This can differ for each buffer.
2. If 'formatprg' is not empty an external program
is used.
3. Otherwise formatting is done internally.

In the third case the 'textwidth' option controls the
length of each formatted line (see below).
If the 'textwidth' option is 0, the formatted line
length is the screen width (with a maximum width of
79).
The 'formatoptions' option controls the type of
formatting fo-table.
The cursor is left on the first non-blank of the last
formatted line.


原帖里说了,先移动到文件开头去,这里motion的那个G就是操作到文件末尾。


--
Silence is golden.

Wizard

unread,
Jan 24, 2015, 9:59:44 AM1/24/15
to shlug
多谢啊, 原来这gq一起就是一个命令。。。
> --
> -- You received this message because you are subscribed to the Google Groups Shanghai Linux User Group group. To post to this group, send email to sh...@googlegroups.com. To unsubscribe from this group, send email to shlug+un...@googlegroups.com. For more options, visit this group at https://groups.google.com/d/forum/shlug?hl=zh-CN
> ---
> 您收到此邮件是因为您订阅了 Google 网上论坛的“Shanghai Linux User Group”群组。
> 要退订此群组并停止接收此群组的电子邮件,请发送电子邮件到shlug+un...@googlegroups.com
> 要查看更多选项,请访问 https://groups.google.com/d/optout



--
Wizard

Jerry Ling

unread,
Feb 5, 2015, 11:40:58 PM2/5/15
to sh...@googlegroups.com
是gg=G

--
-- You received this message because you are subscribed to the Google Groups Shanghai Linux User Group group. To post to this group, send email to sh...@googlegroups.com. To unsubscribe from this group, send email to shlug+unsubscribe@googlegroups.com. For more options, visit this group at https://groups.google.com/d/forum/shlug?hl=zh-CN

---
您收到此邮件是因为您订阅了 Google 网上论坛的“Shanghai Linux User Group”群组。
要退订此群组并停止接收此群组的电子邮件,请发送电子邮件到shlug+unsubscribe@googlegroups.com
要查看更多选项,请访问 https://groups.google.com/d/optout
Reply all
Reply to author
Forward
0 new messages