In VIM in command line mode a "%" denotes the current file, "cword" denotes the current word under the cursor. I want to create a shortcut where I need the current line number. What is the symbol which denotes this?
在命令行模式的VIM中,“%”表示当前文件,“cword”表示光标下的当前字。我想创建一个我需要当前行号的快捷方式。表示这个的符号是什么?
4 个解决方案
#1
11
If you want to pass the current line number to a shell command, you could do
如果要将当前行号传递给shell命令,则可以执行此操作
:exe "!echo " . line(".")
#2
14
. (dot) stands for the current line.
。 (点)代表当前行。
To clarify: This is meant for stuff like :1,.s/foo/bar/g
which will transform every foo
to bar
from the beginning of the file up to the current line.
澄清一下:这适用于以下内容:1,.s / foo / bar / g,它会将每个foo从文件开头转换为bar到当前行。
I don't know know of a way to get the current line number expanded for a shell command, which is what you are trying to do by doing :!echo .
我不知道如何获得为shell命令扩展的当前行号,这是你要做的事情:!echo。
You can find out about the expansions that are done (like %
and #
for example) in :he cmdline-special
.
您可以在以下位置找到已完成的扩展(例如%和#):he cmdline-special。
#3
2
To return the line number of current line at bottom of screen, use:
要返回屏幕底部当前行的行号,请使用:
:.=
#4
1
Commands in vim works on the current line so:
vim中的命令适用于当前行,因此:
:s/foo/bar/g
will transform every foo in bar on the line you are currently on.
将改变您当前所在行中的每个foo。
#1
11
If you want to pass the current line number to a shell command, you could do
如果要将当前行号传递给shell命令,则可以执行此操作
:exe "!echo " . line(".")
#2
14
. (dot) stands for the current line.
。 (点)代表当前行。
To clarify: This is meant for stuff like :1,.s/foo/bar/g
which will transform every foo
to bar
from the beginning of the file up to the current line.
澄清一下:这适用于以下内容:1,.s / foo / bar / g,它会将每个foo从文件开头转换为bar到当前行。
I don't know know of a way to get the current line number expanded for a shell command, which is what you are trying to do by doing :!echo .
我不知道如何获得为shell命令扩展的当前行号,这是你要做的事情:!echo。
You can find out about the expansions that are done (like %
and #
for example) in :he cmdline-special
.
您可以在以下位置找到已完成的扩展(例如%和#):he cmdline-special。
#3
2
To return the line number of current line at bottom of screen, use:
要返回屏幕底部当前行的行号,请使用:
:.=
#4
1
Commands in vim works on the current line so:
vim中的命令适用于当前行,因此:
:s/foo/bar/g
will transform every foo in bar on the line you are currently on.
将改变您当前所在行中的每个foo。