Tip 1563 Printable Monobook Previous Next

created 2008 · complexity basic · author Pressel · version 7.0

Here is a convenience function to help Perl programmers when writing new routines.

Put the cursor on a word, then type \ns (assuming the default backslash leader key) to create a new subroutine. The subroutine is given the name of the word under the cursor, and is placed at the "bottom" of the file. If any __xxx__ tokens are used (such as __DATA__ or __END__), the subroutine is inserted before that token. Otherwise, it is appended to the end of the file.

nnoremap <Leader>ns :call Newsub()<CR>
function! Newsub()
  let word = "sub " . expand("<cword>") . "{}"
  let ln = search("__.*__", 'nW')
  if ln == 0
    call append('$', word)
    call append(ln-1, word)


Community content is available under CC-BY-SA unless otherwise noted.