Vim find & replace (RT)
To find and replace one or more occurrences of a given pattern with a new string, use the s[ubstitute] command in vim.
The format of the s[ubstitute] command is:
代码:
:[rang]s[ubstitute] /{pattern}/{string}/{flags} [count]
This command means that for each line in [rang] replace a match of {pattern} with {string}. The {string} can be a literal string, or something special. When [rang] and [count] are omitted, replace in the current line only.When [count] is given, replace in [count] lines, starting with the last line in [rang]. When [rang] is omitted start in the current line.
There are many {flags} can be used, only a few of them are listed bellow:
[&] This flag must be the first one, Used to keep the flags from the previous substitute command
[c] Confirm each substitution. With this flag, you will be asked what to do:type ‘y’ to substitute the selected match, ‘l’ to substitute the match and then quit. ‘ n ‘ to skip the current match, ‘ a ‘ to substitute all the matches. <Esc> and ‘ q ‘ to quit substituting, CTRL-E to scroll the screen up, and CTRL-Y to scroll the screen down.
[g] Find and Replace all occurrences in the line. Without this argument, replacement occurs only for the first occurrence in each line.
[i] Ignore case for the pattern.
[I] Don’t ignore case for the pattern.
For more information, please refer to
代码:
:help substitute
The usage of [rang] can be find by
代码:
:help cmdline-rang
[$] The last line of the file
[.] The current line
[%] equal to 1, $, the entire file
Examples:
代码:
:%s/foo/bar/g
find each occurance of ‘foo’ and replace it with ‘bar’ without asking for confirmation
代码:
:%s/foo/bar/gc
find each occurance of ‘foo’ and replace it with ‘bar’ asking for confirmation first
代码:
:%s/<foo>/bar/gc
find (match exact word only) and replace each occurance of ‘foo’ with ‘bar’
代码:
:%s/foo/bar/gci
find (case insensitive) and replace each occurance of ‘foo’ with ‘bar’
代码:
:%s/foo/bar/gcI
find (case sensitive) and replace each occurance of ‘foo’ with ‘bar’
分享到:
相关推荐
VMware ESXI 6.5 & VMware vCenter 6.5 & VIM6.5 & VCSA6.5 本地版 完整安装手册 17个不同厂商 主流厂商的VMware ESXI 6.5安装镜像 以及密钥 3个VCSA6.5版本 3个vCenter6.5版本 以及密钥 3个VIM6.5版本 若干其它工具...
vim env
bash shell awk vim bash shell awk vim bash shell awk vim bash shell awk vim
space-vim, 精益&平均 spacemacs Vim 前言 | 运行截图 | 适用人群 | 开始使用 | 个性化 | 更新 | 默认安装 | 基础键位 | 使用建议目录简介特性为谁?安装失败先决条件Linux和 macOS一行安装程序Makefil
Ubuntu学习笔记\vi&vim vi&vim常用操作学习笔记 希望对字符向往者有帮助
VIM QUICK REFERENCE CARD Basic movement Insertion & replace ! insert mode
vim-航空公司主题 这是的官方主题库 安装 该插件遵循标准的运行时路径结构,因此可以与各种插件管理器一起安装: 插件管理器 安装... git clone https://github.com/vim-airline/vim-airline-themes ~/.vim/bundle...
VIM快捷键 VIM快捷键 VIM插件 VIM快捷键 VIM插件
ln -s ~ /.vim/vimrc ~ /.vimrc && cd ~ /.vim && git submodule update --init 哪个 无性系回购 符号链接vimrc 将我们所有的vim插件安装到捆绑包中,通过病原体将它们合并。 然后,要创建符号链接并添加到您的...
vim中文手册 vim中文手册 vim中文手册 vim中文手册 vim中文手册 vim中文手册 vim中文手册vim中文手册vim中文手册
VIM编辑器-head命令-trail命令-find命令-grep命令的介绍和说明。
add wintagexplorer.vim , echofunc.vim , vimrc
SwiftForVim 具有Swift功能的快速,类型安全的Vim插件! SwiftForVim将Swift编程语言集成到Vim中。Vim APIVim Vimscript <->迅捷从Swift调用Vim命令Vim. command ( " echo 'Hello World!' " ) 从Swift评估Vim...
Peter Jakobs 的 Vim 配置。 我的 vim 配置(从复制) 要安装,请执行以下操作: 清除你的~/.vimrc文件和~/.vim目录(如果你愿意,可以备份) git clone https://github.com/pjakobs/vim-config.git ~/.vim cd ...
cp molokai.vim /usr/share/vim/vim73/colors cp /etc/vim/vimrc /etc/vim/vimrc.bak cp vimrc /etc/vim/vimrc
讲述 vim 编辑器的几十个实用上手技巧
"source ~/.vim/bundle/unite.vim/conf.vim "neosnippet.vim source ~/.vim/bundle/neosnippet/conf.vim "vimshell.vim, vim中使用shell, 最好一款 source ~/.vim/bundle/vimshell/conf.vim "omnicppcomplete.vim...
vim配置 vim 配置 整理出来大家一起学习
Mastering Vim: Build a software development environment with Vim and Neovim By 作者: Ruslan Osipov ISBN-10 书号: 1789341094 ISBN-13 书号: 9781789341096 出版日期: 2018-11-30 pages 页数: (330) Vim is ...
vim自动提示等多种功能 先安装ctags 然后进入./vim文件中执行 sh vim_config_ctags-v2.0.sh 再进入./vimconfig中执行 解压缩压缩报 tar jxvf vimconfig.tar.bz2 然后执行 ./config.sh 脚本会自动更新 用户根目录下...