Text Editor
What is a text editor?
A text editor is a software application used for creating, editing, and manipulating plain text files. Unlike word processors, which are designed for formatting and styling documents, text editors focus on working with the content of the text itself, without adding complex formatting, fonts, or graphics. Text editors are commonly used by programmers, writers, system administrators, and anyone who needs to work with text-based files, configuration files, code, scripts, and more.
Text editors come in various forms, including graphical user interface (GUI) editors and terminal-based editors. Here are a few key characteristics and features of text editors:
-
Plain Text Handling: Text editors work with plain text files, which means they don't add any formatting beyond line breaks and characters. This makes them suitable for editing code, configuration files, logs, and other text-based content.
-
Syntax Highlighting: Many text editors provide syntax highlighting, which colorizes different parts of the code based on their syntax. This makes it easier to read and understand code by visually differentiating keywords, variables, comments, and other elements.
-
Keyboard-Centric Interface: Text editors are typically designed to be operated efficiently using keyboard shortcuts and commands, minimizing the need for mouse interaction. This can speed up the editing process, especially for tasks that involve rapid navigation and manipulation of text.
-
Customizability: Text editors often offer customization options, allowing users to adjust settings, keybindings, and appearance to match their preferences and workflow.
-
Search and Replace: Text editors provide tools for searching for specific text strings within a file and replacing them with other strings. This is crucial for tasks such as code refactoring or making changes across multiple lines.
-
Regular Expressions: Some advanced text editors support regular expressions, which are powerful patterns used for searching and manipulating text based on complex criteria.
-
Multiple Tabs and Split Views: Many text editors allow you to work on multiple files simultaneously by using tabs or split views, which can be useful when comparing or referencing different files.
-
Extensibility: Some text editors support plugins or extensions, which add extra functionality beyond the core features. These can include code linting, version control integration, project management, and more.
-
Line Numbering: Text editors often display line numbers, making it easier to reference specific lines in a file.
Popular text editors include:
- Notepad++: A graphical text editor for Windows, known for its syntax highlighting and extensibility.
- Sublime Text: A cross-platform text editor with a focus on speed, flexibility, and powerful search and navigation features.
- Visual Studio Code (VSCode): A highly customizable code editor developed by Microsoft, widely used for programming with a rich selection of extensions.
- Atom: A free and open-source text editor developed by GitHub, known for its user-friendly interface and extensive customization options.
- Vim: A terminal-based text editor with a unique modal editing system that emphasizes efficiency and speed, often favored by experienced users.
Overall, text editors are essential tools for working with plain text files, and the choice of text editor depends on factors such as your specific needs, workflow preferences, and the type of content you're working with.
However, we strongly encourage that all engineers learn how to use VIM.
Why VIM?
Vim is often recommended as a tool for several compelling reasons that make it stand out among text editors. Here's why Vim is frequently recommended:
-
Efficiency and Speed: Vim's modal editing and keyboard-centric design allow you to perform tasks more efficiently once you're familiar with its commands. This can lead to faster coding and text editing workflows compared to traditional mouse-driven editors.
-
Minimalistic Interface: Vim's interface is lightweight and doesn't require a graphical user interface (GUI). It operates directly in the terminal, which makes it ideal for remote development, server administration, and situations where a GUI might not be available.
-
Powerful Text Manipulation: Vim provides a wide range of text manipulation commands, search functionalities, and support for regular expressions. This makes it an excellent choice for developers who frequently work with code refactoring, data processing, and other text-related tasks.
-
Customizability: Vim can be customized extensively to match your coding style and preferences. You can configure key mappings, install plugins, and customize various settings to create a personalized and efficient editing environment.
-
Portability: Vim is available on virtually all major operating systems and platforms, ensuring that you can use it consistently across different environments. This makes it a reliable choice for developers who work on various systems.
-
Learning Investment: While Vim has a learning curve, the skills you acquire by learning its commands and modal editing philosophy are transferable and can benefit you throughout your career. Once you've mastered Vim, your productivity can increase significantly.
-
Community and Resources: Vim has a dedicated and active community that produces extensive documentation, tutorials, plugins, and solutions to common problems. This support network can help you learn and make the most of Vim's features.
-
Focus on Mindful Editing: Vim's modal nature encourages a mindful approach to editing. By separating different modes for navigation, editing, and more, you're less likely to make accidental changes and more likely to review your work thoroughly.
-
Available Everywhere: Vim is pre-installed on many Unix-like systems, so you're likely to encounter it in various professional settings. Knowing how to use Vim can be advantageous when working on servers or collaborating with other developers.
-
Coding Style and Refactoring: Vim's text manipulation capabilities, combined with plugins and syntax highlighting, support various coding styles and make code refactoring more manageable and efficient.
-
Career Advancement: Proficiency in Vim can set you apart in job applications and technical interviews, especially in fields like software development and system administration where command-line skills are valued.
-
Long-Term Skill Development: Once you've invested time in learning Vim, your expertise doesn't become obsolete quickly. Vim's core principles have remained consistent over the years, ensuring that your skills will remain relevant.
While Vim might not be the best fit for every individual or situation, its unique features and benefits make it a recommended tool for those who are open to learning a new way of editing text and who value efficiency, customization, and a powerful set of text manipulation tools.
Vim (Text editor)
Vim is a highly configurable text editor built to make creating and changing any kind of text very efficient. It is included as "vi" with most UNIX systems and with Apple OS X.
Installing Vim
sudo apt install vim
How to exit Vim
Press esc multiple times to get back into normal mode and then type :wq and press enter.
Using Vim
You can learn how to use Vim via Openvim.
Modes
- Normal mode: Press
esc - Insert mode: Press
i - Visual mode: Press
v
Navigating
- Left/right/up/down: Press
h,l,k, andjrespectively. - Go top/ Go bottom: Press
ggandshift+grespectively. - Go to the start/end of the line: Press
0and$respectively.
Text editing
- Inserting: Press
i. - Deleting a character: Press
x. - Deleting a line: Press
dd.
Visual mode
- Select character(s): Press
v. - Select line(s): Press
Shift+v. - Select block: Press
Ctrl+v.
Yanking (Copying)
- Yank and paste
- To yank, get into SELECT mode and highlight the text and then press
yto yank. - To paste, simply press
p.
- To yank, get into SELECT mode and highlight the text and then press
Repeating
- Repeating the last operation: Press
..
Indenting
- Indenting right: Press
>>. - Indenting left: Press
<<.
Search and replace
- Searching: Press
/and type the pattern. - Replacing: Type
:s/{pattern-to-replace}/{what-to-replace}
Vim Customization
To configure Vim, create a .vimrc file at $HOME directory.
touch ~/.vimrc
Vim executes .vimrc when the program starts. Any configuration saved in .vimrc will always be executed.
Some basic settings
" Enable line numbers
set number
" Enable syntax highlighting
syntax on
" Set shift width to 4 spaces.
set shiftwidth=4
" Set tab width to 4 columns.
set tabstop=4
" Use space characters instead of tabs.
set expandtab
" Do not save backup files.
set nobackup
" Do not let cursor scroll below or above N number of lines when scrolling.
set scrolloff=10
" Do not wrap lines. Allow long lines to extend as far as the line goes.
set nowrap
" While searching though a file incrementally highlight matching characters as you type.
set incsearch
" Ignore capital letters during search.
set ignorecase
" Override the ignorecase option if searching for capital letters.
" This will allow you to search specifically for capital letters.
set smartcase
" Show partial command you type in the last line of the screen.
set showcmd
" Show the mode you are on the last line.
set showmode
" Show matching words during a search.
set showmatch
" Use highlighting when doing a search.
set hlsearch
" Set the commands to save in history default number is 20.
set history=1000
VimPlug as a Vim plugin manager
Installation
Install VimPlug by visiting here.
For Unix system, executes
curl -fLo ~/.vim/autoload/plug.vim --create-dirs \
https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
Usage
Add a vim-plug section to .vimrc.
call plug#begin()
" Put your plugins here
Plug 'junegunn/vim-easy-align'
call plug#end()
After you've places your plugins in .vimrc, reload Vim and :PlugInstall to install plugins.
reference: Awesome plugins could be found at https://vimawesome.com/.
VSCode and Vim
Vim surely does have it strength but a lot of you may be more familiar with VSCode. Since VSCode also has its strength and you don't want to lose it by switching to Vim.
Luckily, there is a Vim emulation plugin in VSCode. It can be downloded using the following info.
Name: Vim
Id: vscodevim.vim
Description: Vim emulation for Visual Studio Code
Version: 1.22.2
Publisher: vscodevim
VS Marketplace Link: https://marketplace.visualstudio.com/items?itemName=vscodevim.vim
Neovim
(Neovim)[https://neovim.io/] is an improved version of Vim. Neovim is a forked, more feature-rich version of the Vim text editor developed to make Vim simpler, flexible, and easier to maintain.
Neovim can be installed by
sudo apt install neovim
To start a Neovim session, run
nvim
Nano (Text editor)
Nano is another easy to use text editor. It's not as powerful as Vim or VSCode but if you're looking for an easy-to-go text editor then this is it.