Skip to main content
Notice removed Authoritative reference needed by Mega Bang
Bounty Ended with Vivian De Smedt's answer chosen by Mega Bang
deleted 876 characters in body
Source Link
Mega Bang
  • 319
  • 1
  • 12
func! Hack() abort
    if exists("b:rwfcmd1") && b:rwfcmd1
        nnoremap <buffer> <F4> :RunWithFile 
        nnoremap <buffer> <F5> <Esc>:w <bar> CompileAndRunWithFile 
        imap <buffer> <F5> <Esc>:w <bar> CompileAndRunWithFile 
        echo "HackerCup Special Deactivated"
        let b:rwfcmd1 = 0
    else
        nnoremap <buffer> <F4> :RunWithFile ~/Downloads/ > output.txt && cat output.txt<s-left><s-left><s-left><s-left><s-left><left>
        nnoremap <buffer> <F5> <Esc>:w <bar> CompileAndRunWithFile ~/Downloads/
        imap <buffer> <F5> <Esc>:w <bar> CompileAndRunWithFile ~/Downloads/
        echo "HackerCup Special Activated"
        let b:rwfcmd1 = 1
    endif
endfunc

com -nargs=0 Cup call Hack()
com -nargs=0 Hackercup let hack_tab = tabpagenr()|tabdo call Hack()|execute 'tabnext' hack_tab

cnoreabbrev cup Cup
cnoreabbrev hackercup Hackercup

au TextYankPost * silent! lua vim.highlight.on_yank {higroup="IncSearch", timeout=300}

au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif

" type :messages to see all the changed files
set autoread
autocmd FocusGained,BufEnter,CursorHold,CursorHoldI *
   \ if mode() !~ '\v(c|r.?|!|t)' && getcmdwintype() == '' | checktime | endif
autocmd FileChangedShellPost *
  \ echohl WarningMsg | echom "File " . expand('<afile>') . " changed on disk. Buffer reloaded." | echohl None
func! Hack() abort
    if exists("b:rwfcmd1") && b:rwfcmd1
        nnoremap <buffer> <F4> :RunWithFile 
        nnoremap <buffer> <F5> <Esc>:w <bar> CompileAndRunWithFile 
        imap <buffer> <F5> <Esc>:w <bar> CompileAndRunWithFile 
        echo "HackerCup Special Deactivated"
        let b:rwfcmd1 = 0
    else
        nnoremap <buffer> <F4> :RunWithFile ~/Downloads/ > output.txt && cat output.txt<s-left><s-left><s-left><s-left><s-left><left>
        nnoremap <buffer> <F5> <Esc>:w <bar> CompileAndRunWithFile ~/Downloads/
        imap <buffer> <F5> <Esc>:w <bar> CompileAndRunWithFile ~/Downloads/
        echo "HackerCup Special Activated"
        let b:rwfcmd1 = 1
    endif
endfunc

com -nargs=0 Cup call Hack()
com -nargs=0 Hackercup let hack_tab = tabpagenr()|tabdo call Hack()|execute 'tabnext' hack_tab

cnoreabbrev cup Cup
cnoreabbrev hackercup Hackercup

au TextYankPost * silent! lua vim.highlight.on_yank {higroup="IncSearch", timeout=300}

au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif

" type :messages to see all the changed files
set autoread
autocmd FocusGained,BufEnter,CursorHold,CursorHoldI *
   \ if mode() !~ '\v(c|r.?|!|t)' && getcmdwintype() == '' | checktime | endif
autocmd FileChangedShellPost *
  \ echohl WarningMsg | echom "File " . expand('<afile>') . " changed on disk. Buffer reloaded." | echohl None
au TextYankPost * silent! lua vim.highlight.on_yank {higroup="IncSearch", timeout=300}

au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif

" type :messages to see all the changed files
set autoread
autocmd FocusGained,BufEnter,CursorHold,CursorHoldI *
   \ if mode() !~ '\v(c|r.?|!|t)' && getcmdwintype() == '' | checktime | endif
autocmd FileChangedShellPost *
  \ echohl WarningMsg | echom "File " . expand('<afile>') . " changed on disk. Buffer reloaded." | echohl None
added 186 characters in body
Source Link
Mega Bang
  • 319
  • 1
  • 12
if has('nvim')
    augroup terminal_setup | au!
        autocmd TermOpen * nnoremap <buffer><LeftRelease> <LeftRelease>i
    augroup end
endif

function! TermWrapper(command) abort
    if !exists('g:split_term_style') | let g:split_term_style = 'vertical' | endif
    if g:split_term_style ==# 'vertical'
        let buffercmd = 'vnew'
    elseif g:split_term_style ==# 'horizontal'
        let buffercmd = 'new'
    else
        echoerr 'ERROR! g:split_term_style is not a valid value (must be ''horizontal'' or ''vertical'' but is currently set to ''' . g:split_term_style . ''')'
        throw 'ERROR! g:split_term_style is not a valid value (must be ''horizontal'' or ''vertical'')'
    endif
    exec buffercmd
    if exists('g:split_term_resize_cmd')
        exec g:split_term_resize_cmd
    endif
    exec 'term ' . a:command
    exec 'setlocal nornu nonu'
    exec 'startinsert'
endfunction

command! -nargs=0 Compile call TermWrapper(printf('g++ -std=c++17 -O2 -Wall %s -o %s.out', expand('%'), expand('%:r')))
autocmd FileType cpp nnoremap <F9> <Esc>:w <bar> Compile<CR>
autocmd FileType cpp imap <F9> <Esc>:w <bar> Compile<CR>

command! -nargs=0 Run call TermWrapper(printf('./%s.out', expand('%:r')))
autocmd FileType cpp nnoremap <F10> :Run<CR>

command! -nargs=0 CompileAndRun call TermWrapper(printf('g++ -std=c++17 -O2 -Wall %s -o %s.out && ./%s.out', expand('%'), expand('%:r'), expand('%:r')))
autocmd FileType cpp nnoremap <F12> <Esc>:w <bar> CompileAndRun<CR>
autocmd FileType cpp imap <F12> <Esc>:w <bar> CompileAndRun<CR>

func! Hack() abort
    if exists("b:rwfcmd1") && b:rwfcmd1
        nnoremap <buffer> <F4> :RunWithFile 
        nnoremap <buffer> <F5> <Esc>:w <bar> CompileAndRunWithFile 
        imap <buffer> <F5> <Esc>:w <bar> CompileAndRunWithFile 
        echo "HackerCup Special Deactivated"
        let b:rwfcmd1 = 0
    else
        nnoremap <buffer> <F4> :RunWithFile ~/Downloads/ > output.txt && cat output.txt<s-left><s-left><s-left><s-left><s-left><left>
        nnoremap <buffer> <F5> <Esc>:w <bar> CompileAndRunWithFile ~/Downloads/
        imap <buffer> <F5> <Esc>:w <bar> CompileAndRunWithFile ~/Downloads/
        echo "HackerCup Special Activated"
        let b:rwfcmd1 = 1
    endif
endfunc

com -nargs=0 Cup call Hack()
com -nargs=0 Hackercup let hack_tab = tabpagenr()|tabdo call Hack()|execute 'tabnext' hack_tab

cnoreabbrev cup Cup
cnoreabbrev hackercup Hackercup

au TextYankPost * silent! lua vim.highlight.on_yank {higroup="IncSearch", timeout=300}

au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif

" type :messages to see all the changed files
set autoread
autocmd FocusGained,BufEnter,CursorHold,CursorHoldI *
   \ if mode() !~ '\v(c|r.?|!|t)' && getcmdwintype() == '' | checktime | endif
autocmd FileChangedShellPost *
  \ echohl WarningMsg | echom "File " . expand('<afile>') . " changed on disk. Buffer reloaded." | echohl None
 

This block solved in https://vi.stackexchange.com/a/43284/36876

tnoremap <Esc> <C-\><C-n>

" https://vi.stackexchange.com/a/22327/36876
if has('nvim')
    augroup terminal_setup | au!
        autocmd TermOpen * nnoremap <buffer><LeftRelease> <LeftRelease>i
    augroup end
endif

function! TermWrapper(command) abort
    if !exists('g:split_term_style') | let g:split_term_style = 'vertical' | endif
    if g:split_term_style ==# 'vertical'
        let buffercmd = 'vnew'
    elseif g:split_term_style ==# 'horizontal'
        let buffercmd = 'new'
    else
        echoerr 'ERROR! g:split_term_style is not a valid value (must be ''horizontal'' or ''vertical'' but is currently set to ''' . g:split_term_style . ''')'
        throw 'ERROR! g:split_term_style is not a valid value (must be ''horizontal'' or ''vertical'')'
    endif
    exec buffercmd
    if exists('g:split_term_resize_cmd')
        exec g:split_term_resize_cmd
    endif
    exec 'term ' . a:command
    exec 'setlocal nornu nonu'
    exec 'startinsert'
endfunction

command! -nargs=0 Compile call TermWrapper(printf('g++ -std=c++17 -O2 -Wall %s -o %s.out', expand('%'), expand('%:r')))
autocmd FileType cpp nnoremap <F9> <Esc>:w <bar> Compile<CR>

command! -nargs=0 Run call TermWrapper(printf('./%s.out', expand('%:r')))
autocmd FileType cpp nnoremap <F10> :Run<CR>

command! -nargs=0 CompileAndRun call TermWrapper(printf('g++ -std=c++17 -O2 -Wall %s -o %s.out && ./%s.out', expand('%'), expand('%:r'), expand('%:r')))
autocmd FileType cpp nnoremap <F12> <Esc>:w <bar> CompileAndRun<CR>

let g:split_term_style = 'horizontal'
let g:split_term_resize_cmd = 'resize 30'
set splitbelow

This block is solved in https://vi.stackexchange.com/a/43287/36876

if has('nvim')
    augroup terminal_setup | au!
        autocmd TermOpen * nnoremap <buffer><LeftRelease> <LeftRelease>i
    augroup end
endif

function! TermWrapper(command) abort
    if !exists('g:split_term_style') | let g:split_term_style = 'vertical' | endif
    if g:split_term_style ==# 'vertical'
        let buffercmd = 'vnew'
    elseif g:split_term_style ==# 'horizontal'
        let buffercmd = 'new'
    else
        echoerr 'ERROR! g:split_term_style is not a valid value (must be ''horizontal'' or ''vertical'' but is currently set to ''' . g:split_term_style . ''')'
        throw 'ERROR! g:split_term_style is not a valid value (must be ''horizontal'' or ''vertical'')'
    endif
    exec buffercmd
    if exists('g:split_term_resize_cmd')
        exec g:split_term_resize_cmd
    endif
    exec 'term ' . a:command
    exec 'setlocal nornu nonu'
    exec 'startinsert'
endfunction

command! -nargs=0 Compile call TermWrapper(printf('g++ -std=c++17 -O2 -Wall %s -o %s.out', expand('%'), expand('%:r')))
autocmd FileType cpp nnoremap <F9> <Esc>:w <bar> Compile<CR>
autocmd FileType cpp imap <F9> <Esc>:w <bar> Compile<CR>

command! -nargs=0 Run call TermWrapper(printf('./%s.out', expand('%:r')))
autocmd FileType cpp nnoremap <F10> :Run<CR>

command! -nargs=0 CompileAndRun call TermWrapper(printf('g++ -std=c++17 -O2 -Wall %s -o %s.out && ./%s.out', expand('%'), expand('%:r'), expand('%:r')))
autocmd FileType cpp nnoremap <F12> <Esc>:w <bar> CompileAndRun<CR>
autocmd FileType cpp imap <F12> <Esc>:w <bar> CompileAndRun<CR>

func! Hack() abort
    if exists("b:rwfcmd1") && b:rwfcmd1
        nnoremap <buffer> <F4> :RunWithFile 
        nnoremap <buffer> <F5> <Esc>:w <bar> CompileAndRunWithFile 
        imap <buffer> <F5> <Esc>:w <bar> CompileAndRunWithFile 
        echo "HackerCup Special Deactivated"
        let b:rwfcmd1 = 0
    else
        nnoremap <buffer> <F4> :RunWithFile ~/Downloads/ > output.txt && cat output.txt<s-left><s-left><s-left><s-left><s-left><left>
        nnoremap <buffer> <F5> <Esc>:w <bar> CompileAndRunWithFile ~/Downloads/
        imap <buffer> <F5> <Esc>:w <bar> CompileAndRunWithFile ~/Downloads/
        echo "HackerCup Special Activated"
        let b:rwfcmd1 = 1
    endif
endfunc

com -nargs=0 Cup call Hack()
com -nargs=0 Hackercup let hack_tab = tabpagenr()|tabdo call Hack()|execute 'tabnext' hack_tab

cnoreabbrev cup Cup
cnoreabbrev hackercup Hackercup

au TextYankPost * silent! lua vim.highlight.on_yank {higroup="IncSearch", timeout=300}

au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif

" type :messages to see all the changed files
set autoread
autocmd FocusGained,BufEnter,CursorHold,CursorHoldI *
   \ if mode() !~ '\v(c|r.?|!|t)' && getcmdwintype() == '' | checktime | endif
autocmd FileChangedShellPost *
  \ echohl WarningMsg | echom "File " . expand('<afile>') . " changed on disk. Buffer reloaded." | echohl None
 

This block solved in https://vi.stackexchange.com/a/43284/36876

func! Hack() abort
    if exists("b:rwfcmd1") && b:rwfcmd1
        nnoremap <buffer> <F4> :RunWithFile 
        nnoremap <buffer> <F5> <Esc>:w <bar> CompileAndRunWithFile 
        imap <buffer> <F5> <Esc>:w <bar> CompileAndRunWithFile 
        echo "HackerCup Special Deactivated"
        let b:rwfcmd1 = 0
    else
        nnoremap <buffer> <F4> :RunWithFile ~/Downloads/ > output.txt && cat output.txt<s-left><s-left><s-left><s-left><s-left><left>
        nnoremap <buffer> <F5> <Esc>:w <bar> CompileAndRunWithFile ~/Downloads/
        imap <buffer> <F5> <Esc>:w <bar> CompileAndRunWithFile ~/Downloads/
        echo "HackerCup Special Activated"
        let b:rwfcmd1 = 1
    endif
endfunc

com -nargs=0 Cup call Hack()
com -nargs=0 Hackercup let hack_tab = tabpagenr()|tabdo call Hack()|execute 'tabnext' hack_tab

cnoreabbrev cup Cup
cnoreabbrev hackercup Hackercup

au TextYankPost * silent! lua vim.highlight.on_yank {higroup="IncSearch", timeout=300}

au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif

" type :messages to see all the changed files
set autoread
autocmd FocusGained,BufEnter,CursorHold,CursorHoldI *
   \ if mode() !~ '\v(c|r.?|!|t)' && getcmdwintype() == '' | checktime | endif
autocmd FileChangedShellPost *
  \ echohl WarningMsg | echom "File " . expand('<afile>') . " changed on disk. Buffer reloaded." | echohl None

This block solved in https://vi.stackexchange.com/a/43284/36876

tnoremap <Esc> <C-\><C-n>

" https://vi.stackexchange.com/a/22327/36876
if has('nvim')
    augroup terminal_setup | au!
        autocmd TermOpen * nnoremap <buffer><LeftRelease> <LeftRelease>i
    augroup end
endif

function! TermWrapper(command) abort
    if !exists('g:split_term_style') | let g:split_term_style = 'vertical' | endif
    if g:split_term_style ==# 'vertical'
        let buffercmd = 'vnew'
    elseif g:split_term_style ==# 'horizontal'
        let buffercmd = 'new'
    else
        echoerr 'ERROR! g:split_term_style is not a valid value (must be ''horizontal'' or ''vertical'' but is currently set to ''' . g:split_term_style . ''')'
        throw 'ERROR! g:split_term_style is not a valid value (must be ''horizontal'' or ''vertical'')'
    endif
    exec buffercmd
    if exists('g:split_term_resize_cmd')
        exec g:split_term_resize_cmd
    endif
    exec 'term ' . a:command
    exec 'setlocal nornu nonu'
    exec 'startinsert'
endfunction

command! -nargs=0 Compile call TermWrapper(printf('g++ -std=c++17 -O2 -Wall %s -o %s.out', expand('%'), expand('%:r')))
autocmd FileType cpp nnoremap <F9> <Esc>:w <bar> Compile<CR>

command! -nargs=0 Run call TermWrapper(printf('./%s.out', expand('%:r')))
autocmd FileType cpp nnoremap <F10> :Run<CR>

command! -nargs=0 CompileAndRun call TermWrapper(printf('g++ -std=c++17 -O2 -Wall %s -o %s.out && ./%s.out', expand('%'), expand('%:r'), expand('%:r')))
autocmd FileType cpp nnoremap <F12> <Esc>:w <bar> CompileAndRun<CR>

let g:split_term_style = 'horizontal'
let g:split_term_resize_cmd = 'resize 30'
set splitbelow

This block is solved in https://vi.stackexchange.com/a/43287/36876

deleted 426 characters in body; edited tags
Source Link
Mega Bang
  • 319
  • 1
  • 12
if !exists("g:os")
    if has("win64") || has("win32") || has("win16")
        let g:os = "Windows"
    else
        let g:os = substitute(system('uname'), '\n', '', '')
    endif
endif

if has('nvim')
    augroup terminal_setup | au!
        autocmd TermOpen * nnoremap <buffer><LeftRelease> <LeftRelease>i
    augroup end
endif

function! TermWrapper(command) abort
    if !exists('g:split_term_style') | let g:split_term_style = 'vertical' | endif
    if g:split_term_style ==# 'vertical'
        let buffercmd = 'vnew'
    elseif g:split_term_style ==# 'horizontal'
        let buffercmd = 'new'
    else
        echoerr 'ERROR! g:split_term_style is not a valid value (must be ''horizontal'' or ''vertical'' but is currently set to ''' . g:split_term_style . ''')'
        throw 'ERROR! g:split_term_style is not a valid value (must be ''horizontal'' or ''vertical'')'
    endif
    exec buffercmd
    if exists('g:split_term_resize_cmd')
        exec g:split_term_resize_cmd
    endif
    exec 'term ' . a:command
    exec 'setlocal nornu nonu'
    exec 'startinsert'
endfunction

command! -nargs=0 Compile call TermWrapper(printf('g++ -std=c++17 -O2 -Wall %s -o %s.out', expand('%'), expand('%:r')))
autocmd FileType cpp nnoremap <F9> <Esc>:w <bar> Compile<CR>
autocmd FileType cpp imap <F9> <Esc>:w <bar> Compile<CR>

command! -nargs=0 Run call TermWrapper(printf('./%s.out', expand('%:r')))
autocmd FileType cpp nnoremap <F10> :Run<CR>

command! -nargs=0 CompileAndRun call TermWrapper(printf('g++ -std=c++17 -O2 -Wall %s -o %s.out && ./%s.out', expand('%'), expand('%:r'), expand('%:r')))
autocmd FileType cpp nnoremap <F12> <Esc>:w <bar> CompileAndRun<CR>
autocmd FileType cpp imap <F12> <Esc>:w <bar> CompileAndRun<CR>

command! -nargs=1 -complete=file CompileAndRunWithFile call TermWrapper(printf('g++ -std=c++17 -O2 -Wall %s -o %s.out && ./%s.out < %s', expand('%'), expand('%:r'), expand('%:r'), <q-args>))
autocmd FileType cpp nnoremap <F5> <Esc>:w <bar> CompileAndRunWithFile 
autocmd FileType cpp imap <F5> <Esc>:w <bar> CompileAndRunWithFile 

command! -nargs=1 -complete=file RunWithFile call TermWrapper(printf('./%s.out < %s', expand('%:r'), <q-args>))
autocmd FileType cpp nnoremap <F4> :RunWithFile 

func! Hack() abort
    if exists("b:rwfcmd1") && b:rwfcmd1
        nnoremap <buffer> <F4> :RunWithFile 
        nnoremap <buffer> <F5> <Esc>:w <bar> CompileAndRunWithFile 
        imap <buffer> <F5> <Esc>:w <bar> CompileAndRunWithFile 
        echo "HackerCup Special Deactivated"
        let b:rwfcmd1 = 0
    else
        nnoremap <buffer> <F4> :RunWithFile ~/Downloads/ > output.txt && cat output.txt<s-left><s-left><s-left><s-left><s-left><left>
        nnoremap <buffer> <F5> <Esc>:w <bar> CompileAndRunWithFile ~/Downloads/
        imap <buffer> <F5> <Esc>:w <bar> CompileAndRunWithFile ~/Downloads/
        echo "HackerCup Special Activated"
        let b:rwfcmd1 = 1
    endif
endfunc

com -nargs=0 Cup call Hack()
com -nargs=0 Hackercup let hack_tab = tabpagenr()|tabdo call Hack()|execute 'tabnext' hack_tab

cnoreabbrev cup Cup
cnoreabbrev hackercup Hackercup

au TextYankPost * silent! lua vim.highlight.on_yank {higroup="IncSearch", timeout=300}

au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif

" type :messages to see all the changed files
set autoread
autocmd FocusGained,BufEnter,CursorHold,CursorHoldI *
   \ if mode() !~ '\v(c|r.?|!|t)' && getcmdwintype() == '' | checktime | endif
autocmd FileChangedShellPost *
  \ echohl WarningMsg | echom "File " . expand('<afile>') . " changed on disk. Buffer reloaded." | echohl None

This block is solved by @vivian-de-smedt in https://vi.stackexchange.com/a/43279/36876

if !exists("g:os")
    if has("win64") || has("win32") || has("win16")
        let g:os = "Windows"
    else
        let g:os = substitute(system('uname'), '\n', '', '')
    endif
endif

This block solved in https://vi.stackexchange.com/a/43284/36876

if !exists("g:os")
    if has("win64") || has("win32") || has("win16")
        let g:os = "Windows"
    else
        let g:os = substitute(system('uname'), '\n', '', '')
    endif
endif

if has('nvim')
    augroup terminal_setup | au!
        autocmd TermOpen * nnoremap <buffer><LeftRelease> <LeftRelease>i
    augroup end
endif

function! TermWrapper(command) abort
    if !exists('g:split_term_style') | let g:split_term_style = 'vertical' | endif
    if g:split_term_style ==# 'vertical'
        let buffercmd = 'vnew'
    elseif g:split_term_style ==# 'horizontal'
        let buffercmd = 'new'
    else
        echoerr 'ERROR! g:split_term_style is not a valid value (must be ''horizontal'' or ''vertical'' but is currently set to ''' . g:split_term_style . ''')'
        throw 'ERROR! g:split_term_style is not a valid value (must be ''horizontal'' or ''vertical'')'
    endif
    exec buffercmd
    if exists('g:split_term_resize_cmd')
        exec g:split_term_resize_cmd
    endif
    exec 'term ' . a:command
    exec 'setlocal nornu nonu'
    exec 'startinsert'
endfunction

command! -nargs=0 Compile call TermWrapper(printf('g++ -std=c++17 -O2 -Wall %s -o %s.out', expand('%'), expand('%:r')))
autocmd FileType cpp nnoremap <F9> <Esc>:w <bar> Compile<CR>
autocmd FileType cpp imap <F9> <Esc>:w <bar> Compile<CR>

command! -nargs=0 Run call TermWrapper(printf('./%s.out', expand('%:r')))
autocmd FileType cpp nnoremap <F10> :Run<CR>

command! -nargs=0 CompileAndRun call TermWrapper(printf('g++ -std=c++17 -O2 -Wall %s -o %s.out && ./%s.out', expand('%'), expand('%:r'), expand('%:r')))
autocmd FileType cpp nnoremap <F12> <Esc>:w <bar> CompileAndRun<CR>
autocmd FileType cpp imap <F12> <Esc>:w <bar> CompileAndRun<CR>

command! -nargs=1 -complete=file CompileAndRunWithFile call TermWrapper(printf('g++ -std=c++17 -O2 -Wall %s -o %s.out && ./%s.out < %s', expand('%'), expand('%:r'), expand('%:r'), <q-args>))
autocmd FileType cpp nnoremap <F5> <Esc>:w <bar> CompileAndRunWithFile 
autocmd FileType cpp imap <F5> <Esc>:w <bar> CompileAndRunWithFile 

command! -nargs=1 -complete=file RunWithFile call TermWrapper(printf('./%s.out < %s', expand('%:r'), <q-args>))
autocmd FileType cpp nnoremap <F4> :RunWithFile 

func! Hack() abort
    if exists("b:rwfcmd1") && b:rwfcmd1
        nnoremap <buffer> <F4> :RunWithFile 
        nnoremap <buffer> <F5> <Esc>:w <bar> CompileAndRunWithFile 
        imap <buffer> <F5> <Esc>:w <bar> CompileAndRunWithFile 
        echo "HackerCup Special Deactivated"
        let b:rwfcmd1 = 0
    else
        nnoremap <buffer> <F4> :RunWithFile ~/Downloads/ > output.txt && cat output.txt<s-left><s-left><s-left><s-left><s-left><left>
        nnoremap <buffer> <F5> <Esc>:w <bar> CompileAndRunWithFile ~/Downloads/
        imap <buffer> <F5> <Esc>:w <bar> CompileAndRunWithFile ~/Downloads/
        echo "HackerCup Special Activated"
        let b:rwfcmd1 = 1
    endif
endfunc

com -nargs=0 Cup call Hack()
com -nargs=0 Hackercup let hack_tab = tabpagenr()|tabdo call Hack()|execute 'tabnext' hack_tab

cnoreabbrev cup Cup
cnoreabbrev hackercup Hackercup

au TextYankPost * silent! lua vim.highlight.on_yank {higroup="IncSearch", timeout=300}

au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif

" type :messages to see all the changed files
set autoread
autocmd FocusGained,BufEnter,CursorHold,CursorHoldI *
   \ if mode() !~ '\v(c|r.?|!|t)' && getcmdwintype() == '' | checktime | endif
autocmd FileChangedShellPost *
  \ echohl WarningMsg | echom "File " . expand('<afile>') . " changed on disk. Buffer reloaded." | echohl None

This block is solved by @vivian-de-smedt in https://vi.stackexchange.com/a/43279/36876

if has('nvim')
    augroup terminal_setup | au!
        autocmd TermOpen * nnoremap <buffer><LeftRelease> <LeftRelease>i
    augroup end
endif

function! TermWrapper(command) abort
    if !exists('g:split_term_style') | let g:split_term_style = 'vertical' | endif
    if g:split_term_style ==# 'vertical'
        let buffercmd = 'vnew'
    elseif g:split_term_style ==# 'horizontal'
        let buffercmd = 'new'
    else
        echoerr 'ERROR! g:split_term_style is not a valid value (must be ''horizontal'' or ''vertical'' but is currently set to ''' . g:split_term_style . ''')'
        throw 'ERROR! g:split_term_style is not a valid value (must be ''horizontal'' or ''vertical'')'
    endif
    exec buffercmd
    if exists('g:split_term_resize_cmd')
        exec g:split_term_resize_cmd
    endif
    exec 'term ' . a:command
    exec 'setlocal nornu nonu'
    exec 'startinsert'
endfunction

command! -nargs=0 Compile call TermWrapper(printf('g++ -std=c++17 -O2 -Wall %s -o %s.out', expand('%'), expand('%:r')))
autocmd FileType cpp nnoremap <F9> <Esc>:w <bar> Compile<CR>
autocmd FileType cpp imap <F9> <Esc>:w <bar> Compile<CR>

command! -nargs=0 Run call TermWrapper(printf('./%s.out', expand('%:r')))
autocmd FileType cpp nnoremap <F10> :Run<CR>

command! -nargs=0 CompileAndRun call TermWrapper(printf('g++ -std=c++17 -O2 -Wall %s -o %s.out && ./%s.out', expand('%'), expand('%:r'), expand('%:r')))
autocmd FileType cpp nnoremap <F12> <Esc>:w <bar> CompileAndRun<CR>
autocmd FileType cpp imap <F12> <Esc>:w <bar> CompileAndRun<CR>

func! Hack() abort
    if exists("b:rwfcmd1") && b:rwfcmd1
        nnoremap <buffer> <F4> :RunWithFile 
        nnoremap <buffer> <F5> <Esc>:w <bar> CompileAndRunWithFile 
        imap <buffer> <F5> <Esc>:w <bar> CompileAndRunWithFile 
        echo "HackerCup Special Deactivated"
        let b:rwfcmd1 = 0
    else
        nnoremap <buffer> <F4> :RunWithFile ~/Downloads/ > output.txt && cat output.txt<s-left><s-left><s-left><s-left><s-left><left>
        nnoremap <buffer> <F5> <Esc>:w <bar> CompileAndRunWithFile ~/Downloads/
        imap <buffer> <F5> <Esc>:w <bar> CompileAndRunWithFile ~/Downloads/
        echo "HackerCup Special Activated"
        let b:rwfcmd1 = 1
    endif
endfunc

com -nargs=0 Cup call Hack()
com -nargs=0 Hackercup let hack_tab = tabpagenr()|tabdo call Hack()|execute 'tabnext' hack_tab

cnoreabbrev cup Cup
cnoreabbrev hackercup Hackercup

au TextYankPost * silent! lua vim.highlight.on_yank {higroup="IncSearch", timeout=300}

au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif

" type :messages to see all the changed files
set autoread
autocmd FocusGained,BufEnter,CursorHold,CursorHoldI *
   \ if mode() !~ '\v(c|r.?|!|t)' && getcmdwintype() == '' | checktime | endif
autocmd FileChangedShellPost *
  \ echohl WarningMsg | echom "File " . expand('<afile>') . " changed on disk. Buffer reloaded." | echohl None

This block is solved by @vivian-de-smedt in https://vi.stackexchange.com/a/43279/36876

if !exists("g:os")
    if has("win64") || has("win32") || has("win16")
        let g:os = "Windows"
    else
        let g:os = substitute(system('uname'), '\n', '', '')
    endif
endif

This block solved in https://vi.stackexchange.com/a/43284/36876

added 102 characters in body
Source Link
Mega Bang
  • 319
  • 1
  • 12
Loading
added 99 characters in body
Source Link
Mega Bang
  • 319
  • 1
  • 12
Loading
can be done in lua; deleted 8 characters in body
Source Link
Mega Bang
  • 319
  • 1
  • 12
Loading
less scary
Link
Mega Bang
  • 319
  • 1
  • 12
Loading
Notice added Authoritative reference needed by Mega Bang
Bounty Started worth 50 reputation by Mega Bang
corrected the wrong
Source Link
Mega Bang
  • 319
  • 1
  • 12
Loading
edited tags
Link
Vivian De Smedt
  • 21.2k
  • 5
  • 22
  • 40
Loading
Source Link
Mega Bang
  • 319
  • 1
  • 12
Loading