Proposed tip Please edit this page to improve it, or add your comments below (do not use the discussion page).
created May 7, 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) else call append(ln-1, word) endif endfunction