Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

for example I want to echo :

  "let vim know the last edit position
  au BufReadPost * if line("'\"") > 0|if line("'\"")
  \ <= line("$")|exe("norm '\"")|else|exe "norm $"|endif|endif

I tried but failed:

  echo '
  "let vim know the last edit position
  au BufReadPost * if line("\'\"") > 0|if line("\'\"")
  \ <= line("$")|exe("norm \'\"")|else|exe "norm $"|endif|endif
  '

How to show the correct format?

Thank you~

share|improve this question
add comment

2 Answers 2

up vote 4 down vote accepted

You can use here documents:

cat <<-EOF
  au BufReadPost * if line("'\"") > 0|if line("'\"")
  \ <= line("$")|exe("norm '\"")|else|exe "norm $"|endif|endif
EOF
share|improve this answer
    
I was going to answer the best I could do is to use cat rather then echo. –  bodhi.zazen Jan 29 '12 at 4:56
add comment

If you want to use echo, all you need to do is to use single quotes

'string containing many strange characters $ " \ and so'

The only problem is posed by literal single quotes contained in the string.
In such a case:

  1. close the string before the literal '
  2. write and escaped single quote \'
  3. reopen the string to continue with following characters

For example:

aaa'bbb  ==>  'aaa' + \' + 'bbb'  ==>  'aaa'\''bbb'

Obviously, if the literal single quote is at the start or end of the string, one of the closing or opening quote should not be used:

'aaa'bbb  ==>  \' + 'aaa' + \' + 'bbb'  ==>  \''aaa'\''bbb'

Your specific string can be output with the command

echo '"let vim know the last edit position
au BufReadPost * if line("'\''\"") > 0|if line("'\''\"")
\ <= line("$")|exe("norm '\''\"")|else|exe "norm $"|endif|endif'
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.