如何使用echo命令显示’?

例如,我想回应:

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

我试过但失败了:

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

如何显示正确的格式?

谢谢〜

你可以在这里使用文件 :

 cat <<-EOF au BufReadPost * if line("'\"") > 0|if line("'\"") \ <= line("$")|exe("norm '\"")|else|exe "norm $"|endif|endif EOF 

如果你想使用echo ,你需要做的就是使用单引号

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

唯一的问题是字符串中包含的文字单引号。
在这种情况下:

  1. 在文字之前关闭字符串'
  2. 写和逃脱单引号\'
  3. 重新打开字符串以继续以下字符

例如:

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

显然,如果文字单引号位于字符串的开头或结尾,则不应使用其中一个结束或开头引号:

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

您可以使用该命令输出您的特定字符串

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