Skip to main content
Corrections to teminology (in title) as pointed out by @romani
Link

How can I chain multiple commands in one Leader commandmapping?

Make corrections to terminology pointed out by romain.
Source Link

These two mappings work separately:

nnoremap <leader>zs :let @+=substitute(substitute(join(filter(getline(1,'$'),'v:val=~"^source:"'),"\n"),'^\(source:\s*\)\(.*\)$','\2',''),'^\s*\(.*\)$','\1','')<CR><ESC>
nnoremap <leader>zd :let @+=getline('.')<CR>

Note on what the codes need to accomplish: the first leader entrymapping copies into system clipboard the text following "source: "; the second leader entrymapping copies the currently cursored line into system clipboard. I use a clipboard manager (Parcellite) thus I prefer to copy multiple items (separately) from a text file into clipboard.

How do I combine them into a single leader entrymapping?

I've tried following this answer to produce:

nnoremap <leader>zs :let @+=substitute(substitute(join(filter(getline(1,'$'),'v:val=~"^source:"'),"\n"),'^\(source:\s*\)\(.*\)$','\2',''),'^\s*\(.*\)$','\1','') \| let @+=getline('.')<CR>

but this doesn't work. What could I be doing wrong?

[UPDATE]

To illustrate, here is a sample text showing [*] where the cursor is currently in:

Her research also shows about 14% of adults are clinically addicted to food, predominantly ultraprocessed foods with higher levels of sugar, salt, fat and additives.

For comparison, 10.5% of Americans age 12 or older were diagnosed with alcohol use disorder in 2022, according to the National Survey on Drug Use and Health. [*]

While many people addicted to food will say that their symptoms began to worsen significantly in adolescence, some recall a childhood focused on ultraprocessed food.

source: https://edition.cnn.com/2024/06/27/health/child-addiction-ultraprocessed-foods-wellness/index.html

After pressing <leader>zs in vim, parcellite should show this when accessed:

what parcellite should show

These two mappings work separately:

nnoremap <leader>zs :let @+=substitute(substitute(join(filter(getline(1,'$'),'v:val=~"^source:"'),"\n"),'^\(source:\s*\)\(.*\)$','\2',''),'^\s*\(.*\)$','\1','')<CR><ESC>
nnoremap <leader>zd :let @+=getline('.')<CR>

Note on what the codes need to accomplish: the first leader entry copies into system clipboard the text following "source: "; the second leader entry copies the currently cursored line into system clipboard. I use a clipboard manager thus I prefer to copy multiple items (separately) from a text file into clipboard.

How do I combine them into a single leader entry?

I've tried following this answer to produce:

nnoremap <leader>zs :let @+=substitute(substitute(join(filter(getline(1,'$'),'v:val=~"^source:"'),"\n"),'^\(source:\s*\)\(.*\)$','\2',''),'^\s*\(.*\)$','\1','') \| let @+=getline('.')<CR>

but this doesn't work. What could I be doing wrong?

[UPDATE]

To illustrate, here is a sample text showing [*] where the cursor is currently in:

Her research also shows about 14% of adults are clinically addicted to food, predominantly ultraprocessed foods with higher levels of sugar, salt, fat and additives.

For comparison, 10.5% of Americans age 12 or older were diagnosed with alcohol use disorder in 2022, according to the National Survey on Drug Use and Health. [*]

While many people addicted to food will say that their symptoms began to worsen significantly in adolescence, some recall a childhood focused on ultraprocessed food.

source: https://edition.cnn.com/2024/06/27/health/child-addiction-ultraprocessed-foods-wellness/index.html

After pressing <leader>zs in vim, parcellite should show this when accessed:

what parcellite should show

These two mappings work separately:

nnoremap <leader>zs :let @+=substitute(substitute(join(filter(getline(1,'$'),'v:val=~"^source:"'),"\n"),'^\(source:\s*\)\(.*\)$','\2',''),'^\s*\(.*\)$','\1','')<CR><ESC>
nnoremap <leader>zd :let @+=getline('.')<CR>

Note on what the codes need to accomplish: the first mapping copies into system clipboard the text following "source: "; the second mapping copies the currently cursored line into system clipboard. I use a clipboard manager (Parcellite) thus I prefer to copy multiple items (separately) from a text file into clipboard.

How do I combine them into a single mapping?

I've tried following this answer to produce:

nnoremap <leader>zs :let @+=substitute(substitute(join(filter(getline(1,'$'),'v:val=~"^source:"'),"\n"),'^\(source:\s*\)\(.*\)$','\2',''),'^\s*\(.*\)$','\1','') \| let @+=getline('.')<CR>

but this doesn't work. What could I be doing wrong?

[UPDATE]

To illustrate, here is a sample text showing [*] where the cursor is currently in:

Her research also shows about 14% of adults are clinically addicted to food, predominantly ultraprocessed foods with higher levels of sugar, salt, fat and additives.

For comparison, 10.5% of Americans age 12 or older were diagnosed with alcohol use disorder in 2022, according to the National Survey on Drug Use and Health. [*]

While many people addicted to food will say that their symptoms began to worsen significantly in adolescence, some recall a childhood focused on ultraprocessed food.

source: https://edition.cnn.com/2024/06/27/health/child-addiction-ultraprocessed-foods-wellness/index.html

After pressing <leader>zs in vim, parcellite should show this when accessed:

what parcellite should show

Overexplanation deleted
Source Link

I have a narrative text file containing data scattered all over the place and my task is to organize those data into a spreadsheet. The basic way I can do that is copy a single data from the text file into to the clipboard, switch to the spreadsheet application, and paste the data into the appropriate cell. Repeat switching between vim and the spreadsheet application until all the data I need is into the spreadsheet file.

One way I know in sprinkling a dash of simplification to the process is

  1. to harvest each pre-shredded bit of data while I am in vim
  2. dump each item into the clipboard, each item occupying a "cell" in clipboard history stack (using parcellite)
  3. when I switch to the spreadsheet, I just access parcellite history stack, and one data at a time paste each into a spreadsheet cell.

Steps #1 and #2 somewhat reduces some of the repetition, but I want to go a little further with some of the data that can immediately be identified by vim, namely, the line of text that begins with "source: " and the current line the cursor is in.

This is where the proposed vim code comes in. What I want the code to accomplish while in vim is to copy the data that begins with the keyword "source" (<leader>zs in the example above) into clipboard, then copy the current line the cursor is in (<leader>zd in the example above), again into the same clipboard history stack. But both of these procedures combined into just one <leader>zs, one procedure after the other, accomplishing steps 1 and [2] for these two particular pieces of data. The end result giving me the source and the line on top of one another in the clipboard history stack.

To illustrate, here is a sample text showing [*] where the cursor is currently in:

I have a narrative text file containing data scattered all over the place and my task is to organize those data into a spreadsheet. The basic way I can do that is copy a single data from the text file into to the clipboard, switch to the spreadsheet application, and paste the data into the appropriate cell. Repeat switching between vim and the spreadsheet application until all the data I need is into the spreadsheet file.

One way I know in sprinkling a dash of simplification to the process is

  1. to harvest each pre-shredded bit of data while I am in vim
  2. dump each item into the clipboard, each item occupying a "cell" in clipboard history stack (using parcellite)
  3. when I switch to the spreadsheet, I just access parcellite history stack, and one data at a time paste each into a spreadsheet cell.

Steps #1 and #2 somewhat reduces some of the repetition, but I want to go a little further with some of the data that can immediately be identified by vim, namely, the line of text that begins with "source: " and the current line the cursor is in.

This is where the proposed vim code comes in. What I want the code to accomplish while in vim is to copy the data that begins with the keyword "source" (<leader>zs in the example above) into clipboard, then copy the current line the cursor is in (<leader>zd in the example above), again into the same clipboard history stack. But both of these procedures combined into just one <leader>zs, one procedure after the other, accomplishing steps 1 and [2] for these two particular pieces of data. The end result giving me the source and the line on top of one another in the clipboard history stack.

To illustrate, here is a sample text showing [*] where the cursor is currently in:

To illustrate, here is a sample text showing [*] where the cursor is currently in:

Provide further clarification and illustration
Source Link
Loading
seems unrelated to vimrc, remove blockquote which seems off
Source Link
Friedrich
  • 3.3k
  • 1
  • 13
  • 26
Loading
Source Link
Loading