From: [email protected]
To: [email protected]
Subject: How to Access 2nd Word on Search Result Line
Date: Sun, 17 Apr 2011 14:00:56 -0400
What I am trying to do is insert a 'warn' statement after each subroutine
definition in a Perl program. The warn statement displays "Entering subroutine
xxxx". I currently have the following mapping:
map F6 /^sub <CR>:r generic_warn.txt<CR>/xxxx<CR>
where I find the next subroutine definition, read in a generic 'warn' statement
from an external file, and locate xxxx in the warn statement. This works OK,
but what I would like to do is capture the subroutine name from the subroutine
definition line when I first find it, and substitute the subroutine name for
xxxx in the warn statement.
--
This is my second attempt, and it is working (yea!!!).
" Insert warn statement after subroutine definition.
function! InsertWarn()
let words = split(getline('.'), '\W\+')
let subname = get(words,1)
:r \generic_warn.txt
let line = getline('.')
let repl = substitute(line,'xxxx',subname,'')
call setline('.',repl)
endfunction
noremap <F6> /^sub <CR>:call InsertWarn()<CR>
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php