Code

How to Code Quickly and Efficiently: Emacs, Vim, and Other Editors for Haskell Developers

How to Code Quickly and Efficiently: Emacs, Vim, and Other Editors for Haskell Developers

Learn: Front-end Developer Profession

Learn More

Dmitry Kovanikov

An expert in his field has deep knowledge and practical experience, which allows him to effectively solve problems and offer valuable solutions. His qualifications are confirmed by many years of work and successful projects, making him an authority in this field. The expert constantly monitors trends and new developments, which allows him to stay at the forefront and offer relevant and innovative approaches. His professional skills and analytical thinking contribute to achieving high results and satisfying client needs.

A Haskell developer at a London bank, passionate about functional programming, actively shares his experience at conferences. For several years, he taught Haskell at ITMO University. Together with a friend, he founded the organization Kowainik, where he supports open-source projects, mentors beginners, maintains a blog, and teaches a Haskell course. His contributions to the developer community promote knowledge of Haskell and functional programming.

Links are an essential element of the web world. They allow users to move from one page to another, providing navigation and access to information. Websites use internal and external links to improve the structure of their content and increase its visibility in search engines. Internal links help distribute the weight of pages within a site, while external links can increase authority if they point to reliable resources. Optimizing links, both in anchor text and in their placement, plays a key role in SEO. Properly configured links improve user experience and contribute to higher rankings in search results.

I have been programming for over six years, the last five of which have been working with Haskell. I am currently a backend developer at Standard Chartered Bank in London. My primary role is supporting a service that provides a high-speed cache over a slow database. My experience with Haskell allows me to effectively solve optimization and performance improvement problems, which are key aspects in the banking sector.

Before moving to banking, I worked for a healthcare company, where I developed an application for people with type 2 diabetes. My work included architecture design, backend development, integration with various APIs, and the implementation of AI models. Previously, I also had experience in the blockchain field.

What is Vim good for and what tasks is it suitable for?

I first encountered Vim at university during a course on operating systems. The professor who taught the class emphasized the importance of working with this editor, stating: "You should write C code in Vim." He also required that all homework be done in this text editor, so in addition to learning a programming language, we also had to master a new coding tool. This introduction to Vim was a crucial step in my learning process and significantly increased my programming productivity.

Vim has a steep learning curve, making learning this text editor challenging. Initially, everything feels unfamiliar, and writing code is difficult. Even simple tasks require a significant investment of time. However, over time, as users master the basic commands and functions, they begin to see the benefits. The increase in productivity becomes noticeable, and working in Vim becomes more efficient. This editor, while challenging to learn, ultimately opens up new horizons in programming and code editing.

The text editor often proves indispensable. Thanks to it, I can quickly make changes to files without having to launch the full IDE. This significantly saves time and simplifies my workflow, especially when I need to make small edits or review code. Text editors offer convenience and speed, making them an ideal choice for quickly working with files.

One of the key advantages of the Vim editor is the ability to edit files on remote servers via SSH. This feature allows developers to easily make changes to code without installing additional development environments, such as IntelliJ IDEA, on the server. Thus, Vim provides the flexibility and convenience of working with files directly on the server.

In Vim, I mainly edit individual files. Although there is a developed ecosystem that allows you to create projects and add useful plugins, I have not delved into this functionality. My primary use for Vim is for fast and efficient text processing, while for working on projects, I prefer VS Code.

Vim has its own scripting language, known as VimL or Vim script. With it, users can create programs and perform calculations directly in the text editor, as well as customize integrated development environments and create individual configurations. Unlike other IDEs where features are activated with simple checkboxes in the settings, Vim offers complete programmatic customization, allowing each user to tailor the editor to their unique needs and preferences.

Using Vim in the terminal to edit files is a convenient and efficient way to work. I can quickly open the file I need directly from the terminal, navigate to the desired fragment of text, and make changes. After editing, I save the file and close it, which allows me to continue compiling without unnecessary steps. This process saves time and simplifies working with text documents.

I'll demonstrate some of the Vim features using VS Code, as it handles multi-cursor editing more efficiently. In this editor, I can switch to overwrite mode, which allows me to make changes without affecting other parts of the code. For example, if I need to change one import to qualified and leave another unchanged, I can do it with just a few keyboard shortcuts.

In case I need to add the «user» prefix to all fields of the data types, due to the peculiarities of the Haskell language, I must assign unique names to the fields. This is done to prevent naming conflicts and ensure the correct operation of the program. This approach helps keep the code clear and organized, which is especially important when developing in Haskell. Unique field names make the data structure more understandable and simplify interaction with them during programming.

To change the case of the first letters in the selected text, I use the keyboard shortcut Ctrl + V to paste the text and turn on block selection mode. Then I select the beginning of the text and press the tilde (~), which changes the case. After that, I add the «user» prefix by simply dragging it with the cursor. To return to editing mode after block selection, I use the Shift + I shortcut. This is an effective way to work with text, allowing me to quickly make changes and organize information.

Deleting functions in a text editor can be done using simple commands. For example, to quickly delete the current line, just press the dd key combination. Also, to combine multiple lines into one, use the combination Shift + j or just J. These standard functions greatly simplify working with text and help increase productivity.

There is a useful function that allows you to use a hotkey to delete everything between the opening and closing brackets. This function supports working with round, square, and curly brackets, and also allows you to quickly delete the text inside these brackets. Using hotkeys significantly speeds up the editing process and simplifies working with text.

The key combination is also useful for editing lambda functions, or anonymous functions. You can select the desired fragment and enter edit mode, then make the necessary changes and correct the text right away. This speeds up the editing process and makes it more convenient.

If you need to rename a function in Vim, you can use the useful s command. This command deletes one character and switches the editor to edit mode. For example, to change the name strictSum to veryStrictSum, just use this function.

Sometimes comments in code can become too long, which requires breaking them into paragraphs for better readability. In the Vim editor, there is a convenient keyboard shortcut for this task: g + q + l, which automatically wraps text to new lines. Although it requires three keystrokes to use this function, I memorized the combination and actively use it in my work. It significantly simplifies the editing process and improves the structure of comments in the code.

An example of creating a list of programming languages ​​can be implemented using a global variable. To do this, you need to copy the list of languages ​​and separate them with commas. However, at this stage, these are just values. To convert them to strings, you need to surround each value with quotation marks. To do this, select all the list items, add an opening quotation mark at the beginning, and then move to the end of the line and add a closing quotation mark. This approach will ensure the correct formatting of the list of programming languages.

The process occurs in the following order:

The keyboard shortcut Ctrl + V activates block text selection mode. This is a convenient tool for working with text that significantly simplifies the editing and formatting process. In this mode, users can select and copy blocks of text without having to select each line individually. Block selection mode is useful for working with large amounts of information, making it indispensable for editors and other professionals working with text content. Use Ctrl + V for efficient editing and improved workflow.

In Vim, the j key is used to move the cursor down. Instead of the standard navigation arrows, Vim provides navigation using the h, j, k, and l keys, allowing for more efficient text management. Using these keys promotes quick and convenient editing, making Vim a popular choice among programmers and text editors.

Copying selected text is done using the Ctrl + C key combination on Windows or Command + C on Mac. This feature allows you to quickly and conveniently save information for later use. Copying selected text is especially useful when working with documents, web pages, and other text resources, as it allows you to avoid retyping data and saves time.

The p tag in HTML is used to paste the last copied value. This element allows you to easily integrate text into a document, ensuring proper formatting and structure. Using the p tag improves the readability and comprehension of content, which has a positive impact on SEO. Proper use of tags like p is important for optimizing web pages and improving their ranking in search engines.

The keyboard shortcut Ctrl + V is used to insert text or objects into a document. However, if you want to select the beginning of all lines, you need to use other keyboard shortcuts or methods. To select the beginning of lines in a text editor, you typically use shortcuts such as Shift + Home, which allows you to select text from the cursor to the beginning of the line. Understanding hotkeys and their functionality greatly simplifies editing and working with text. Use effective methods to increase your productivity when working with documents.

Shift + i (or simply i) - activates insert mode in a text editor. In this mode, you can add new text to existing text without deleting what you've already written. This is a convenient editing method that allows you to preserve the structure of the original text and add new ideas or corrections. Using the Shift + i keyboard shortcut significantly speeds up the editing process and simplifies working with documentation.

I type the necessary text.

The r[ command is used to replace the first comma in the text with an opening square bracket. This moves the cursor to the first comma, and replaces the character under the cursor with «[«. This function can be useful for quickly editing text data and formatting it as needed.

I move the cursor to the end of the block and add a closing square bracket.

The Ctrl + V keyboard shortcut quickly switches to block selection mode. This mode is especially useful for editing text, as it allows you to select and edit text blocks more efficiently. Using this combination simplifies the process of working with text, allowing the user to focus on editing without having to constantly switch between modes. Using Ctrl + V in block selection mode increases productivity and improves the quality of edited content. Shift + i — activates insert mode. Adds an opening quotation mark. The Ctrl + V keyboard shortcut activates block selection mode, allowing you to select all words in the text. This functionality simplifies the editing and formatting process, especially when working with large amounts of information. Using block selection promotes more efficient text management, which is important for optimizing your workflow. Selecting text from the cursor to the end of the line using the $ key is a convenient tool for quick editing. This feature allows users to effectively manage text, facilitating the editing process and improving productivity. Using this command, you can quickly select the desired fragment of text for further actions, such as copying or deleting. Knowing how to work with such commands significantly simplifies interaction with text editors and increases the overall efficiency of working with documents. Shift + i — activates insert mode in a text editor. This keyboard shortcut allows users to quickly begin typing new text, adding it to existing content. Insert mode is an essential feature for efficient text editing and formatting, as it allows for continuous addition of information without having to delete what you've already written. Using the Shift + i keyboard shortcut significantly speeds up the editing process and improves overall productivity when working with text.

Adding a closing quotation mark.

While this may seem complicated, I use these shortcuts regularly and do it automatically.

When you first encounter a new process, it may seem unusual and unfamiliar. Inevitably, even the simplest actions require significant effort at first. However, over time, you will adapt, and many actions will begin to occur automatically. The creators of Vim paid special attention to ergonomics and keyboard shortcuts, which greatly simplifies the work and increases user efficiency. Once you master the basic commands, you can significantly speed up your workflow and focus on more complex tasks.

Why Emacs is an Indispensable Code Editor

I started using Emacs at my first job, where I was programming in Haskell. The main reason I chose this text editor was the Org Mode plugin, which made it much easier to track the time spent on various tasks. Thanks to its functionality, I was able to manage my time more effectively and improve my productivity.

I no longer wasted time opening tasks, tracking, and counting hours spent. With a few hotkeys in the plugin, I could easily manage my time, and at the end of the month, it automatically generated a report. This was the main reason I decided to try Emacs.

I didn't think it was practical to use Emacs solely for time tracking while programming in a different environment. So, I delved deeper into the settings and installed a Haskell plugin. Since then, I've primarily written code in Emacs, which has significantly simplified my workflow and increased my productivity.

One thing I find frustrating about Emacs is the need to constantly configure the development environment for my projects. This process differs from working with traditional IDEs, which provide the user with ready-made functionality. Emacs has its advantages and disadvantages. On the one hand, customization allows you to adapt the editor to your individual needs, but on the other, it requires additional time for configuration and refinement.

I like VS Code and IntelliJ IDEA because they provide all the necessary tools and features out of the box. These development environments are easy to learn, which is especially important for beginners. With an intuitive interface and a wealth of built-in features, users can quickly start working on projects without any unnecessary configuration.

Emacs requires some effort to set up, but the result is a fully customized environment that suits your needs. You can add custom features and optimize your workflows. However, I prefer to have tools that work effectively out of the box, without the need for extensive customization.

After using Emacs, I switched to Spacemacs, which is a separate ecosystem built on top of Emacs. Spacemacs offers improved settings, a simplified plugin installation process, and many other interesting features. It works great out of the box: just add a single line to support a new language, such as YAML or Rust, and you have instant access to its functionality. Spacemacs also has a more attractive visual design, which makes it even more enjoyable to use.

This editor does have its drawbacks: its performance degrades over time, and using it on macOS is often fraught with problems such as crashes and other issues. As a result, I returned to classic Emacs, which provides stable operation and reliability.

In my opinion, migration and the package ecosystem in Emacs are organized more simply than in Vim. In Emacs, I found the process of setting up plugins, writing my own scripts, and understanding the system as a whole more convenient. This makes Emacs a more attractive choice for developers who are looking for flexibility and ease of customization of their working environment.

Emacs and Spacemacs use Emacs Lisp, also known as elisp, to set up and configure the development environment. Emacs Lisp is a dialect of the Lisp language that provides flexibility and powerful customization options. In contrast, the VimL language seems less convenient and intuitive for users. Emacs provides extensive customization options, making it a popular choice among developers looking to create a personalized working environment.

Keyboard shortcuts in Emacs may seem less convenient compared to Vim. Frequent use of the Ctrl key can cause discomfort in the pinky finger. Therefore, many users prefer to use the familiar Vim shortcuts to improve comfort and increase productivity.

In Emacs, I prefer to use Vim via the Evil plugin because I like its editing concept. Hotkeys, view modes, and insert modes make working more convenient and efficient. This rule also applies to other IDEs: I always install the Vim plugin to implement familiar keyboard shortcuts. This allows me to maintain productivity and comfort while working with code.

Emacs has become the ideal development environment for me thanks to its customization and the features it offers. I have adapted it to my workflow, and when switching to other IDEs, I always feel a lack of certain features. At the same time, some options in other tools seem redundant and interfere with my concentration. That's why I continue to use Emacs as my primary development tool.

The Lisp language used for writing plugins causes me some inconvenience. I'm particularly confused by the dynamic typing. When I open a plugin and try to understand how it works, I have a hard time understanding how certain functions or hotkeys work. The lack of ability to view the data type makes it difficult to understand what values ​​can be passed into functions—whether a boolean flag or a string. This leads to code that may not work correctly, since any data can be passed into it, including numbers and strings.

Understanding a plugin's modes, hooks, and hotkeys requires reading the documentation and, in some cases, the source code. This can be inconvenient, but it makes it easy to make changes. I can copy a piece of code, make the necessary changes, and it will work. While I'm not a fan of Lisp, I have to admit its flexibility in these situations.

Emacs has a feature that allows you to automatically restore previous sessions by opening the same files you were working on. This feature isn't new, but it's not often found in other IDEs. When I close Emacs and then launch it again, all my open files are back in the same state I left them in. This is especially handy if I haven't worked on a project for a week—I just open Emacs and can pick up where I last left off. This feature greatly simplifies my work and increases my productivity, allowing me to focus on my code without wasting time restoring my workflow.

I especially like the editing capabilities of Emacs, including the buffer system. I can split the screen, open multiple files at once, and conveniently switch between buffers left and right, without having to cycle through them. This greatly simplifies my work and increases productivity.

I miss the high ergonomics of Emacs in other IDEs. This development environment offers convenient split-screen capabilities, which makes multitasking much easier. Filename autocompletion allows for quick and efficient switching between documents, which significantly speeds up the programming process and improves overall productivity. Emacs truly creates a comfortable working environment for developers, making it an indispensable tool in their arsenal.

I'm used to Vim having view and edit modes. In insert mode, I write code and then press Esc to return to normal mode. In Emacs, I quickly set up automatic saving of the currently edited file when I exit edit mode. This saves me from having to periodically save files manually. This approach significantly simplifies my work and allows me to focus on coding without being distracted by routine operations.

When I save a file in the code editor, autoformatting automatically runs, removing extra spaces at the end of lines and performing other actions. This is significantly faster and more convenient than saving the file after every change, using a timeout, or manually. I spent a long time trying to set up similar features in VS Code, and eventually found a solution on Stack Overflow.

I don't have any special settings for Emacs—I'm not a huge fan of this editor and don't obsess over details. For example, one developer created a plugin for Telegram that allows you to use the messenger directly within Emacs. This plugin even supports video messages, allowing you to simultaneously code and chat in one window.

This is what the Telegram plugin for Emacs looks like. Screenshot: GitHub

I plan to work on projects in Emacs. To do this, I open the file search, and a line appears at the bottom of the screen where I can select the desired file, for example, a file with settings. If I need to make changes, I continue to use Vim hotkeys, which makes the editing process convenient and efficient. Emacs and Vim can combine beautifully, allowing the user to work on projects more productively.

I want to study the "license" data type, which belongs to the licenses module. To do this, I split the screen and open the corresponding module. Then I turn my attention to the section on the implementation of the "file tree" data type.

I can easily switch between editors using hotkeys, the mouse, or by changing the active window. This allows me to quickly revert to previous versions of my work and improve my editing efficiency.

My tool offers basic settings, such as highlighting changes. Deleted lines are highlighted with red cubes, and changed lines are orange. The bottom of the window displays information about the current line and column, as well as the name of the open file.

Haskell stands out for its conciseness, which makes it convenient for editing. Basic features, such as syntax highlighting, are sufficient for working with this programming language. This allows you to focus on the programming logic while minimizing distractions.

Who Should Learn Vim and Emacs

When learning a new development environment (IDE), it is difficult to immediately determine whether it is right for you. Unlike tools such as Notion, which you can quickly test and evaluate the convenience of documentation, a new IDE requires time to adapt. After the first day of work, many users may say: "I don’t like it." This is because you first need to set up your workflow and get used to the interface and functionality. Only then can you objectively assess how well the IDE meets your requirements and preferences.

I recommend learning Vim, as it is a versatile tool and an entire paradigm for text editing. If your development environment supports the Vim plugin, this will be enough to increase your productivity. You will be able to edit files quickly and efficiently, especially on servers where it is not possible to install a full-fledged IDE. Mastering Vim will significantly improve your text-processing skills and increase the efficiency of your tasks.

Exploring different approaches to programming helps broaden your horizons and improve your visual acuity. One such approach is using the Vim text editor. It offers a unique work structure, dividing the process into two modes: one for writing code and one for editing. This allows you to efficiently switch between files, move and delete blocks of code, significantly speeding up your workflow. By mastering Vim, developers can not only improve their editing skills but also improve their productivity and the usability of their code.

Using Vim can seem daunting at first, but the editor itself features a built-in twenty-minute onboarding guide to help you get up to speed quickly. Additionally, numerous guides and tutorials are available online. Emacs, on the other hand, is a more comprehensive environment, closer to a full-fledged IDE, making it more challenging to learn. However, Emacs is worth learning, especially if you work with a variety of programming languages, including less common ones that lack powerful integrated development environments (IDEs). Mastering these tools will significantly increase your productivity and simplify the programming process.

If your programming language lacks a powerful integrated development environment (IDE), don't despair—there's likely an Emacs plugin. This is because developing plugins for Emacs is significantly easier than for IDEs like IntelliJ IDEA. If you have programming skills, creating a high-quality plugin for Emacs will take less time and effort. This approach allows you to extend the editor's functionality and tailor it to your needs, making development more efficient. Learning Emacs opens new horizons for programmers, especially those interested in languages ​​with dependent types, such as Idris or Agda. These languages ​​offer a unique programming paradigm known as Type-Driven Development. This approach includes techniques such as case splitting and Hole-Driven Development. The idea is that you can specify a function type, and then, by pressing a specific hotkey, get an automatically generated implementation of the function. This significantly simplifies the development process and improves code quality. Emacs, as a powerful editor, is ideal for working with such languages, allowing you to effectively manage types and automate routine programming tasks.

Emacs provides unique capabilities for working with programming languages, especially in the context of studying type theory and dependent types. By mastering just four keyboard shortcuts, you'll gain access to a wealth of tools that will greatly facilitate your learning process. Using Emacs, you can focus on the theoretical aspects of languages ​​and effectively apply them in practice. This decision will make your learning more productive and less burdensome. You definitely won't regret choosing Emacs for diving into programming and learning type theory.

Sublime Text, IntelliJ IDEA, VS Code, and Atom

I tested numerous IDEs and code editors, starting with Sublime Text. This editor is a powerful text editor, but it had issues with Haskell support due to an ineffective plugin. While Sublime Text offers basic features like syntax highlighting and autocompletion, these are not sufficient for a full-fledged experience. Frequent crashes and the difficulty in adding new functionality were also serious drawbacks. Perhaps the situation with this editor has improved now, but at the time it did not live up to my expectations.

After that, I started using Atom. This application was quite popular in its time, but now few people talk about it. However, Atom had its drawbacks, especially in terms of Haskell support.

I used IntelliJ IDEA and I can say that it is an excellent IDE. If you are satisfied with its functionality, there is no need to look for alternatives. However, it is worth noting that IntelliJ IDEA only has a few plugins for Haskell programming. The most active of them is maintained by just one developer. This plugin used to be slow, but over time its performance has improved. However, I have not used it for a long time.

At work, I do programming in VS Code. For the last year and a half, the Haskell plugin has been actively developed, thanks to which the user experience for Haskell developers has significantly improved. The established community of volunteers, as well as the ongoing involvement of Meta staff, contribute to the project's effective development. This plugin makes VS Code a powerful tool for Haskell developers, providing the convenience and functionality needed for effective work.

Support for multiple programming languages ​​in Visual Studio Code is provided by the Language Server Protocol (LSP). This protocol allows developers to create their own Language Servers for various languages, as well as develop plugins for IDE integration. A ready-made Language Server for Haskell is available on GitHub, simplifying the development process and improving the editor's functionality for Haskell users.

JetBrains recently introduced the lightweight Fleet editor. Although it does not yet support Haskell, integration is possible via LSP. To do this, you need to create a plugin that connects the Haskell language server to the editor. This will enable full-fledged work with Haskell code in the Fleet environment, which will significantly simplify the development process for programmers working with this language.

Useful resources for those learning Emacs and Vim

I recommend using the following materials.

Reading is an important aspect of our lives, contributing to the development of intelligence and broadening our horizons. It not only enriches our vocabulary but also helps form critical thinking. Books, articles, and other sources of information provide us with the opportunity to immerse ourselves in new ideas and concepts. Regular reading helps improve concentration and memory, and promotes emotional development. In the digital age, access to information has become easier, which makes reading even more accessible. Maintain the habit of reading, and you will notice how it positively affects your personal and professional growth.

  • Must read. 5 Fresh Articles on Using Emacs in Development
  • Epic AI Failures: Extortion, 🙅 Dollhouses, Unparliamentary Expressions
  • IT Product Support, Part 1: Chats, Employee Roles, Bots, and Relations with Development

Profession: Frontend Developer

Thanks to frontend developers, we leave likes and comments, add products to carts, and quickly navigate online maps. In this course, you'll learn to create web service interfaces using programming languages ​​and additional technologies. You'll be able to develop task schedulers, messengers, and online stores.

Find out more