0

I am using gvim 9.0.1047 on Windows 10

I added the following to my vimrc so I can run the sas program I am working on and open the log file without leaving vim:

map <F12> :!"C:\Program Files\SASHome\SASFoundation\9.4\sas.exe" % -CONFIG "C:\Program Files\SASHome\SASFoundation\9.4\nls\en\SASV9.CFG" -nosplash -icon -log %<.log -print %<.lst<CR> & :e %<.log<CR>

It works fine, but it puts a hash (#) in the program at the front of the line where the cursor lies when I hit f12

I can't understand why. Thanks for any help

EDIT: I saw the same problem with simpler mapping eg,

map <F8> :set guifont=Consolas:h12:cANSI:qDRAFT<CR> & :set numberwidth=2<CR>

ie this also produces the #. At the bottom here: https://vim.fandom.com/wiki/Mapping_keys_in_Vim_-_Tutorial_(Part_2), they suggest this should be

map <F8> :set guifont=Consolas:h12:cANSI:qDRAFT<CR> \| set numberwidth=2<CR>

this solves it ie no # appears, but the second setting is not implemented when i write it like this. I wonder how to get any mapping like this where you want to do 2 things, in the above case i want to reduce the font size and narrow the left margin (to get the output to fit on the screen)

1 Answer 1

0

I didn't manage to reproduce your problem since I don't have sas.exe

I would do:

nnoremap <F12> :execute '!"C:\Program Files\SASHome\SASFoundation\9.4\sas.exe"' expand('%') '-CONFIG "C:\Program Files\SASHome\SASFoundation\9.4\nls\en\SASV9.CFG" -nosplash -icon -log' expand('%<') . '.log' '-print' expand('%<') . '.lst' \| e %<.log<CR>

I have:

  • Used execute to be able to have a sequence of command.
  • Used ' to avoid the backslash (\) are interpreted by Vim the wrong way
  • Used | to separate the two commands
  • Used expand to build the argument of your command line
6
  • thanks a lot for this. It works. A couple minor things: 1) it throws errors with the ':e %<.log<CR>' bit, but that's ok, i will use another fn key to open and scan the log, 2) i had to add <CR><CR> to the end, I'm not sure why
    – neverdimed
    Jan 16, 2023 at 15:07
  • Thanks for the feedback :-) If the solution solves your problem I'll be glad if you could validate it using the green v button next to the voting arrow buttons. Jan 16, 2023 at 16:00
  • 1
    actually the problem has evolved :) i'll edit the question to clarify
    – neverdimed
    Jan 16, 2023 at 16:10
  • I forgot to escape the |. To solve the problem add only one <CR> at the end of the command and skip the one in the middle of the command. Jan 16, 2023 at 16:47
  • 1
    excellent, that works, many thanks!
    – neverdimed
    Jan 17, 2023 at 9:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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