美文网首页
2021-11-17

2021-11-17

作者: 追梦人在路上不断追寻 | 来源:发表于2021-11-17 22:31 被阅读0次

9 Essential commands to unlock the power of vim

Bram Moolenaar , the creator of vim, cloned and improved vi and released it in 1991. The name vim came from “vi imitations”, later changed to “Vi improved”. Gradually it became the most popular text editor among Linux users. In 2019 Stackoverflow developers survey vim was the fourth most popular text editor.

In their last survey, Stackoverflow revealed over 2.1 million people visited the ‘ How do I exit the Vim editor? ‘ question on Stack Overflow. So I am writing some top googled vim commands and the general know-how required to use vim.

Vim modes

Out of so many, the most frequently used are “command-line mode”, “normal mode” and “insert mode”.

Normal mode

You are in normal mode when you open a file. To go back to the “normal mode”, press the Esc key.

Command-line mode

To run a command, go to the command-line mode by typing colon :.

Insert mode

Get into “insert mode” by pressing i in "normal mode".

Vim commands

Press Esc key to enter "normal mode" then press colon : to enter "command-line mode". At the bottom left corner of vim, a colon : appears. Now you can type any command and press the Enter key to execute the command.

vim command to open a file

Type vim preceded by file name to open a file in the vim text editor.

vim command to save and exit

Press the Esc to get out of "insert mode". Press colon : to get into the "command-line mode" and type wq to write and quit the file. If you have not made any changes to the file, you can exit by q command.

  • :q to quit
  • :wq to write and quit
  • :q! to quit without writing
  • :x to save and quit (similar to :wq)
  • :exit save and exit (similar to :x)

vim command to edit file

Press the i key in "normal mode" to start editing the file.

vim command to go to the end of the file

Type capital G or shift+g to go to the end of the file in vim.

vim command to go to top of file

Type gg or 1G to go to the beginning of the file.

vim command to delete all lines

Use letter d to delete. Go into "command-line mode" by pressing : and type %d to delete all lines. You can also use range 1,$d. Just like regular expressions $ sign represents the end of the file.

vim command to show line numbers

In “command-line mode” type, set numbers or short command set nu to display line numbers of the file.

vim command to replace string

Type search string followed by the replacement string %s/search/replace/g.

vim command to delete lines with pattern

Inside “command-line mode” type, g/pattern/d

Run the :help command to check usage documentation. Add a query after :help to get specific help. Vim comes with a separate tutor program to teach vim usage. Run vimtutor in the terminal for this 20 minutes practice tutorial. Use the comments section to mention any other essential commands that I have missed.

相关文章

  • 万马奔腾

    内心万马奔腾, 情绪亚历山大! 加油! 2021-11-17

  • 读书笔记(四十三)

    书名:《非暴力沟通》 作者:【美】马歇尔·卢森堡 分类:人际交往 阅读时间:2021-11-17 内容简介:马歇尔...

  • 冬天已来,你准备好了吗?

    D341 2021-11-17 最近在调整状态,自己在做一些后端优化的工作,餐饮人的每天都很充实,细小而琐碎,却很...

  • 今日份幸福

    幸福日志2021-11-17 周三晴 今日份幸福一 收到同事送的平衡车。想省钱就按省钱的搞法,逛了几天咸鱼无果,于...

  • 2021-11-17周三

    2021-11-17 每日复盘 早上晚起了,来不及煮早餐了,洗漱,护肤,换衣服,把中午汤煮上,出门上班。楼下买个早...

  • 写给先生(84)

    2021-11-17 阴 大抵是思念作祟,姑娘横竖都睡不着。侧身躺着,打开手机,翻着旧时的文字,想再寻一遍你的影子...

  • 精华摘

    2021-11-17 周三 阴天 今天是周三,阴天,最高气温21度。体感舒适。刚才打开手机看到13点57分的时候,...

  • 兄弟姐妹

    2021-11-17 周三 晴 1 二姐 二姐生病了。嘴唇干裂,浑身乏力。吃了两天板蓝根,她时而说好,时而说难受。...

  • 主妇日记

    2021-11-17 今天天气很好,阳光透过窗户照到卧室一角的工作桌上,柚子的碎发留下深深浅浅的影影绰绰。 录入昨...

  • 干锅女王再度上线

    2021-11-17 早上刚起来,打开微信看到先生给我发了一张图片。 猛然想起来昨天晚上没关煤气。 因为生活中经常...

网友评论

      本文标题:2021-11-17

      本文链接:https://www.haomeiwen.com/subject/gpvrtrtx.html