Related config:

noremap <F5> :make<CR>
noremap <F6> :!./%<<CR>
noremap <F7> :!./%< 2>/dev/null<CR>

The problem is while running the program with F6 when I paste input from clipboard it messes up the output and before all the input is pasted there is already something printed which makes it a bit difficult to read quickly.

A workaround is to read from a file, like ./<filename> < in but i was not able to map this command to key.

noremap <F8> :!./%<CR> < in

I am a beginner and don't know much about these configurations. Any help will be appreciated.

For copy pasting from clipboard, i have the following lines in .vimrc from https://stackoverflow.com/questions/44480829/how-to-copy-to-clipboard-in-vim-of-bash-on-windows. I am using WSL on windows.

vmap <C-c> y:new ~/.vimbuffer<CR>VGp:x<CR> \| :!cat ~/.vimbuffer \| clip.exe <CR><CR>
map <C-Shift-v> :r ~/.vimbuffer<CR>
  • I'm a bit confused, how can you paste input from clipboard while you run something with !, it's not asynchronous. – dedowsdi May 8 '19 at 11:32
  • it opens up terminal, in which i can either type or paste. – kayush May 8 '19 at 11:37
  • Have a look ibb.co/dPsCwrv – kayush May 8 '19 at 11:37

You can't do it with map, you should do it with command, command allows you to input filename as args.

command -nargs=1 -complete=file Exe !./%< <<args>

:h <args> will be expanded to your input filename. You can execute it like this:

:Exe input_filename

If you are using vim8, you may try this:

command -nargs=1 -complete=file ExeTerminal exec 'terminal bash -c "./%< <<args>"' | wincmd p

It's asynchronous, you output will be in a vim terminal buffer. :h terminal see | as it's arguments, you need to use exec to write multiple commands in 1 line.


If you want to create a map to just enter filename:

nnoremap <f8> :Exe<space>

<space> is a space.

  • +1, Thanks it works. Is this possible to map this with key such that i only input the file name? Is this possible for <kbd>F6</kbd> to run after everything is pasted? – kayush May 8 '19 at 12:48
  • ./test.cpp: line 3: using: command not found ./test.cpp: line 5: syntax error near unexpected token (' ./test.cpp: line 5: int main()' shell returned 2 – kayush May 8 '19 at 12:56
  • @D.BenKnoble What do you suggest? – kayush May 8 '19 at 14:44
  • @dedowsdi I am simply tring to execute the executable file i.e. ./test – kayush May 8 '19 at 14:44
  • I was wrong—I didn’t understand the < syntax. But in any case, there’s something wrong with @kayush setup and it isn’t a good fit for Vi and Vim. The answer should work. – D. Ben Knoble May 8 '19 at 15:15

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.