【问题标题】:How do I edit a text file in Git Bash?如何在 Git Bash 中编辑文本文件?
【发布时间】:2017-07-10 09:46:17
【问题描述】:

我使用的是 Windows 10,并且在 Git Immersion 教程的 Lab 5 中,使用 Git Bash 作为我的 shell。

我使用echo 'puts "Hello, World"' > hello.rb 来创建 hello.rb 文件,如下所示: how to create a file with the cmd?

我是change our hello program to take an argument from the command line. Change the file to be:

puts "Hello, #{ARGV.first}!"

我曾想过使用 Sublime Text 来编辑文件,但我觉得不得不使用 Git Bash。如何在 Git Bash 中编辑文件?

谢谢!

【问题讨论】:

  • 为什么你觉得有必要使用 Git Bash?在我看来,Sublime Text 是适合这项工作的工具。
  • @Haoyu:你想在不使用文本编辑器的情况下编辑文件????当你有心情惩罚自己时,有很多行之有效的方法....
  • @user1934428 是否可以在 Git Bash 中使用诸如 emacs 之类的文本编辑器进行编辑?我知道它适用于提交 cmets。
  • 我从没想过人们可能想要使用文本编辑器以外的任何东西。我只是在徘徊:您之前是如何编辑程序的?为什么这与您使用的外壳有关?

标签: bash git git-bash


【解决方案1】:

对我来说,在 Git Bash 中编辑文件的最佳方式是命令“nano fileName.txt”。此命令打开编辑模式。完成工作后,按 Ctrl + x。然后用“y”批准更改以最终退出 nano。

【讨论】:

    【解决方案2】:

    使用 GNU sed 替换文本。

    sed -i "s/World/#{ARGV.first}\!/" hello.rb

    cat hello.rb  
    puts "Hello, #{ARGV.first}!  
    

    https://www.gnu.org/software/sed/manual/sed.html#The-_0022s_0022-Command

    编辑:或使用命令行编辑器,例如vivim

    【讨论】:

      猜你喜欢
      • 2019-12-31
      • 2021-03-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-10
      • 1970-01-01
      • 1970-01-01
      • 2022-12-15
      相关资源
      最近更新 更多