This story on HackerNoon has a decentralized backup on Sia.
Transaction ID: jSd__k9cMW5M-QbBIaoQBDrcMAGyqdrr4qBDPQpk7_Y
Cover

Vim - 2 Commands for Text Modification

Written by @artwalker | Published on 2024/1/4

TL;DR
Learned Vim essentials: append ('a'), change word ('cw'), replace ('r'/'R'). Efficiently edit text, navigate, delete spaces, and save changes ('wq').

Vim Commands for Text Modification

In the realm of Vim, mastering essential commands like append, change word, and replace can significantly enhance your text editing prowess.

Append (a)

Appending text using `a` places you in insert mode, allowing for seamless additions after the cursor position. For instance, adding a new field in a file becomes intuitive:

# Go to the end of the line

$ (to reach the end of a line)

# Use 'a' to append text

a

At the beginning of the first line

Type '$' to the end of the first line

Use a to append content

Change Word (cw) and Replace (r/R)

- cw: Alter a word or overwrite text until the next punctuation character or space. Example: Correcting a word, say 'Hackernoon' to 'World' involves using `cw` and editing the text.

- r/R: Replace one character (`r`) or overwrite text (`R`). Typing errors or changing your mind about the edit becomes effortless:

At the beginning of the word "World"

# Change 'Hackernoon' to 'World' (with a typo)

cw World

Enter  'cw'

Type  Hackernoon to there

# Correct the typo using 'r' (replaces one character)

re

Wrong character

Type 'r'

Type o

# Overwrite the text with 'R'

R Discover Anything

Type 'R'

Type the text then 'ESC'

Refining Text and Streamlining Edits

Vim offers shortcuts for effective text refinement:

- Navigate: Use arrow keys for navigation and `$` to reach the end of a line.

- Deleting Spaces: Trim trailing spaces by maneuvering with arrow keys and using D to delete from the cursor position to the end of the line.

Many '.'

Type 'D' to Delete the '.'

Wrapping Up Modifications and Writing Files

Once edits are complete, ensure to save changes:

# Save changes and exit

:wq (write and quit)

Save and quit

Conclusion

Mastering these foundational Vim commands empowers efficient text editing and streamlines the process of modifying files. With practice, these commands become second nature, boosting productivity and precision in your editing endeavors.

[story continues]


Written by
@artwalker
Passionate about Crafting Intelligent OS & Pioneering TinyML Applications for Resource-Constrained Devices

Topics and
tags
vim-editor|vim|learning-vim|learn-to-code-vim|how-to-use-vim|vim-tips|how-to-modify-text-in-vim|vim-for-beginners
This story on HackerNoon has a decentralized backup on Sia.
Transaction ID: jSd__k9cMW5M-QbBIaoQBDrcMAGyqdrr4qBDPQpk7_Y