Insert text into current buffer from function
问题 I'm having a hard time finding the documentation for this. How do I read/write text from the current buffer in my vim functions? More concretely, if my buffer contains the words foo bar how would write a function to overwrite the word bar with cat so that in the end my buffer contains foo cat ? 回答1: You can use the substitute ex command inside a function. For example function! ReplaceBar() :%s/bar/cat/g endfunction This defines a function. The % character means operate on the entire buffer.