aru Posted April 15, 2003 Report Share Posted April 15, 2003 Browse: [About the FAQ Forum] [Table of Contents] [FAQs] [Contribute] [CL: Command Line Questions] CL-01: How can I edit a file in the command line? You have been told to edit a file in command line to fix something, but you don't know which editor to use, or you don't know how to use it at all. Answer: For this task you should use the vi/vim editor which is installed by default in Linux. There are a few things you should know before using it: The vi (and his improved clone vim) is opened by default in "command mode"; in that mode you can't insert text, that mode is for browsing and editing (as in deleting whole lines) the file. So to insert/edit text you have to be in "insert mode". How to do it: Now browse using the arrow keys through the document till you find the line you want to edit. Remember that you are in "command mode". Go into "insert mode" either by pressing the "i" key, or pressing the "INSERT" key. Edit what you have to. Save the file and exit: To do this, you have to go back to "command mode" by pressing the "ESC" key. Once you are in "command mode" type :wq which means "w"rite and "q"uit. In case you want to exit w/o writting the changes you've made, then type in "command mode" :q! For further information about how to use vi/vim you can use the program "/usr/bin/vimtutor" or visit the vim faq: www.vim.org/faq/ [PREV: "CL: Command Line Questions"] [NEXT: "CL-02: How do I move/rename a file from the command line?"] Link to comment Share on other sites More sharing options...
Recommended Posts