Linux text editor terminal

Linux text editor terminal

Authored by: John Abercrombie

There are two command-line text editors in Linux®: vim and nano.

You can use one of these two available options should you ever need to write a script, edit a configuration file, create a virtual host, or jot down a quick note for yourself. These are but a few examples of what you can do with these tools.

While these tools might seem daunting at first, any Linux user should become accustomed to using at least one. Ask any Linux Administrator or regular user, and you soon find that everyone has their favorite.

This article covers the basics of each editing tool and how they differ.

Vim comes from Vi Improved because it is the successor of an older editor called vi. Because this editor (through its predecessor) has been around a long time, Linux Administrators or coders usually favor it. Vim is typically used by people who are familiar with Linux because it can have a bit of an uphill learning curve.

You can use vim to edit, write, and save a document from the command line. It does this through the use of two different modes:

By default, the vim editor opens in command mode. To open the vim editor, use the following syntax at the command line:

To start writing or editing, you must enter insert mode by pressing the letter i on your keyboard (“I” for insert). You should see —INSERT— at the bottom of your terminal page if you did it correctly.

When you are finished typing, and you want to save your work, you need to exit insert mode. Press the escape (esc) key, which places you back in command mode. Then you can save your work.

After you press escape, press shift + ;. The bottom of your terminal screen changes to reflect that you did it correctly. You now see a : where the —INSERT— was.

After you see the : in the lower left-hand corner of your vim editor, type w and then press enter to save your work. Then, you can either type i again to go back into insert mode if you want to continue writing, or you can quit the file. To quit, press shift + ; again, type q and then press enter. This saves your file and closes vim. You should see your usual terminal screen again.

You can also enter both the save and quit functions at the same time. To save and quit vim in one command, type wq after the : and then press enter. The file saves and closes.

If you start working on a file, but you change your mind, you can exit without saving. To do this, enter command mode by pressing esc followed by shift + ;. After you see the : at the lower left, enter q! . This force-quits vim without saving. ! is the force function.

Those commands are the ones that you are going use most of the time, but you can use the following cheat sheet if you want to do more complex actions with vim.

Vim editor cheat sheet

Use the following commands in command mode:

  • h — Moves the cursor to the left by one character; you can also press the left arrow.
  • j — Moves the cursor one line down; you can also press the down arrow.
  • k — Moves the cursor one line up; you can also press the up arrow.
  • l — Moves the cursor to the right by one character; you can also press the right arrow.
  • w — Moves the cursor one full word to the right.
  • b — Moves the cursor one full word to the left.
  • 0 — Moves the cursor to the beginning of the current line.
  • $ — Moves the cursor to the end of the current line.

— Changes the case of the current character.

  • dd — Deletes the current line.
  • D — Deletes everything on the line to the right of the cursor’s current position.
  • x — Deletes the current character.
  • u — Undo the last command.
  • . — Repeats the last command.
  • :w — Saves current file, but does not exit.
  • :wq — Saves current file, and quits.
  • The following commands place you into insert mode:

    • i — Inserts to the left of the current cursor position.
    • a — Appends to the right of the current cursor position.
    • dw — Deletes the current word.
    • cw — Changes the current word.

    Nano is a newer text editor in Linux systems. It’s simpler and easier to use than vim.

    To open a file with nano, use the following syntax at the command line:

    After the nano editor opens, you can begin typing. When you’re ready to save your work, press ctrl + o, which is called a write out. It saves your current work while allowing you to continue your work. If you’re done, you can save and quit by pressing ctrl + x. When you save a file in nano, your current work is color-coded based on what you’re writing.

    Another major difference with nano is that you can access a list of commands within the editor, but you can use the following cheat sheet as well.

    Nano editor cheat sheet

    Note: The commands in the following list use ^ to indicate that you should press the ctrl key along with the other key. For example ^G means that you should press ctrl + G.

    • ^G — Get Help.
    • ^X — Exit. Nano then asks if you want to save with a Y or N option.
    • ^O — Write Out; also known as save.
    • ^R — Read File. Enter the name of a file you want to paste into the current document at your cursor’s position.
    • ^W — Where Is; Search function.
    • ^\ — Replace.
    • ^K — Cut text.
    • ^U — Uncut text.
    • ^J — Justify.
    • ^T — To spell.
    • ^C — Current Position; Cancel save.
    • ^_ — Go to line.

    You can use the man pages to find out more in-depth information about each text editor. The commands are ‘man vim’ or ‘man nano’, respectively.

    Share this information:

    ©2020 Rackspace US, Inc.

    Except where otherwise noted, content on this site is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License

    Источник

    Best Linux Command Line Text Editors

    Text editors are useful tools for any operating system to work with this. While working with the GUI-based operating system, you can find lots of text editors.

    The Linux users and system administrators always prefer to use command line interface to work on it. In this guide, you will find some details of the most favorite and useful command line text editors.

    Note: Fedora 22+ Users use DNF to install packages instead of yum.

    #1. vi/vim – Text Editor

    Vi (visual editor) or Vim is most commonley used text editor for the command line users. The minimum operating system installation may not have default installed it. Use the following command to install.

    #2. Nano

    Nano is another favorite and commonley used text editors by the command line users. This also default installed on most of the Linux platforms. You can also use following command to install nano on your Linux system.

    #3.Nice Editor (ne)

    Nice (ne) editor is intended to provide an alternative to vi that will be more familiar to beginners. The ne text editor supports most of the common features in advanced text editors, such as syntax highlighting, regular expressions, key bindings, and auto-completes etc. Use the following command to install this on your system.

    #4. EMACS

    Emacs is an extensible, customizable and real time display editor. This is a GNU project application for command line lovers. Install Emacs on your system using the following commands.

    #5. mc (Midnight Commander)

    Midnight Commander provides an internal text editor, which can be invoked with mc -e or mcedit commands, featuring syntax highlighting, regexp searching and other features.

    Источник

    How to open, create, edit, and view a file in Linux

    One thing GNU/Linux does as well as any other operating system is give you the tools you need to create and edit text files. Ask ten Linux users to name their favorite text editor, and you might get ten different answers. On this page, we cover a few of the many text editors available for Linux.

    GUI text editors

    This section discusses text editing applications for the Linux windowing system, X Windows, more commonly known as X11 or X.

    If you are coming from Microsoft Windows, you are no doubt familiar with the classic Windows text editor, Notepad. Linux offers many similar programs, including NEdit, gedit, and geany. Each of these programs are free software, and they each provide roughly the same functionality. It’s up to you to decide which one feels best and has the best interface for you. All three of these programs support syntax highlighting, which helps with editing source code or documents written in a markup language such as HTML or CSS.

    NEdit

    NEdit, which is short for the Nirvana Editor, is a straightforward text editor that is very similar to Notepad. It uses a Motif-style interface.

    The NEdit homepage is located at https://sourceforge.net/projects/nedit/. If you are on a Debian or Ubuntu system, you can install NEdit with the following command:

    For more information, see our NEdit information page.

    Geany

    Geany is a text editor that is a lot like Notepad++ for Windows. It provides a tabbed interface for working with multiple open files at once and has nifty features like displaying line numbers in the margin. It uses the GTK+ interface toolkit.

    The Geany homepage is located at http://www.geany.org/. On Debian and Ubuntu systems, you can install Geany by running the command:

    Gedit

    Gedit is the default text editor of the GNOME desktop environment. It’s a great, text editor that can be used on about any Linux system.

    The Gedit homepage is located at https://wiki.gnome.org/Apps/Gedit. On Debian and Ubuntu systems, Gedit can be installed by running the following command:

    Terminal-based text editors

    If you are working from the Linux command line interface and you need a text editor, you have many options. Here are some of the most popular:

    pico started out as the editor built into the text-based e-mail program pine, and it was eventually packaged as a stand-alone program for editing text files. («pico» is a scientific prefix for very small things.)

    The modern version of pine is called alpine, but pico is still called pico. You can find more information about how to use it in our pico command documentation.

    On Debian and Ubuntu Linux systems, you can install pico using the command:

    nano is the GNU version of pico and is essentially the same program under a different name.

    On Debian and Ubuntu Linux systems, nano can be installed with the command:

    vim, which stands for «vi improved,» is a text editor used by millions of computing professionals all over the world. Its controls are a little confusing at first, but once you get the hang of them, vim makes executing complex editing tasks fast and easy. For more information, see our in-depth vim guide.

    On Debian and Ubuntu Linux systems, vim can be installed using the command:

    emacs

    emacs is a complex, highly customizable text editor with a built-in interpreter for the Lisp programming language. It is used religiously by some computer programmers, especially those who write computer programs in Lisp dialects such as Scheme. For more information, see our emacs information page.

    On Debian and Ubuntu Linux systems, emacs can be installed using the command:

    Redirecting command output into a text file

    When at the Linux command line, you sometimes want to create or make changes to a text file without actually running a text editor. Here are some commands you might find useful.

    Creating an empty file with the touch command

    To create an empty file, it’s common to use the command touch. The touch command updates the atime and mtime attributes of a file as if the contents of the file had been changed — without actually changing anything. If you touch a file that doesn’t exist, the system creates the file without putting any data inside.

    For instance, the command:

    The above command creates a new, empty file called myfile.txt if that file does not already exist.

    Redirecting text into a file

    Sometimes you need to stick the output of a command into a file. To accomplish this quickly and easily, you can use the > symbol to redirect the output to a file.

    For instance, the echo command is used to «echo» text as output. By default, this goes to the standard output — the screen. So the command:

    The above command prints that text on your screen and return you to the command prompt. However, you can use > to redirect this output to a file. For instance:

    The above command puts the text «Example text» into the file myfile.txt. If myfile.txt does not exist, it is created. If it already exists, its contents will be overwritten, destroying the previous contents and replacing them.

    Be careful when redirecting output to a file using >. It will overwrite the previous contents of the file if it already exists. There is no undo for this operation, so make sure you want to completely replace the file’s contents before you run the command.

    Here’s an example using another command:

    The above command executes ls with the -l option, which gives a detailed list of files in the current directory. The > operator redirects the output to the file directory.txt, instead of printing it to the screen. If directory.txt does not exist, it is created first. If it already exists, its contents will be replaced.

    Redirecting to the end of a file

    The redirect operator >> is similar to >, but instead of overwriting the file contents, it appends the new data to the end of the file. For instance, the command:

    Источник

    Читайте также:  Отключение spotlight mac os big sur
    Оцените статью