Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is vim's @@ variable?

Tags:

vim

I know that by typing @@ I execute the last @ command. But can anyone explain what @@ is in the code below (found in the vim help files)?:

function! CountSpaces(type, ...)
  let sel_save = &selection
  let reg_save = @@

  if a:0
    silent exe "normal! `<" . a:type . "`>y"
  elseif a:type == 'line'
    silent exe "normal! '[V']y"
  elseif a:type == 'block'
    silent exe "normal! `[\<C-V>`]y"
  else
    silent exe "normal! `[v`]y"
  endif

  echomsg strlen(substitute(@@, '[^ ]', '', 'g'))

  let &selection = sel_save
  let @@ = reg_save
endfunction

It appears to be a register, but it isn't in the list at :help registers. From reading the code I'd guess it is the default register for yanking/deleting? Is this documented anywhere? All my searches just yield the @@ idiom that executes the last @ command.

like image 216
Paul A Jungwirth Avatar asked Dec 15 '10 21:12

Paul A Jungwirth


1 Answers

:help @r gives me

register                        *expr-register* *@r*
--------
@r          contents of register 'r'

The result is the contents of the named register, as a single string.
Newlines are inserted where required.  To get the contents of the unnamed
register use @" or @@.  See |registers| for an explanation of the available
registers.

So, @@ will have the value of the text deleted with a d, c, s or x command, or the the text yanked with a y command.

like image 195
René Nyffenegger Avatar answered Oct 08 '22 19:10

René Nyffenegger