Skip to content

Instantly share code, notes, and snippets.

@lusingander
Created February 28, 2019 08:23
Show Gist options
  • Save lusingander/fdf2d210c6ca63123f5a2b07926b0603 to your computer and use it in GitHub Desktop.
Save lusingander/fdf2d210c6ca63123f5a2b07926b0603 to your computer and use it in GitHub Desktop.
vim command util
" json format (by jq) and syntax highlight
function! FormatAndHighlightJsonData()
if executable('jq')
:%!jq .
:set filetype=json
endif
endfunction
ca json call FormatAndHighlightJsonData()
" convert unix time to str under cursor
function! UnixTimeToStr(unixtime)
return strftime("%Y/%m/%d %H:%M:%S", a:unixtime)
endfunction
function! ConvCursorUnixTimeToStr()
let l:thisStr = expand("<cword>")
echo UnixTimeToStr(l:thisStr)
endfunction
ca ut call ConvCursorUnixTimeToStr()
function! ConvCursorUnixTimeToStrAndInsert()
let l:thisStr = expand("<cword>")
execute ":normal A" . " => " . UnixTimeToStr(l:thisStr)
endfunction
ca uta call ConvCursorUnixTimeToStrAndInsert()
function! ConvCursorUnixTimeToStrAndChange()
let l:thisStr = expand("<cword>")
execute ":normal ciw" . UnixTimeToStr(l:thisStr)
endfunction
ca utc call ConvCursorUnixTimeToStrAndChange()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment