Reputation: 1466
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>
Upvotes: 0
Views: 269
Reputation: 196546
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
Upvotes: 1
Reputation: 195059
in short, buffer, is in mem text of your file, which you can see by :ls
and edit. script, could be loaded by vim as well, however you cannot see it in :ls
command. E.g., you create vim file, say foo.vim
:
function! s:SayHi() abort
echo "Hi, there"
endfunction
And in your vimrc
file, you source the foo.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 with nnoremap
.
An example perhaps is better. Say the same foo.vim
, we have two mappings:
nnoremap <SID>foo dowhatever
nnoremap abc <SID>foo
in this way, abc
won't eventually go to dowhatever
, because of the nore
. However
nnoremap <SID>foo dowhatever
nnoremap <script> abc <SID>foo
This will overwrite the nore
rule, abc
will reach dowhatever
. but only if the first mapping was defined in the same script. (nnoremap <script>
and nmap <script>
are doing same)
Personally I don't think <script>
map is really useful.
Upvotes: 3