Play linux series Vim use

The secret of success is constancy of purpose
The secret of success is to hold on to constant

Sometimes I need to write code on the Linux server at work, but I am used to sublime. Suddenly switching to vim under Linux feels very uncomfortable, and the programming efficiency naturally drops a lot. But this is not to say that the vim editor itself is inefficient, but I have not played its powerful functions (it is said that the gods use vim), in order to speed up the efficiency of programming, simply learn to summarize the usage of vim.

Copy Cut Paste

1
2
3
Yy # copy a line
Dd # cut a line
p # paste

Find words

1
2
3
Bin/bash>:/nmask # Find the location where the nmask string exists
or
Bin/bash>:?nmask # Find the location where the nmask string exists

Continue to find the next location where the nmask string exists

  • n look up
  • N look down

Editor display settings

1
2
3
:set nu! # Display line number
:set autoindent # auto indent
:syntax enable # syntax highlighting

File Content Targeting

1
2
3
4
5
Gg # first line
G # last line
XG # navigate to line X
or:
Bin/bash>:10 # navigate to line 10

Insert data

1
o # insert a row under the current line

Save and exit

1
2
3
ZZ # save exit
ZQ # does not save exit
Bin/bash>:w filename #Save as

Character replacement

1
Bin/bash>:%s/regexp/replacement/g # Replace all matches in the text

In-line move

1
2
( # Move to the beginning of the sentence
) # Move to the end of the sentence

vim save files without permissions

File Read Only

Use :w! to force writes
Or: set noreadonly and then just use the normal :w

Can’t write, but has sudo privileges.

1
:w !sudo tee %

This is a command that receives pipe information and can write to a file.

No right to write to this file, no admin sudo

Use :w! ~/tempfile.ext to write the changes to a temporary file, then take steps to move the temporary files to the directory (send temporary files to the directory owner/administrator).

Portal

[[Play linux series] Linux basic commands] (https://thief.one/2017/08/08/1/)
[[Play linux system] Linux intranet penetration] (https://thief.one/2017/08/09/2/)
[[Play linux series] shell programming] (https://thief.one/2017/08/11/1/)

本文标题:Play linux series Vim use

文章作者:nmask

发布时间:2017年08月09日 - 15:08

最后更新:2019年08月16日 - 15:08

原始链接:https://thief.one/2017/08/09/1/en/

许可协议: 署名-非商业性使用-禁止演绎 4.0 国际 转载请保留原文链接及作者。

nmask wechat
欢迎您扫一扫上面的微信公众号,订阅我的博客!
坚持原创技术分享,您的支持将鼓励我继续创作!

热门文章推荐: