I'm working on vim
editor and want to edit some default options provided by vim editor.
我正在使用vim编辑器,想要编辑vim编辑器提供的一些默认选项。
i.e N+G(5G) to move to nth line but I want N+Enter to move to nth line
即N + G(5G)移动到第n行,但我希望N + Enter移动到第n行
likewise:
^ want change to s
^想要改变为s
$ want change to e
$想要改变e
etc
1 个解决方案
#1
3
With the right terminology, you should be able to look up these simple tasks in the excellent and comprehensive :help
.
使用正确的术语,您应该能够在优秀而全面的帮助中查找这些简单的任务。
Options influence the behavior of Vim. For example, :set wrap
enables (soft) line breaking of long lines. You'll find it under :help 'wrap'
; options are wrapped in single quotes in the help; :help options
has them all.
选项会影响Vim的行为。例如,:set wrap使(长线)线条断开。你会发现它:help'wrap';选项包含在帮助中的单引号中; :帮助选项包含所有内容。
That's not what you're after, though. You want to change the keys that trigger certain, built-in behavior. That's called mapping, documented under :help mapping
.
不过,那不是你想要的。您想要更改触发某些内置行为的键。这称为映射,记录在:帮助映射。
To make <Enter>
do the same thing as G
(in normal mode), you'd use
要使
:nnoremap <Enter> G
:help key-notation
helps with how you specify the keys. You should use :noremap
; it makes the mapping immune to remapping and recursion. The [N]
count is separate from the command itself; you can ignore it here.
:help key-notation有助于指定键的方式。你应该使用:noremap;它使映射不受重映射和递归的影响。 [N]计数与命令本身是分开的;你可以在这里忽略它。
Likewise, you can do:
同样,你可以这样做:
:nnoremap s ^
:nnoremap e $
However, note that this will override very useful built-in commands (s
replaces the current [count]
characters and starts editing, e
moves to the end of word; you can look these up with :help s
and :help e
). Vim has attracted so many followers because of its very efficient mode-based command model; if you instead try to reconfigure Vim heavily, you're commiting a typical beginner's mistake!
但是,请注意,这将覆盖非常有用的内置命令(s替换当前[count]字符并开始编辑,e移动到单词的结尾;您可以使用:help s和:help e查看这些命令)。由于其基于模式的高效命令模型,Vim吸引了众多粉丝;如果你试图重新配置Vim,你就会犯一个典型的初学者的错误!
Persistence
All the above commands only persist for the current Vim session, so you can safely try them out. To make them permanent, put them into a ~/.vimrc
configuration file (:help vimrc
), and restart Vim. The :
prefix is optional in that file; scripts use Ex mode, not normal mode.
以上所有命令仅在当前的Vim会话中保留,因此您可以安全地尝试它们。要使它们永久化,请将它们放入〜/ .vimrc配置文件(:help vimrc),然后重新启动Vim。 :前缀在该文件中是可选的;脚本使用Ex模式,而不是普通模式。
#1
3
With the right terminology, you should be able to look up these simple tasks in the excellent and comprehensive :help
.
使用正确的术语,您应该能够在优秀而全面的帮助中查找这些简单的任务。
Options influence the behavior of Vim. For example, :set wrap
enables (soft) line breaking of long lines. You'll find it under :help 'wrap'
; options are wrapped in single quotes in the help; :help options
has them all.
选项会影响Vim的行为。例如,:set wrap使(长线)线条断开。你会发现它:help'wrap';选项包含在帮助中的单引号中; :帮助选项包含所有内容。
That's not what you're after, though. You want to change the keys that trigger certain, built-in behavior. That's called mapping, documented under :help mapping
.
不过,那不是你想要的。您想要更改触发某些内置行为的键。这称为映射,记录在:帮助映射。
To make <Enter>
do the same thing as G
(in normal mode), you'd use
要使
:nnoremap <Enter> G
:help key-notation
helps with how you specify the keys. You should use :noremap
; it makes the mapping immune to remapping and recursion. The [N]
count is separate from the command itself; you can ignore it here.
:help key-notation有助于指定键的方式。你应该使用:noremap;它使映射不受重映射和递归的影响。 [N]计数与命令本身是分开的;你可以在这里忽略它。
Likewise, you can do:
同样,你可以这样做:
:nnoremap s ^
:nnoremap e $
However, note that this will override very useful built-in commands (s
replaces the current [count]
characters and starts editing, e
moves to the end of word; you can look these up with :help s
and :help e
). Vim has attracted so many followers because of its very efficient mode-based command model; if you instead try to reconfigure Vim heavily, you're commiting a typical beginner's mistake!
但是,请注意,这将覆盖非常有用的内置命令(s替换当前[count]字符并开始编辑,e移动到单词的结尾;您可以使用:help s和:help e查看这些命令)。由于其基于模式的高效命令模型,Vim吸引了众多粉丝;如果你试图重新配置Vim,你就会犯一个典型的初学者的错误!
Persistence
All the above commands only persist for the current Vim session, so you can safely try them out. To make them permanent, put them into a ~/.vimrc
configuration file (:help vimrc
), and restart Vim. The :
prefix is optional in that file; scripts use Ex mode, not normal mode.
以上所有命令仅在当前的Vim会话中保留,因此您可以安全地尝试它们。要使它们永久化,请将它们放入〜/ .vimrc配置文件(:help vimrc),然后重新启动Vim。 :前缀在该文件中是可选的;脚本使用Ex模式,而不是普通模式。