-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA512 On December 12, 2014 5:04:24 PM EAT, Joydeep Chakrabarty <[email protected]> wrote: >On Thu, 11 Dec 2014 16:24:42 -0500, David Fishburn wrote: > >> On Thu, Dec 11, 2014 at 12:10 PM, Joydeep Chakrabarty >> <[email protected] >>> wrote: >> >>> ... >> >> >> >>> Thanks for your interesting tips. I forgot to mention I am working >on >>> Linux Mint 64-bit laptop. So I just changed "iexplorer.exe" to >firefox. >>> But when I used the tip - "nnoremap <silent> <C-F5> :if >expand('%:p:h') >>> != ""<CR>:! firefox %:p<CR>:endif<CR><CR>", it sent "firefox >>> /home/username/public_html/current_directory/program1.php" and it >>> didn't work. As I said in my earlier post I am using Php. So I have >to >>> sent "http://localhost/current_directory/program1.php" to firefox. >>> I could use ":!firefox http://localhost/current_directory/%". But in >>> that case I have to write current_directory every time. >>> I need a general way to get the path from after localhost(= >>> ~/public_html) to filename.php ( = %). >>> >>> >> You just have to use an extra substitution command (and probably an >> execute statement). >> >> I think this should work for you. >> >> nnoremap <silent> <C-F5> :if expand('%:p:h') != ""<CR>:exec ":! >firefox >> " >> . substitute(expand('%:p'), '\/home\/username\/public_html', ' >> http://localhost', '')<CR>:endif<CR> >> >> You can replace :exec with :echomsg and see what will happen. >> >> Dave >> >> -- > >Thanks David, >It finally worked. I used - > >nmap <F2> :w<CR>:exec "!firefox " . substitute(expand('%:p'),"\/home\/ >username\/public_html","http\:\/\/localhost","")<CR>
You forgot shellescape(, 1). I suggest you use it even if you do not plan to have anything that needs to be escaped there. >Thanks again. >BTW, is there any way I can run this in background? Everytime I press >F2, >firefox opens and I cannot use vim until I close firefox. So I need to >call this in background and I can edit in vim. Next time I press F2, >another tab in firefox will be opened. Use screen, tmux, dtach or shell own backgrounding capabilities (&) (you may need nohup). Check out 'man bash', section SHELL GRAMMAR/Lists for the latter, 'man screen/tmux/...' for the former. -----BEGIN PGP SIGNATURE----- Version: APG v1.1.1 iQI1BAEBCgAfBQJUiwAbGBxaeVggPHp5eC52aW1AZ21haWwuY29tPgAKCRCf3UKj HhHSvkz3EACi5TW9DmQqX0/+dbZ2wdg3suDs2AjN7tRNE9aV2nhrWRd+rZkR7hlF KzD4MRjGxfnfup9gzSQpWc2EHho+Ai8SIN1P56I36JRObfLavp+9xIiVmxj/iVLX /sF4AymFc5PJ6+BrzqMiiX4xRWs/bgKh1gaNG+lGEWEvnv0s1UBCICc+WSMh8bEt ze05zdpd9KipHTMff+P1SwU1j1VP4hmI1pzdlUHDvV92T/oaxuqM0etlBpEOK8Q3 igq9qoWisGy/cBLRSZHgYSM8azFUmQD2i/9IpqSi+8cl7DuLPhqbUUn/Xv1SwGib jUeCaIwNAU+fEO9L7ZqNXlnLb6gvN3xpb3nz83SVcwfpjPwQ/ScQUcy4AY9N5C4D h59s2xyRXZZPBlHHRGtYWj0QCkP3s8ToKU0ZJNvNuVlkwaBtAX0wmfAlB9EcwyEd mAtLA2lvNXGaQa5ocR7IZ8M1p/ikijsWrj/bEt2/nXMr8TOuB8bI27RbzkKyOTrz ZRC71D0OVQLstkfC/IsfVqA5XIX+9tyvZoRIgLtR3NqfRa4uNJ+Nudeuk6vujJLM gsmYtnatrU2C1Wv34nbRv1WzM+oI2+iR7/vCv2A9jqBpShC2PAqXX4uk8wQMgnhi AB0lNNR9pu0WU7LTxTspteNWHGzXdhIXZYGJieeBKDXpCbsvyMSdug== =5fP4 -----END PGP SIGNATURE----- -- -- 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 --- You received this message because you are subscribed to the Google Groups "vim_use" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
