vim批量替換
阿新 • • 發佈:2017-09-02
uri pattern git vim編輯器 p s 模式 插入模式 多行 username (文章都是從別的地方摘抄並總結的,如有侵權,請聯系管理員)
:起始行號,結束行號s/^註釋符//g
- vim編輯器---批量註釋與反註釋
在使用vim編寫代碼的時候,經常需要用到批量註釋與反註釋一段代碼。下面簡要介紹其操作。
方法一 塊選擇模式
插入註釋:
用v進入virtual模式
用上下鍵選中需要註釋的行數
按CTL+v(win下面ctrl+q)進入列模式
按大些“I”進入插入模式,輸入註釋符“#”或者是"//",然後立刻按下ESC(兩下)
取消註釋:
Ctrl + v 進入塊選擇模式,選中你要刪除的行首的註釋符號,註意// 要選中兩個,選好之後按d即可刪除註釋
方法二 替換命令
批量註釋: 使用下面命令在指定的行首添加註釋: :起始行號,結束行號s/^/註釋符/g 取消註釋:- vim批量替換:
如想把所有的username換成login_name,那麽:%s/username/login_name/g就可以了。
Connecting to 192.168.127.130:23...
Connection established.
Escape character is ‘^@]‘.
Ubuntu 16.04.2 LTS
ubuntu64-casa login: casa
Password:
Login incorrect
ubuntu64-casa login: casa
Password:
Last login: Tue Mar 21 09:29:56 CST 2017 from 192.168.127.1 on pts/1
Welcome to Ubuntu 16.04.2 LTS (GNU/Linux 4.4.0-62-generic x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
26 packages can be updated.
25 updates are security updates.
Signature not found in user keyring
Perhaps try the interactive ‘ecryptfs-mount-private‘
[Oh My Zsh] Would you like to check for updates? [Y/n]: Y
Updating Oh My Zsh
error: Cannot pull with rebase: You have unstaged changes.
There was an error updating. Try again later?
?. ~ git:(master) ?.
?. ~ git:(master) ?.ls
python
?. ~ git:(master) ?.cd python
?. python git:(master) ?.ls
03062.pcap 1_0310.py 1.py ftp1.py ftp2.py ftp.py master.zip paramiko.log pydiction ssh.py startup.py
?. python git:(master) ?.vim startup.py
?. python git:(master) ?.vim startup.py
1 #startup.py
2 #!/usr/bin/python
3 # python startup file
4
5 import sys
6 import readline
7 import rlcompleter
8 import atexit
9 import os
10 # tab completion
11 readline.parse_and_bind(‘tab: complete‘)
12 # history file
13 histfile = os.path.join(os.environ[‘HOME‘], ‘.pythonhistory‘)
14 try:
15 readline.read_history_file(histfile)
16 except IOError:
17 pass
18 atexit.register(readline.write_history_file, histfile)
19
20 del os, histfile, readline, rlcompleter
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
:%s/import/immport/g
Connecting to 192.168.127.130:23...
Connection established.
Escape character is ‘^@]‘.
Ubuntu 16.04.2 LTS
ubuntu64-casa login: casa
Password:
Login incorrect
ubuntu64-casa login: casa
Password:
Last login: Tue Mar 21 09:29:56 CST 2017 from 192.168.127.1 on pts/1
Welcome to Ubuntu 16.04.2 LTS (GNU/Linux 4.4.0-62-generic x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
26 packages can be updated.
25 updates are security updates.
Signature not found in user keyring
Perhaps try the interactive ‘ecryptfs-mount-private‘
[Oh My Zsh] Would you like to check for updates? [Y/n]: Y
Updating Oh My Zsh
error: Cannot pull with rebase: You have unstaged changes.
There was an error updating. Try again later?
?. ~ git:(master) ?.
?. ~ git:(master) ?.ls
python
?. ~ git:(master) ?.cd python
?. python git:(master) ?.ls
03062.pcap 1_0310.py 1.py ftp1.py ftp2.py ftp.py master.zip paramiko.log pydiction ssh.py startup.py
?. python git:(master) ?.vim startup.py
?. python git:(master) ?.vim startup.py
1 #startup.py
2 #!/usr/bin/python
3 # python startup file
4
5 immport sys
6 immport readline
7 immport rlcompleter
8 immport atexit
9 immport os
10 # tab completion
11 readline.parse_and_bind(‘tab: complete‘)
12 # history file
13 histfile = os.path.join(os.environ[‘HOME‘], ‘.pythonhistory‘)
14 try:
15 readline.read_history_file(histfile)
16 except IOError:
17 pass
18 atexit.register(readline.write_history_file, histfile)
19
20 del os, histfile, readline, rlcompleter
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
-- VISUAL -- 16 5,1 All
- VI刪除與復制多行
vim批量替換