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.