generated from mateusfg7/nextjs-setup
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(content/til): add 2024_01_17-find_and_replace_vim
- Loading branch information
Showing
1 changed file
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
--- | ||
title: 'Find-And-Replace Vim' | ||
description: 'How to fast replace all mathing strings on vim' | ||
date: '2024-01-17' | ||
tags: [vim,editor,ide,cli] | ||
--- | ||
|
||
For base find-and-replace on vim, we can use the `:substituto` (`:s`) command. | ||
|
||
The general form of the substitute command is as follow: | ||
``` | ||
:[range]s/{pattern}/{string}/[flags] [count] | ||
``` | ||
|
||
The command search each line in `[range]` for a `{pattern}`, and replaces it with a `{string}`. | ||
`[count]` is a positive integer that multiplies the command. | ||
|
||
If no `[range]` and `[count]` are given, only the pattern found in the current line is replaced. | ||
The current line is the line where the cursor is placed. | ||
|
||
For example, to search for the first occurrences of the string `"foo"` in the current line, and replace it with `"bar"`, you should use: | ||
``` | ||
:s/foo/bar | ||
``` | ||
|
||
To replace all occurrences of the search pattern in the current line, add the `g` flag: | ||
``` | ||
:s/foo/bar/g | ||
``` | ||
|
||
If you want to search and replace the pattern in the intire file, use the percentage character `%` as a range. | ||
This caracter indicates a range from the first to the last line of the file: | ||
``` | ||
:%s/foo/bar/g | ||
``` | ||
|
||
We can also use `|` as parameter separator: | ||
``` | ||
:s|foo|bar | ||
``` | ||
|
||
To show confirmation for each substituition, use `c` flag: | ||
``` | ||
:s/foo/bar/gc | ||
``` | ||
|
||
To ignore case sensitivity, use `i` flag: | ||
``` | ||
:s/foo/bar/gi | ||
``` | ||
|
||
> There is much more options, look at the **ref** link for more... | ||
**ref**: https://linuxize.com/post/vim-find-replace/ |
3cdfd4e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
mateusf-com – ./
mateusf.vercel.app
mfg-b.vercel.app
mateusf-com-mateusfg7.vercel.app
mateusf-com-git-main-mateusfg7.vercel.app
mateusf.com
www.mateusf.com