Linux nano copy paste

A Beginner’s Guide on How to Use Nano Text Editor in Linux

Nano is a command line text editor, that comes preinstalled in almost every Linux distribution. It is often preferred by new users because of its simplicity, compared to other command line text editors such as vi/vim and emacs. It has plenty of useful features such as syntax coloring, line numbering, easy search and many others.

Install Nano Editor in Linux

If for any reason nano is not already installed on your Linux distro, you should be able to easily install it with the following commands:

# apt install nano [For Ubuntu/Debian] # yum install nano [For CentOS/Fedora]

Nano Keyboard Shortcuts

Nano uses keyboard combinations for different functions, such as to find text in a file, justify text etc. Those combinations are really easy and are visible while you edit your file. They change automatically depending on what action you are taking.

One thing you should know is that a keyboard shortcut represented with ^ and a symbol (for example ^W ) is a combination of the Ctrl key and that symbol (Ctrl+W in our example).

A combination that is shown to start with M means that it needs to be completed by pressing Alt key and the following symbol.

Below are listed the options that you will see when you first open nano:

You don’t need to remember each option as it is always in front of you. You can get the full list of keyboard combinations by pressing ^G (or press F1) which will open nano’s help menu. You will notice that some shortcuts can be used with single key.

For example F1 key to get help or F2 to exit nano.

Nano Editor Shortcut Keys

Create a New File in Nano

Creating new file is simple as running nano:

This will open the editor and upon saving the file, it will ask you to give it a name with which the new file will be saved.

Create New File in Nano

Open a File in Nano

To open a file you can run:

The above command will try to open the file “my_text_file.txt” from your home directory. If the file does not exist, nano will try to create it.

Sometimes, you may need to open a file and go at exact line or column. Nano allows you to do this with:

Will open your .bashrc file and the cursor will be located on the third line, second column.

Open File in Nano

Editing Files in Nano

Upon opening or creating files you can start editing/writing immediately. Unlike vim, there is no need to switch to edit mode in nano. To move the cursor around the file, you can use the arrow keys on your keyboard.

Читайте также:  Sti7105 bud прошивка linux

Edit Files in Nano

Search for Text in Nano

You can search for text inside a file by using ^W , which represents the “where is” option. This will open a search input above the menu, where you can input the text you are search for:

Search Text in Nano

You will also see that the bottom menu will change and will show some additional options. They are pretty much self explanatory, so we will review the more important ones.

  • Search with regular expressions – press M-R (Alt + R keys) and input your search with the regular expressions you wish to use.
  • Go to line – press ^T (Ctrl + T) followed by the line to which you want to move the cursor to.
  • Replace text – press ^R (Ctrl +T) in search mode, or ^\ in regular mode. You will be asked to enter your search, after pressing Enter, you will be asked to input the text which will be used for the replacement. Finally you will be asked if you wish to replace a matched instance of your search, or all matches. If you choose “No”, the cursor will be moved towards the next match.
  • Go to first line – press ^Y (Ctrl + Y).
  • Go to last line – press ^V (Ctrl +V).

Copy/Paste/Cut Text in Nano

Nano’s interface is very similar to a GUI text editors. If you wish to copy or cut a text in GUI editor, you will first have to select it. Same thing goes in nano. To mark a text press Ctrl + ^ then move the cursors with the arrow keys.

Copy and Paste Text in Nano

  • To copy the marked text press Alt + ^.
  • To cut the marked text press ^K (Ctrl +K).
  • To paste the marked text, move the cursor to a suitable position and press ^U (Ctrl + U).

Save File in Nano

If you wish to save your current changes to the file, press the ^O (Ctrl + O) combination. If you are editing a new file, you will be asked to give that file a name. This will save your current changes and nano will remain opened so you can continue making changes to the file.

Save File with Backup

Sometimes when editing a file, you may want to keep temporary copies of the same file just in case. You can use nano’s -B option, which will create backup of the file you are editing. You can use it in combination with the -C option to tell nano where to save those backups like this:

$ nano -BC ~/backups myfile.txt

The above will make backup copies of the file myfile.txt in the folder “backups” located in the user’s home directory. Note that the backup directory should be existing, otherwise, nano will tell you that the directory is invalid.

Exit Nano Editor

To exit nano, simply press ^X (Ctrl +X keys). If the file has not been previously saved, you will be asked to save the changes with yes/no or cancel the exit.

Conclusion

Nano is an easy to use command line text editor, that attracts users with its simplicity. Its interface is similar to those of GUI editors which makes it perfect for Linux newcomers.

Читайте также:  Manjaro linux dota 2

Источник

How to Cut, Copy and Paste Text in Nano editor?

While Nano is more beginner-friendly than Vim and Emacs, you still need to know the keyboard shortcuts for even the basic operations such as cut, copy and paste in Nano.

GNU Nano is an editor that has a minimal learning curve and hence is widely used for beginner-level guides.

That doesn’t mean that it is as easy to use for beginners as a graphical text editor. Why? because you still have to rely on the keyboard shortcuts to do the basic things such as save, undo, etc.

How about cut, copy and paste in Nano? Does it require specific keyboard shortcuts too?

Well, yes and no. You can use the mouse to copy-paste. There are also keyboard shortcuts for the same purpose. To cut, you must use shortcuts.

Let me show all this to you in detail.

Copy text in Nano

To copy a piece of text, the text needs to be selected first.

There are two ways to copy the text in Nano:

Using mouse to select, copy and paste

If you want a quick and dirty selection to copy text, there is no better way than using a mouse to do it.

Below are the steps you can follow:

Once the text is copied to clipboard, to paste text using mouse, make sure that you have moved the cursor to the location where you want to paste text.

Then, do a right click, and select «Paste» from the context menu that popped up.

This is what you should do to select, copy and paste text using mouse.

Using keyboard to select and copy (for pros)

Using a mouse to copy text is all good, but when you have to select text that extends the page, it gets frustrating. For that, you will need to use a few keyboard shortcuts.

Below are the steps to select and copy text using keyboard:

  1. To select text, press the Ctrl + 6 key combination. You will see «Mark Set» appear at the bottom of the screen as an acknowledgement.
  2. Now, use the arrow keys (keys like Home, End, Page Up and Page Down can also be used) to select/highlight text.
  3. To copy selected text, press Alt + 6 key combination.

You now have the text copied to your clipboard!

Cut text in Nano

The cut operation is very similar to the copy operation, the only difference is that the data is deleted from one location to be moved to another location.

Unfortunately, cutting text cannot be done with the use of a mouse, so let’s go over the steps to follow if you want to cut text.

  1. Select text using the Ctrl + 6 key combination.
  2. Use the arrow keys to highlight the text you want to cut.
  3. To cut the selected text, press Ctrl + K (think of it as Kutting text).

That is all there is to kutting text 😀

Paste in Nano

Finally, after copying or cutting the text, it won’t be much of a use if you can not paste text.

Читайте также:  Kali linux reaver wps

Thankfully, pasting text in nano is very easy. Follow the steps given below:

  1. Move your cursor to the location where you want to paste text
  2. Press Ctrl + U

Nano shows the keyboard shortcuts at the bottom of the screen all the time. So, even if you forgot it, you can always look at the bottom of the editor for hints or press Ctrl+G for help. If it says ^K for Cut, use Ctrl+K (^ means Ctrl key). Similarly, if it says M-A for Append, use Alt + M (M means Alt key).

Copy-paste between Nano and the system

If you want to copy text from a web browser or other editor into Nano, use the Ctrl+Shift+V to paste the text into Nano.

Similarly, if you want to copy some text from Nano to an external application, use Ctrl+Shift+C to copy the text and then the usual Ctrl+V to paste it.

When you use Ctrl+Shift+C/V keys, the text is copied into the system buffer and hence it can be used outside the Nano editor as well.

If you use the Nano specific keyboard shortcuts such as Ctrl+K etc, the text stays in Nano buffer. It cannot be accessed at the system level and hence you cannot use it outside Nano.

Conclusion

GNU Nano is a simple text editor that is known best for getting the job done without much fuss. This article covered the basics of copying, cutting and pasting text in Nano.

If you are interested in mastering the basics of Nano, try this free course on Nano.

Источник

Nano: И всё-таки его придётся выучить [2]

Продолжаем. Предыдущий топик (навигация по тексту): тут.

Сегодняшняя тема — работа с выделением, копирование и удаление кусков текста.

Для понимания принципов команд работы с текстом нужно сначала понять принцип выделения текста. Он осуществляется либо мышью, либо с клавиатуры. С клавиатуры выделение происходит так: сначала отмечается начало выделение: Alt-A или Ctrl-^. Далее следует навигация — и до момента выполнения действия над текстом в буффере, выделение сохраняется (обратите внимание, выделение сохраняется даже при вводе текста, в этом оно сильно отличается от выделения в gui-приложениях windows и ближе к persistent blocks в TurboC, DN и соответствующей опции Far Manager’а).

Обратите внимание, применимы все функции навигации, включая переход по номеру строки или поиск (в следующих выпусках).

Далее выделенный текст можно удалить или скопировать в буффер. Это делает комбинация Ctrl-K (или F9 ).

Выделенный текст можно скопировать в буффер обмена — комбинация Alt-6 (да, мы ЛЮБИМ nano).

Далее мы можем вставить текст из буффера обмена — Ctrl-U или F10 . Обратите внимание — в подсказке снизу написана неправда, это не отмена удаления, это вставка.

Кроме этого, для удобства редактирования, Ctrl-K при отсутствии выделения удаляет строку. Либо целиком, либо от курсора до конца строки. Поведение переключается комбинацией Alt-K (по-умолчанию стоит режим удалять строку целиком, а Alt-K переключает его туда-сюда).

Обратите внимание — удалённая строка в буффере, так что её можно вставить с помощью Ctrl-U .

Ещё одна комбинация для лентяев — Alt-T , стирающая всё от курсора и до конца файла (команда trunkate).

Для вставки текста из другого файла используется кнопка Ins (думаю, все пользователи vim хорошо знают поведение этой кнопки в nano).

Источник

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