> Hi, all
>
> I'm new to vim script language and struggling to code a simple
> function to switch between header and source.
> Here are the
>
> function! SwitchSourceHeader()
> if (expand ("%:e") == "cpp" || expand ("%:e") == "c" || expand
> ("%:e") == "cc" )
> find %:t:r.h
> elseif ( expand ("%:e") == "h" )
> let filename = ""
> filename = expand(%:t:r)
> filename = filename + ".cpp"
> if filereadable( filename )
> find %:t:r.cpp
> else
> echo " cannot find source file. "
> endif
> else
> echo "file type unrecognized."
> endif
> endfunction
> nmap ,s :call SwitchSourceHeader()<CR>
>
> However, I get the following
>
> Error detected while processing function SwitchSourceHeader:
> line 5:
> E492 Not an editor command: filename = expand(%:t:r)
>
> I am wondering if anyone can point out a correct way for doing this.
You forgot the quotes :) ..and the "let" keyword.. It should instead be:
let filename = expand("%:t:r")
let filename = filename + ".cpp"
--
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
No comments:
Post a Comment