Skip to main content
added 87 characters in body
Source Link
user202729
  • 339
  • 1
  • 10

It's possible to use a mapping like this:

inoremap <silent> sf <c-r><c-r>=getline('.')[:col('.')-2]->substitute('.*;','','')->substitute('=.*','','')->trim()<cr>

Or an abbreviation (if the keychain consists of only "normal" keys, it's preferred to mapping, as a mapping may conflict with a part of another word, such as transform):

abbr <expr> sf getline('.')[:col('.')-2]->substitute('.*;','','')->substitute('=.*','','')->trim()

(it's necessary to have -2 because col() returns the 1-indexing index of the next character on the cursor, while [:] takes the 0-indexing byte index of the last character to be included)

This uses function or "method" chaining, a feature new to Vim 8.2. For older version where such method calls are not available it's possible to instead use:

inoremapabbr <silent><expr> sf <c-r><c-r>=trimtrim(substitute(substitute(getline('.')[:col('.')-2],'.*;','',''),'=.*','',''))

So you only need to type

table[row][col] = std::max(sf, other_table[row+1][col+1])

The sf typed will expand to table[row][col] in this case.

It's possible to use a mapping like this:

inoremap <silent> sf <c-r><c-r>=getline('.')[:col('.')-2]->substitute('.*;','','')->substitute('=.*','','')->trim()<cr>

(it's necessary to have -2 because col() returns the 1-indexing index of the next character on the cursor, while [:] takes the 0-indexing byte index of the last character to be included)

This uses function or "method" chaining, a feature new to Vim 8.2. For older version where such method calls are not available it's possible to instead use:

inoremap <silent> sf <c-r><c-r>=trim(substitute(substitute(getline('.')[:col('.')-2],'.*;','',''),'=.*','',''))

So you only need to type

table[row][col] = std::max(sf, other_table[row+1][col+1])

The sf typed will expand to table[row][col] in this case.

It's possible to use a mapping:

inoremap <silent> sf <c-r><c-r>=getline('.')[:col('.')-2]->substitute('.*;','','')->substitute('=.*','','')->trim()<cr>

Or an abbreviation (if the keychain consists of only "normal" keys, it's preferred to mapping, as a mapping may conflict with a part of another word, such as transform):

abbr <expr> sf getline('.')[:col('.')-2]->substitute('.*;','','')->substitute('=.*','','')->trim()

(it's necessary to have -2 because col() returns the 1-indexing index of the next character on the cursor, while [:] takes the 0-indexing byte index of the last character to be included)

This uses function or "method" chaining, a feature new to Vim 8.2. For older version where such method calls are not available it's possible to instead use:

abbr <expr> sf trim(substitute(substitute(getline('.')[:col('.')-2],'.*;','',''),'=.*','',''))

So you only need to type

table[row][col] = std::max(sf, other_table[row+1][col+1])

The sf typed will expand to table[row][col] in this case.

added 157 characters in body
Source Link
user202729
  • 339
  • 1
  • 10

It's possible to use a mapping like this:

inoremap <silent> sf <c-r><c-r>=getline('.')->strcharpart(0,getpos[:col('.')[2]-1)2]->substitute('.*;','','')->substitute('=.*','','')->trim()<cr>

(it's necessary to have -2 because col() returns the 1-indexing index of the next character on the cursor, while [:] takes the 0-indexing byte index of the last character to be included)

This uses function or "method" chaining, a feature new to Vim 8.2. For older version where such method calls are not available it's possible to instead use:

inoremap <silent> sf <c-r><c-r>=trim(substitute(substitute(strcharpart(getline('.'),0,getpos[:col('.')[2]-1)2],'.*;','',''),'=.*','',''))

So you only need to type

table[row][col] = std::max(sf, other_table[row+1][col+1])

The sf typed will expand to table[row][col] in this case.

It's possible to use a mapping like this:

inoremap <silent> sf <c-r><c-r>=getline('.')->strcharpart(0,getpos('.')[2]-1)->substitute('.*;','','')->substitute('=.*','','')->trim()<cr>

This uses function or "method" chaining, a feature new to Vim 8.2. For older version where such method calls are not available it's possible to instead use:

inoremap <silent> sf <c-r><c-r>=trim(substitute(substitute(strcharpart(getline('.'),0,getpos('.')[2]-1),'.*;','',''),'=.*','',''))

So you only need to type

table[row][col] = std::max(sf, other_table[row+1][col+1])

The sf typed will expand to table[row][col] in this case.

It's possible to use a mapping like this:

inoremap <silent> sf <c-r><c-r>=getline('.')[:col('.')-2]->substitute('.*;','','')->substitute('=.*','','')->trim()<cr>

(it's necessary to have -2 because col() returns the 1-indexing index of the next character on the cursor, while [:] takes the 0-indexing byte index of the last character to be included)

This uses function or "method" chaining, a feature new to Vim 8.2. For older version where such method calls are not available it's possible to instead use:

inoremap <silent> sf <c-r><c-r>=trim(substitute(substitute(getline('.')[:col('.')-2],'.*;','',''),'=.*','',''))

So you only need to type

table[row][col] = std::max(sf, other_table[row+1][col+1])

The sf typed will expand to table[row][col] in this case.

Rollback to Revision 3
Source Link
user202729
  • 339
  • 1
  • 10

It's possible to use a mapping like this:

inoremap <silent> sf <c-r><c-r>=getline('.')->matchlist('\v.*>strcharpart(;<bar>^)\s*0,getpos('.{')[2]-}1)\s*->substitute(\='.**;','','')?%'.col->substitute(''=.'*','','').'c'->trim()[2]<cr><cr>

This uses function or "method" chaining, a feature new to Vim 8.2. For older version where such method calls are not available it's possible to instead use:

inoremap <silent> sf <c-r><c-r>=matchlistr>=trim(substitute(substitute(strcharpart(getline('.'),'\v.*(;<bar>^)\s*0,getpos('.{-}')\s*(\=.*[2]-1)?%'.col(,'.'*;','',''),'=.'c'*','','')[2]<cr>)

So you only need to type

table[row][col] = std::max(sf, other_table[row+1][col+1])

The sf typed will expand to table[row][col] in this case.

It's possible to use a mapping like this:

inoremap <silent> sf <c-r><c-r>=getline('.')->matchlist('\v.*(;<bar>^)\s*(.{-})\s*(\=.*)?%'.col('.').'c')[2]<cr>

This uses function or "method" chaining, a feature new to Vim 8.2. For older version where such method calls are not available it's possible to instead use:

inoremap <silent> sf <c-r><c-r>=matchlist(getline('.'),'\v.*(;<bar>^)\s*(.{-})\s*(\=.*)?%'.col('.').'c')[2]<cr>

So you only need to type

table[row][col] = std::max(sf, other_table[row+1][col+1])

The sf typed will expand to table[row][col] in this case.

It's possible to use a mapping like this:

inoremap <silent> sf <c-r><c-r>=getline('.')->strcharpart(0,getpos('.')[2]-1)->substitute('.*;','','')->substitute('=.*','','')->trim()<cr>

This uses function or "method" chaining, a feature new to Vim 8.2. For older version where such method calls are not available it's possible to instead use:

inoremap <silent> sf <c-r><c-r>=trim(substitute(substitute(strcharpart(getline('.'),0,getpos('.')[2]-1),'.*;','',''),'=.*','',''))

So you only need to type

table[row][col] = std::max(sf, other_table[row+1][col+1])

The sf typed will expand to table[row][col] in this case.

deleted 50 characters in body
Source Link
user202729
  • 339
  • 1
  • 10
Loading
Doc links for new feature
Source Link
B Layer
  • 20.1k
  • 2
  • 32
  • 59
Loading
added 232 characters in body
Source Link
user202729
  • 339
  • 1
  • 10
Loading
Source Link
user202729
  • 339
  • 1
  • 10
Loading