Jump to content

Search the Community

Showing results for tags 'emacs'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

There are no results to display.

There are no results to display.


Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Website URL


LinkedIn Profile URL


About Me


Cloud Platforms


Cloud Experience


Development Experience


Current Role


Skills


Certifications


Favourite Tools


Interests

Found 6 results

  1. The post Get Started with Emacs: Mastering Text Editing in Linux first appeared on Tecmint: Linux Howtos, Tutorials & Guides .GNU Emacs is one of the oldest text editors. It was created by Richard Stallman, the founder of the Free Software movement and GNU project. The post Get Started with Emacs: Mastering Text Editing in Linux first appeared on Tecmint: Linux Howtos, Tutorials & Guides.View the full article
  2. We all appreciate the high customization and extensible nature of the Emacs text editor. Emacs offers powerful features coupled with the intensive use of keyboard shortcuts, providing the users with quick access and a workaround. If you are new to Emacs, these keyboard shortcuts can be challenging to master, especially when you are unsure of what the different commands do and the various keyboard shortcuts that you can use. To help clear the confusion, this post focuses on the Emacs key bindings. We will discuss the commonly used keys while giving examples whenever applicable. Different Categories and Examples of Emacs Key Bindings At first, Emacs can seem more complicated than the other text editors. With Emacs, everything can be done using key bindings, and mastering your way of using the keys is stressful. However, we curated the most common keys that you should know and arrange them based on their functionality. This breakdown will give you comfort and ease as you get started with Emacs. 1. Modifier Keys Emacs uses two modifier keys. The first is the Ctrl (control). The other is the Meta key (Alt/Esc). The “Ctrl” key is used with basic commands to trigger an event. For instance, you can trigger the search feature by pressing “C-x x-f”. In such a case, you press the “Ctrl + x” keys simultaneously, then release and press the “Ctrl + f” keys to bring up the search prompt. You will get an output like the one in the following: The “Meta” key is combined with other keys to trigger the commands. For instance, you can use the Emacs command prompt by pressing “M-x”. Press the “Alt + x” keys simultaneously and then type your command. 2. Basic Movements Using the control/Ctrl and Meta (Alt) keys, you can quickly navigate a buffer. C-p – It moves the cursor up. C-n – It moves the cursor down. C-b – It moves the cursor left. C-f – It moves the cursor right. C-a – It moves to the start of the line. C-e – It moves to the end of the line. M-f – It moves the cursor forward one word. M-b – It moves the cursor back one word. 3. Text Keys You can quickly select, copy, cut, and paste the texts with the following keys: C-SPC (Ctrl + Space) – Start selecting the text. You will get an output that the mark has been set. M-w – Copy the selected text C-w – Cut the selected text C-y – Paste the text from the clipboard 4. Search Features Emacs lets you search within the text. You can also search for files when opening them. C-s – Increments a search forward C-r – Increments a search backward C-x C-f – It lets you search and open a file. 5. Working with the Buffer Emacs works with buffers and windows, and you can have multiple open buffers. Such a case requires you to know what keys to use. C-x b – Switch between open buffers C-x 1 – Close all open windows except the active one C-x 2 – Split a window horizontally C-x 3 – Split a window vertically C-x C-s – Save the changes made to the current buffer C-x C-c – Exit Emacs. If any buffer is open, it prompts you whether to save it before exiting. 6. Customization and Commands You can customize Emacs using the configuration file. The configuration file is either “.emacs” or “.emacs.d/init.el”. To invoke a command such as the “text-scale-adjust”, press the “M-x”. Then, type the command’s name. Press the Enter/RET key to run the command. You can kill the current command by pressing the “C-g” keys. To undo the changes, use the “C-x u” keys. Conclusion Emacs is a powerful text editor, thanks to the numerous key bindings that you can utilize to perform the operations quickly. We discussed the commonly used Emacs key bindings to get you up-to-speed using the Emacs text editor. With that, you are ready to use and level up your usage and experience. Feel free to practice more key bindings; there are tons of them. Happy editing! View the full article
  3. Whether you are a pro or a novice Emacs user, there are some basic things that are worth knowing such as how to highlight the current line. By default, Emacs doesn’t highlight the current line. You might have been used to highlighting the current line for quick access and better user experience when coming from other text editors. Even in Emacs, it’s possible to customize it to highlight the current line to increase the visibility. When defining how to highlight the current line, you can specify what color to use for the background and foreground of the highlighted current line. Why Highlight the Current Line in Emacs? Knowing how to highlight the current line in Emacs offers you the following benefits: Better Navigation and Visual Clarity – Quickly noticing the current line improves your navigation of the opened file. That way, you will have a better focus when scrolling through the Emacs file. Better Readability – Your overall readability in Emacs will improve once you enable highlighting the current line. For instance, if in the programming mode, you can easily read the current line as it stands out over the others. Moreover, it reduces eye strain. How to Highlight the Current Line in Emacs When you open an Emacs file, the current line as you scroll doesn’t get highlighted which limits the visual clarity. We can see no highlight of the current file in the following Emacs file: To change this, let’s start by accessing the Emacs config file. Open your “.emacs” or “.emacs.d/init.el” file. Emacs offers the “global-hl-line-mode” feature which allows the users to activate the highlighting of the current line. Once your Emacs config file opens, add the following line to activate the line highlighting: (global-hl-line-mode 1) Save the configuration file by pressing the “C-x c-s” keys. You will get an output showing that the file has been written which means that it has been saved. Restart Emacs or close the buffer and open Emacs again for the changes to apply. By reopening the previous file on Emacs, we can now notice that the current line is highlighted. With this option, we can navigate the file and we have a better visual of the current line. Change the Background and Foreground Colors of the Highlighted Line The default background and foreground colors for the currently highlighted line in Emacs can be changed. If you do not feel okay with the background color, use the “set-face-background” attribute and add the color code that you prefer. Open your Emacs again and add the following line: (set-face-background ‘hl-line “#00FF00”) For our case, we are using the #00FF00 color code for the green color. Change it to suit your preference. Save the configuration file by pressing “c-x c-s” and restart Emacs. Notice how we now have a new background color for the currently highlighted line in Emacs. You can also change the foreground color by adding the “set-face-foreground” attribute and specifying the color code to use. For instance, to set the foreground to red, add the following line: (set-face-foreground ‘hl-line “#FF0000”) Similarly, you must save the configuration file and restart Emacs for the changes to apply. We now have red as our foreground color for the currently highlighted line in Emacs. You can change the color code and use any supported color that you are comfortable with. The aim is to get better visuals when using Emacs, and the choice of color is individual. Feel free to try out different colors and see how they appear. That way, you will make a better choice of which color to use. Conclusion Emacs only highlights the current line if you enable the feature. The “global-hl-line-mode” enables the line highlighting. Once you activate it, you can also specify what color to use as the background and foreground of the highlighted line. We discussed about highlighting the current line in Emacs and provided the steps to follow to activate and customize it. Enjoy! View the full article
  4. When working with Emacs, there are different instances when you need to select all the text in your buffer. Maybe you want to cut the entire text or paste it elsewhere. As a text editor, Emacs offers different ways to select all the text in your buffer. This guide focuses on the two main ways of selecting all in Emacs. Moreover, we will give the steps and commands on what to do after selecting all the text. For instance, we will see how to copy or cut the selected area. Let’s begin! Two Ways on How to Select All Texts in Emacs When you want to select all in Emacs, the goal is to mark a “region” that you want to select. In this case, the region is the entire text in your buffer. For instance, if you want to cut/delete all the text inside your buffer, selecting it all is the easiest option instead of deleting character by character. Let’s cover two methods of implementing the Emacs “select all”. Method 1: Using the Keyboard Shortcuts Like most things in Emacs, you can select all using the keyboard shortcuts. With this method, you must define the start and end area for the target region. Since our goal is to select all, the start mark is the start of the buffer and the end mark is the end of the buffer. To mark the start of the buffer, ensure that your cursor position is at the start or where you want to start selecting from. Next, press the “C-space” or the “Ctrl + Space” keyboard shortcut to mark the start position. You will get an output that shows “Mark activated” to confirm that the start area has been marked. The next step is to select the last mark which is the buffer’s end. Move the cursor to the end of the buffer using the “M ->” command which is the “Alt+Shift+ >” keyboard shortcut. Doing so will select the marked region, similar to selecting everything inside your Emacs buffer. You will notice how the background color will change to confirm the selected buffer region. You are now ready for the next task which is to cut the selected region or perform other formatting options. Method 2: Using the “Mark-Whole-Buffer” Command Suppose you feel that setting the start and end of the target region is such a hassle. There is an easy way out. For this second method, we will use the “mark-whole-buffer” command. Open your buffer that contains the text that you want to select. To select it all, press the “C-x h” command which means pressing “Ctrl +x then h”. The region inside your buffer will be selected and the background color will change to confirm that you managed to select it. You will get an output that shows “Mark set” which confirms that the target region has been selected. Working on the Selected Region We’ve seen the two methods that you can use to select all in Emacs. After selecting the region, there are different operations that you can perform. For instance, you can copy, cut, or paste the text. Let’s go through each of it. Copying You can only copy a selected item. To copy the selected region inside a buffer, ensure that you selected it using either of the methods that were covered earlier. Then, press the “M-w” command which is the “Alt + w” keyboard shortcut to copy the text. Cutting the Text You can delete all the selected text inside your buffer using the “cut” option. Select the region, then press the “C-w” command which is “Ctrl + w” and all the text/region will be deleted from your buffer. Paste the Text If you want to copy-paste the selected text, start by selecting it and copying it. Lastly, press the “C-y” command, the “Ctrl + y”, to paste the copied text where the cursor is. We pasted the text in our following example to duplicate it. Conclusion Emacs allows you to select all the text inside your buffer for different operations. Whether you want to copy or cut the text inside the buffer, this post has presented two methods to select all the contents inside your buffer by marking the region. Lastly, we provided three operations on what to do with the selected region including copying, cutting, and pasting the text. View the full article
  5. When working with an Emacs file, you can make changes and revert to the previous state. Such a situation is what reloading a file means. It allows you to discard all changes you made in your buffer and have the initial state of the buffer. The reloaded file will open the version that is stored in your discard. Reloading a file is a neat way of undoing all the changes you made to your file, and Emacs offers different ways of reloading the current file. This post covers two methods on how to reload the current file. First, we will talk about a revert method. Then, we will create a shortcut for implementing the “reload” command. Let’s get started! Two Methods to Reload the Current File in Emacs Emacs treats the reloading of the current file as a request to discard all unsaved changes. Doing so retrieves the version of the file that is stored on the disk and all the changes will be discarded. Opening a file in Emacs implies loading it into an Emacs buffer. When you alter the file, the changes won’t affect the version that is stored on the disk until you save the file. However, if you change your mind, you can always reload the current file to discard the changes and use the version that is stored on the disk. Emacs will prompt you when reloading the file whether to save or discard the changes. Method 1: Using the Reload Command Emacs has the “revert-buffer” command in which you run whenever you want to reload a file. For this example, we will work with the following file. We loaded it into Emacs and added one line: Suppose we want to discard the changes and remove the added line. Reloading the file will do the trick. Press “M-x'” (Alt + x) on your Emacs and type “revert-buffer” in the command prompt. Once you press the RET/Enter keyboard key, the command will execute and you will be prompted to confirm that you want to revert the buffer which discards all the unsaved changes. To reload the file, type “yes” and press the RET key. Immediately after doing it, the file will be reloaded and all the unsaved changes we had will be discarded. We now have the file that was stored on the disk, and it doesn’t contain the last line that we added earlier. That’s how you quickly discard the changes in your Emacs file. Method 2: Binding the Reload Command Instead of typing the “revert-buffer” command whenever you want to reload the current file, you can bind the command to a key. That way, pressing the binded key does the same task as the “revert-buffer” command. The first step is to open up your Emacs config file. The config file can be “.emacs” or “.emacs.d/init.el”. Once you open it, we must bind the key to the “reload” command. Use the “global-set-key” attribute and specify what key to bind and to what command. We are using the “f8” key for this case and our bind statement is as follows: Save the configuration file by pressing “c-x c-s”. To apply our changes, restart your Emacs or reopen it. Now, we go back to our initial file that we loaded into an Emacs buffer. Instead of typing the “revert-buffer” command like in the first method, we only press the “f8” key here. Doing so brings up a prompt to confirm that we want to reload the file and discard all the changes. Once you confirm that you want to reload the file, all the changes will be discarded, and you will have the file version that was stored on the disk. That’s how you reload the current file in Emacs. Conclusion Reloading a file in Emacs implies reverting to the version of the file that is stored on the disk. It’s a way of discarding all the unsaved changes on the file that is loaded into Emacs. You can reload a file in two methods. The first method is using the “revert-buffer” command and confirming the prompt. The second method is binding the “revert-buffer” command to a key and pressing the key whenever you want to reload the current file. Both options are discussed in this post. View the full article
  6. As an Emacs user, the default font size on the current buffer or the global buffers may not suit your case. You may feel that the current size is too large or small for clear visibility. When working with texts, knowing how to adjust the font size frees you from straining your eyes by giving you the power to change the text size for the best visibility. There are different ways to increase the font size in Emacs on Linux, and this post will go through a few of the best options that you should use. Two Ways of Increasing the Font Size in Emacs on Linux Some people are okay with the default font size in Emacs, but suppose the font size is too small for you. There are quick steps to increase the font size to a comfortable size. Go through each discussed method to see which works best for you. Method 1: Using the Key Combinations Using the key shortcuts to achieve different tasks in Emacs is not new. Even when it comes to adjusting the font size, there are key combinations that you can use to increase the font size in Emacs. We use the following buffer that contains three lines of text: To increase the font size, press “C-x c-+”. The shortcuts mean that you press the “Ctrl” key, then x, release the x, and press “+” to increase the font size gradually until you get a comfortable font size that gives you the best visibility. Using this key combination only affects the current buffer, and the changes in the font size are temporary for the buffer. The following is an example on how we increase the font size for our buffer: After increasing the font size, you may also want to decrease it as a way of having control over the text size. We use the same key combination for that, but instead of pressing “+”, we press “-” until we obtain the desired font size. Use the “C-x C–” keys. Notice how, as you keep pressing the “C–“, the font size keeps reducing even below the default font size. To return to the default font size, press the “C-x C-0”. The buffer will use the default font size, the global font size for your Emacs. Method 2: Adjusting for the Current Buffer with Command Emacs offers the “text-scale-adjust” command that you can use to increase the font size for the current buffer interactively. To use this option, open your Emacs on any buffer where you want to increase the font size. Next, press the “M-x”, the “Alt + x” keyboard key, and then type “text-scale-adjust”. Once you press the RET/Enter key, you will get an output that shows how to adjust the text size. You can use “+” to increase, “–” to decrease, or 0 to restore the font size. For our case, we want to increase the font size. In that case, press the “Ctrl” and “+” keys together and keep pressing the “+” key to increase the font size interactively. While pressing the “+” key, ensure that you are still holding the “Ctrl” key. If you want to decrease the font size, add the same “text-scale-adjust” command and press “Ctrl” and “–” to decrease the font size. Keep pressing the “–” until you have your preferred font size. You can also quickly restore the font size by pressing “Ctrl + 0” when running the “text-scale-adjust” command. Method 3: Permanent Solution The last method to increase the font size in Emacs is setting the preferred font size in your Emacs configuration file. Locate the configuration file. It is either the “~/.emacs” or “~/.emacs.d/init.el”. Next, add the following statement: (set-face-attribute ‘default nil :height 120) The given statement sets your font size to 12 pt. Feel free to adjust it depending on how you see it best. Lastly, save the configuration file and restart Emacs. With that, Emacs will increase your font size based on the attributes that you specified in the configuration file. Conclusion Emacs allows its users to adjust the font size for the global buffers or their current buffer. This guide provided three methods that you can use to increase the font size in Emacs on Linux. Try each method, see which works best for your needs, and stick to it. View the full article
  • Forum Statistics

    67.4k
    Total Topics
    65.3k
    Total Posts
×
×
  • Create New...