About three years ago, I had gathered chunks of code from the net and made my init.vim config file. Now, with Lua released, I am unable to convert it.
And it's down to you folks whether you can help me. You are my last hope.
Yes, I've read the documentation and whatnot. Still, I don't get it. Most of the code in my init.vim file are complex while I can do only simpler ones.
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
function! TabLcd()
let current_tab = tabpagenr()
tabdo lcd %:p:h
execute 'tabnext' current_tab
endfunction
nnoremap <silent> <leader>lcd :call TabLcd()<cr>
nnoremap <leader>cd :execute 'cd' getcwd(-1)<cr>
This block is solved by me: https://vi.stackexchange.com/a/43276/36876
" No highlight after search - triggers on motion or going into insert mode
noremap <expr> <Plug>(StopHL) execute('nohlsearch')[-1]
noremap! <expr> <Plug>(StopHL) execute('nohlsearch')[-1]
fu! HlSearch()
let s:pos = match(getline('.'), @/, col('.') - 1) + 1
if s:pos != col('.')
call StopHL()
endif
endfu
fu! StopHL()
if !v:hlsearch || mode() isnot 'n'
return
else
sil call feedkeys("\<Plug>(StopHL)", 'm')
endif
endfu
augroup SearchHighlight
au!
au CursorMoved * call HlSearch()
au InsertEnter * call StopHL()
augroup end
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
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
init.vim
. These individual questions answer will be more generic and have more chance to help others.