1
 (A) Upper and lower limits on numeric data.
 (B) Passwords to prohibit unauthorised access to files.
 (C) Data dictionary to keep the data
 (D) Data dictionary to find last access of data

I want to copy the (A) to buffer-a, (B) to buffer-b, etc.

I want to use the key s for this purpose. sa should copy the current line to buffer-a, sb to buffer-b, etc.

I wrote the code :map s "ayy to map s to copy the current line to buffer-a

But I don't have any idea how to pass the buffer name. (The character typing after s.)

UPDATE: Want to copy to register, not buffer!!

Mohammed H
  • 6,880
  • 16
  • 81
  • 127
  • There is a nice series of [Vimcasts](http://vimcasts.org/) episodes that cover register usage: [The copy/paste series - a retrospective](http://vimcasts.org/episodes/simple-operations-using-the-default-register/) – Peter Rincker Nov 18 '14 at 15:41

2 Answers2

5
  • What you are trying to do is coping lines to register, not buffer, your question is pretty confusing. they are two totally different things in vim.

  • try to find another key-combination for your mapping. s is so useful. Maybe you could try <leader>sX(X here is the register name)

Your requirement could be achieved by using <expr> mapping, this mapping would do it for you:

nnoremap <expr> <leader>s '"'.nr2char(getchar()).'Y'

If you press <leader>sa the line under your cursor will be yanked to register a. <leader>sm will yank current line to register m and so on.

default <leader> is \, :h leader for details.

Kent
  • 189,393
  • 32
  • 233
  • 301
3

An alternative to Kent's approach with getchar() is to restructure your mapping to "as instead of sa. That would also be in line with Vim's built in command scheme (where "ayy is yanking to register a). With that, you'll get the parsing of the register for free, in the form of the v:register variable.

Your s mapping would then be just :nnoremap s yy; the register part would automatically be passed to yy. For a more complex mapping, you could use:

:nnoremap <silent> s :execute '"' . v:register . 'yy'<CR>
Ingo Karkat
  • 167,457
  • 16
  • 250
  • 324