What are the actual differences between typing:
:map <script> , dd:map , dd:map <buffer> , dd:map <script> <buffer> , dd
I am much more concerned with <script> arguments. In which cases we need to use the argument <script>
What are the actual differences between typing:
:map <script> , dd
:map , dd
:map <buffer> , dd
:map <script> <buffer> , dd
I am much more concerned with <script> arguments. In which cases we need to use the argument <script>
On
A "script" is a bunch of related Ex commands and vimscript functions put together in a *.vim file.
Upon startup, Vim sources a number of "scripts". It means that it executes each line in each script just like if you wrote it in the command-line yourself. Additionally, Vim keeps track of what was sourced where with the <SID> mechanism. "Scripts" are used internally by Vim to provide additional functionalities.
The meaning of the <script> argument is clearly explained in :h <script>:
If the first argument to one of these commands is "
<script>" and it is used to define a new mapping or abbreviation, the mapping will only remap characters in the{rhs}using mappings that were defined local to a script, starting with "<SID>". This can be used to avoid that mappings from outside a script interfere (e.g., when CTRL-V is remapped in mswin.vim), but do use other mappings defined in the script.
A "buffer" is the in-memory representation of the content of a file. Think of it as a "document" in regular programs.
When you edit a "buffer" and you define a <buffer> mapping, that mapping will only be available in that specific buffer.
Going with your examples:
" - remapping is possible but only with other
" mappings defined in the same script
:map <script> , dd
" - mapping is global
" - remapping is possible
:map , dd
" - mapping is buffer-local
" - remapping is possible
:map <buffer> , dd
" - mapping is buffer-local
" - remapping is possible but only with other
" mappings defined in the same script
:map <script> <buffer> , dd
in short, buffer, is in mem text of your file, which you can see by
:lsand edit. script, could be loaded by vim as well, however you cannot see it in:lscommand. E.g., you create vim file, sayfoo.vim:And in your
vimrcfile, you source thefoo.vim, now there is a script scope. The mapping with<script>will make the{rhs}call other mapping, which is defined in same script, even if withnnoremap.An example perhaps is better. Say the same
foo.vim, we have two mappings:in this way,
abcwon't eventually go todowhatever, because of thenore. HoweverThis will overwrite the
norerule,abcwill reachdowhatever. but only if the first mapping was defined in the same script. (nnoremap <script>andnmap <script>are doing same)Personally I don't think
<script>map is really useful.