Linux nano remove line

Getting Started With Nano Text Editor [Beginner’s Guide]

Though Nano is less complicated to use than Vim and Emacs, it doesn’t mean Nano cannot be overwhelming. Learn how to use the Nano text editor.

Nano is the default terminal-based text editor in Ubuntu and many other Linux distributions. Though it is less complicated to use than the likes of Vim and Emacs, it doesn’t mean Nano cannot be overwhelming to use. In this beginner’s guide, I’ll show you how to use the Nano text editor. I will also include a downloadable PDF cheat sheet at the end of the article so that you can refer to it for practicing and mastering Nano editor commands. Please expand the next section if you are just interested in a quick summary of Nano keyboard shortcuts.

Essential Nano keyboard shortcuts

Shortcut Description
nano filename Open file for editing in Nano
Arrow keys Move cursor up, down, left and right
Ctrl+A, Ctrl+E Move cursor to start and end of the line
Ctrl+Y/Ctrl+V Move page up and down
Ctrl+_ Move cursor to a certain location
Alt+A and then use arrow key Set a marker and select text
Alt+6 Copy the selected text
Ctrl+K Cut the selected text
Ctrl+U Paste the selected text
Ctrl+6 Cancel the selection
Ctrl+K Cut/delete entire line
Alt+U Undo last action
Alt+E Redo last action
Ctrl+W, Alt+W Search for text, move to next match
Ctrl+\ Search and replace
Ctrl+O Save the modification
Ctrl+X Exit the editor

How to use Nano text editor

I presume that you have Nano editor installed on your system already. If not, please your distribution’s package manager to install it.

Getting familiar with the Nano editor interface

Nano Editor Interface

If you’ve ever used Vim or Emacs, you’ll notice that using Nano is a lot simpler. You can start writing or editing text straightaway. Nano editor also shows important keyboard shortcuts you need to use for editing at the bottom of the editor. This way you won’t get stuck at exiting the editor like Vim. The wider your terminal window, the more shortcuts it shows. You should get familiar with the symbols in Nano.

  • The caret symbol (^) means Ctrl key
  • The M character mean the Alt key

When it says “^X Exit”, it means to use Ctrl+X keys to exit the editor. When it says “M-U Undo”, it means use Alt+U key to undo your last action.

Open or create a file for editing in Nano

You can open a file for editing in Nano like this:

Читайте также:  День рождения операционной системы linux

If the file doesn’t exist, it will still open the editor and when you exit, you’ll have the option for saving the text to my_file.

You may also open a new file without any name (like new document) with Nano like this:

Basic editing

You can start writing or modifying the text straightaway in Nano. There are no special insert mode or anything of that sort. It is almost like using a regular text editor, at least for writing and editing.

As soon as you modify anything in the file, you’ll notice that it reflects this information on the editor.

Nano Modified Text

Nothing is saved immediately to the file automatically unless you explicitly do so. When you exit the editor using Ctrl+X keyboard shortcut, you’ll be asked whether you want to save your modified text to the file or not.

Moving around in the editor

Mouse click doesn’t work here. Use the arrow keys to move up and down, left and right.

You can use the Home key or Ctrl+A to move to the beginning of a line and End key or Ctrl+E to move to the end of a line. Ctrl+Y/Page Up and Ctrl+V/Page Down keys can be used to scroll by pages.

If you want to go a specific location like last line, first line, to a certain text, use Ctrl+_ key combination. This will show you some options you can use at the bottom of the editor.

Nano Editor Jump To Line

Cut, copy and paste in Nano editor

If you don’t want to spend too much time remembering the shortcuts, use mouse.

Select a text with mouse and then use the right click menu to copy the text. You may also use the Ctrl+Shift+C keyboard shortcut in Ubuntu terminal. Similarly, you can use the right click and select paste from the menu or use the Ctrl+Shift+V key combination.

Nano specific shortcuts for copy and pasting

Nano also provides its own shortcuts for cutting and pasting text but that could become confusing for beginners.

Move your cursor to the beginning of the text you want to copy. Press Alt+A to set a marker. Now use the arrow keys to highlight the selection. Once you have selected the desired text, you can Alt+6 key to copy the selected text or use Ctrl+K to cut the selected text. Use Ctrl+6 to cancel the selection.

Once you have copied or cut the selected text, you can use Ctrl+U to paste it.

Nano Editor Set Mark

Delete text or lines in Nano

There is no dedicated option for deletion in Nano. You may use the Backspace or Delete key to delete one character at a time. Press them repeatedly or hold them to delete multiple characters.

You can also use the Ctrl+K keys that cuts the entire line. If you don’t paste it anywhere, it’s as good as deleting a line.

If you want to delete multiple lines, you may use Ctrl+K on all of them one by one.

Another option is to use the marker (Ctrl+a). Set the marker and move the arrow to select a portion of text. Use Ctrl+K to cut the text. No need to paste it and the selected text will be deleted (in a way).

Undo or redo your last action

Cut the wrong line? Pasted the wrong text selection? It’s easy to make such silly mistakes and it’s easy to correct those silly mistakes.

You can undo and redo your last actions using:

You can repeat these key combinations to undo or redo multiple times.

Читайте также:  Switch linux kernel ubuntu

Search and replace

If you want to search for a certain text, use Ctrl+W, enter the term you want to search, and press enter. The cursor will move to the first match. To go to the next match, use Alt+W keys.

Nano Editor Basics: Search for Text

By default, the search is case-insensitive. You can also use regex for the search terms.

If you want to replace the searched term, use Ctr+\ keys and then enter the search term and press enter key. Next it will ask for the term you want to replace the searched items with.

Nano Editor Tips: Search and Replace

The cursor will move to the first match and Nano will ask for your conformation for replacing the matched text. Use Y or N to confirm or deny respectively. Using either of Y or N will move to the next match. You may also use A to replace all matches.

Nano Editor Basics: Replace Confirm

Save your file while editing (without exiting)

In a graphical editor, you are probably used to of saving your changes from time to time. In Nano, you can use Ctrl+O to save the changes you made to the file. It also works with a new, unnamed file.

Nano Editor Tips: Save While Writing

Nano shows this keyboard shortcut at the bottom but it’s not apparent. It says “^O Write Out” which means to use Ctrl+O (it is the letter O, not the number zero) to save your current work. Not everyone can figure that out.

In a graphical text editor, you probably use Ctrl+S to save your changes. Old habits die hard but they could cause trouble. Out of habit, if you accidentally press Ctrl+S to save your file, you’ll notice that the terminal freezes and you can do nothing.

If you accidentally press Ctrl+S press Ctrl+Q nothing can be scarier than a frozen terminal and losing the work.

Save and exit Nano editor

To exit the editor, press Ctrl+X keys. When you do that, it will give you the option to save the file, or discard the file or cancel the exit process.

Save and Exit Nano editor

You can also do that if you want to save the modified file as a new file (save as function in usual editors). When you press Ctrl+X to exit and then Y to save the changes, it gives the option to which file it should save. You can change the file name at this point.

You’ll need to have ‘write permission’ on the file you are editing if you want to save the modifications to the file.

Forgot keyboard shortcut? Use help

Like any other terminal based text editor, Nano relies heavily on keyboard shortcuts. Though it displays several useful shortcuts at the bottom of the editor, you cannot see all of them.

It is impossible to remember all the shortcuts, especially in the beginning. What you can do is to use the Ctrl+G keys to bring up the detailed help menu. The help menu lists all the keyboard shortcuts.

Nano Editor Help Menu

Always look at the bottom of the Nano editor

If you are using Nano, you’ll notice that it displays important information at the bottom. This includes the keyboard shortcuts that will be used in the scenario. It also shows the last action you performed.

Nano Editor Hints

If you get too comfortable with Nano, you can get more screen for editing the text by disabling the shortcuts displayed at the bottom. You can use Alt+X keys for that. I don’t recommend doing it, to be honest. Pressing Alt+X brings the shortcut display back.

Download Nano cheatsheet [PDF]

There are a lot more shortcuts and editing options in Nano. I am not going to overwhelm you by mentioning them all.

Читайте также:  Domain server with linux

Here’s a quick summary of the important Nano keyboard shortcuts you should remember. The download link is under the image.

Nano Editor Cheatsheet

You can download the cheatsheet, print it and keep at your desk. It will help you in remembering and mastering the shortcuts.

I hope you find this beginner’s guide to Nano text editor helpful. If you liked it, please share it on Reddit, Hacker News or in various Linux forums you frequently visit.

I welcome your questions and suggestions.

Источник

[!] nano Справочник: Работа с текстоыми файлами в терминале, редактирование, сохранение, поиск — примеры горячих клавиш

vedro-compota's picture

Чтобы сохранить файл в редакторе nano сначала набираем комбинацию клавиш:

потом в ответ на уточняющий вопрос набираем букву:

Потом убедитесь что предлагается сохранить файл на то же место, где он и был и нажмите клавишу ВВОД

Копирование и вставка текста

Чтобы начать выделение (или отменить его) используйте:

Чтобы скопировать выделенное в буфер обмена (альт шифт шесть):

Чтобы вставить текст из буфера, начиная позиции курсора:

Следует учитывать, что скопированный таким образом текст можно вставить только в самом nano, но не перенести наружу.

Выделение и удаление фрагмента текста (нескольких строк)

  • Ставим курсор в нужную позицию и нажимаем CTRL+Shift+6, чтобы отметить начало блока
  • Затем переводим курсор на конец блока
  • Нажимаем CTRL+K, чтобы удалить выделенное

Поиск

Чтобы начать искать нажмите:

Введите фрагмент и нажмите Enter

Перейти к следующему найденному фрагменту

Перейти к следующему найденному можно с помощью комбинации:

Переход к указанной строке по номеру

Вывести номер текущей строки, символа (позиции курсора)

Используйте комбинацию клавиш:

Другие команды

Key Words for FKN + antitotal forum (CS VSU):

  • linux nano
  • Linux nano сохранить файл
  • nano
  • ubuntu nano
  • nano как редактировать файлы
  • nano поиск текста
  • nano поиск строки
  • nano Перейти к следующему найденному объекту
  • nano Как работать в linux
  • nano Скопировать и вставить текст — копипаста
  • nano Выделить весь текст
  • nano Выделить всё
  • nano linux команды
  • nano linux Справочник основные команды
  • nano копировать в буфер
  • нано
  • справочник
  • nano remove several lines
  • удалить выделенное
  • nano go to line

Источник

[Quick guide] How to delete a line in nano

It can be difficult for beginners to work out how to delete a line in nano. Here’s how to do it in three simple steps.

BitLaunch

BitLaunch

[Quick guide] How to delete a line in nano

Nano is the command-line text editor of choice for many Ubuntu users, partially because its basic functions are quite intuitive to use. Even so, there are a few things that trick new users up. One, as we’ve already covered, is how to exit nano, but the second is deleting a line in nano. This very quick guide will get you up to speed.

Deleting a line in nano

Though it makes copious use of hotkeys, deleting a line in nano isn’t that difficult. All you need to is:

  1. Press CTRL + Shift + 6 with your cursor at the start of your line

2. Move the cursor to the end of the line using the arrow keys

3. Press Ctrl + K to cut the text and therefore delete the line in nano

That’s it. You can now delete the extra line if you wish, or use the selection shortcut to delete other parts of your document.

How to Install Outline VPN on a VPS

How to Install Outline VPN on a VPS

Get started with an Outline VPN in a few minutes using BitLaunch VPS servers.

How to check your SSH key fingerprint (verify the authenticity of the remote host)

How to check your SSH key fingerprint (verify the authenticity of the remote host)

Verifying the authenticity of your server is very important when connecting to it for the first time. Here’s how to do it.

Источник

Оцените статью
Adblock
detector