LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (http://www.linuxquestions.org/questions/linux-software-2/)
-   -   Vim function and key mapping (http://www.linuxquestions.org/questions/linux-software-2/vim-function-and-key-mapping-766630/)

voyciz 11-03-2009 06:54 PM

Vim function and key mapping
 
Hello all, having a little trouble with defining a vim function and mapping a key sequence to it, any help would be greatly appreciated. The documentation is a little confusing to me.

Quote:

function Slackbuild()
:%s/ARCH:-i486/ARCH:-x86_64<CR>
:%s/OUTPUT:-\/tmp/OUTPUT:-\/usr\/local\/my_builds<CR>
endfunction
map _sb call Slackbuild()
So I'm trying to map the "_sb" key sequence to Slackbuild() and having some trouble. I'm guessing I'm not listing the correct commands within the function. Originally I was gonna use:

Quote:

map _sb :%s/ARCH:-i486/ARCH:-x86_64<CR>:%s/OUTPUT:-\/tmp/OUTPUT:-\/usr\/local\/my_builds<CR>
...but the problem I ran into was that if the first substitution command was not successfull, then the second was not carried out.

voyciz 11-03-2009 11:11 PM

Quote:

function Slackbuild()
let [lnum, col]=searchpos("ARCH:-i486",'n')
let repl = substitute(getline(lnum),"i486","x86_64","g")
call setline(lnum,repl)
let [lnum,col]=searchpos("OUTPUT:-\/tmp",'n')
let repl = substitute(getline(lnum),"\/tmp","\/usr\/local\/my_builds","g")
call setline(lnum,repl)
endfunction
map _sb :exec Slackbuild()<CR>
So after experimenting for a while, I have something that works. I have a feeling this isn't the best way to do it though. If anyone has any input, let me know please.


All times are GMT -5. The time now is 07:17 PM.