Skip to content

Instantly share code, notes, and snippets.

@alyssarosenzweig
Last active November 12, 2016 23:09
Show Gist options
  • Save alyssarosenzweig/6c84870659871ea4eca75cc4abb7a9d0 to your computer and use it in GitHub Desktop.
Save alyssarosenzweig/6c84870659871ea4eca75cc4abb7a9d0 to your computer and use it in GitHub Desktop.
python3 << EOF
import ctypes, vim
markov = ctypes.cdll.LoadLibrary("/usr/local/lib/libmarkov.so")
markov.initialize_chain(b"/usr/local/share/markov-chain")
def insert():
out = ctypes.create_string_buffer(128)
ln = vim.current.line.encode()
s = markov.nextWord(out, 128, ctypes.create_string_buffer(ln), len(ln))
vim.current.line += out.value.decode()
return s
def substitute():
words = vim.current.line.rstrip().split(" ")
vim.current.line = " ".join(words[:-1]) + " "
if insert() == 0:
vim.current.line += words[-1]
EOF
inoremap  <Esc>:python3 substitute()<CR>$a
inoremap ` <Esc>:python3 insert()<CR>$a
inoremap  `
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment