Skip to content

Instantly share code, notes, and snippets.

View mhinz's full-sized avatar

Marco Hinz mhinz

View GitHub Profile
$ nvim -u NORC
:cd
:edit ~/.config/somefile.txt
" absolute path
:echo @%
:cd .config
:cd -
" relative path
:echo @%
autocmd VimEnter * nested
\ if argc() == 0
\| let last = filter(filter(copy(v:oldfiles), 'match(v:val, getcwd()) == 0'), 'filereadable(v:val)')
\| if !empty(last)
\| execute 'edit' fnameescape(last[0])
\| endif
\| endif
set scrolloff=0
function! s:foo()
echomsg line('w$')
normal! L
+
echomsg line('w$')
endfunction
call s:foo()
@mhinz
mhinz / foo.vim
Last active February 29, 2020 19:36
augroup grepper-side
autocmd!
autocmd FileType GrepperSide silent! keeppatterns %s/^\ze[^\>]/ / | 1
augroup END
function! s:context_jump(close_window)
let fileline = search('\v^\>\>\> [[:alnum:]\/\-_.~]+:\d+', 'bcn')
if empty(fileline)
return
endif
"
" usage: :Vimgrep /foo/ **
"
function! s:exit_handler(id) dict abort
execute 'cfile' self.tempfile
copen
endfunction
function! s:vimgrep(args) abort
@mhinz
mhinz / foo.vim
Created September 27, 2016 10:33
let data1 = []
let data2 = []
let cmd1 = ['sh', '-c', 'ag --vimgrep foo']
let cmd2 = ['sh', '-c', 'rg --no-heading --vimgrep -i foo']
function! s:stdout1(channel, data)
let g:data1 += [a:data]
endfunction
function! s:stdout2(channel, data)
#!/usr/bin/env python3
import sys
import os
from neovim import attach
# WORKING:
def make_func(num):
def func():
let s:buf = []
function! s:error(msgs)
redraw
echohl ErrorMsg
for line in a:msgs
echomsg line
endfor
echohl NONE
endfunction
-- assert_exception({cmd}, [, {error}])
describe('assert_exception()', function()
it('should assert thrown exceptions properly', function()
source([[
try
nocommand
catch
call assert_exception('E492')
endtry
]])
function! s:dump_api()
let api = msgpackparse(systemlist('nvim --api-info'))[0]
for v in api.functions
echohl Function
echomsg v.name._VAL[0]
echohl NONE
echohl Title
echon '('. join(map(v.parameters, 'v:val[1]._VAL[0] .":". v:val[0]._VAL[0]'), ', ') .')'