1

I've posted a number of times to try and get closer to what I'm trying to do. My problem is I have got the commands I need to make the conversion happen, however I cannot successfully map it to a key.

This is the type of sequences I have to convert (123456789 representing any number combination):

0010|C|||N12345678|W1234567891234
0010|H|S12345678|E123456789||
0020|L|N12345678|W123456789|N12345678|W12345678912341234
0030|G|N12345678|W123456789||
0020|R|N12345678|W123456789|N12345678|W12345678912341234

This is my desired outcome:

0010|C|||N12345678|W123456789|123.4
0010|H|S12345678|E123456789||
0020|L|N12345678|W123456789|N12345678|W123456789|123.4|123.4
0030|G|N12345678|W123456789||
0020|R|N12345678|W123456789|N12345678|W123456789|123.4|123.4

A member on reddit came up with two global commands which does exactly what I need it to:

:global/|C|/execute "normal $3hi|\<Esc>$i."

:g/|L|\||R|/execute "normal $7hi|\<Esc>4li.\<Esc>2li|\<Esc>$i."

anyone able to map it to a single key?

2

Trying to cram that in a single line could get a bit ugly without any particular advantage. Simplest approach is going to be to put the commands in a function in your vimrc like so:

function! ConvertNumCols()
  global/|C|/execute "normal $3hi|\<Esc>$i."
  g/|L|\||R|/execute "normal $7hi|\<Esc>4li.\<Esc>2li|\<Esc>$i."
endfunction

Along with a mapping that calls it

nnoremap X :call ConvertNumCols()<CR>

Replace X with whatever key or keys that you want.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.