vim使用

有些工具,当时拿出来的时候很惊艳,但是一段时间过后就会明白充其量也只是惊艳而已。
还有一种工具,当你使用的越多,你才会发现这玩意简直就是神一样的存在。
vim就是这样的工具,你服还是不服?

教程很多,我个人之前存放的是简明vim练级攻略

文本操作历来就是常见操作,这种技能不能挂上技能清单,但是如果你没有处理文字的能力,那么总会让人觉得有些不可思议。从searchregex ,从notepadnotepad++ ,最后再到这里要讨论的vim ,你会发现,有些东西,确实是熟能生巧之后才知牛逼。

vim用的时间不长,已经发现了确实非常赞,个人感觉vim的最大好处是释放了你键盘和鼠标切换的时间,这个时间真的太长了,而且是没有意义的存在。

文本操作有时候和数据库的操作非常像:增,删,改,查。

常见基础命令

阅读

  • 普通模式下光标移动h(left-line),j(down-line),k(up-line),l(right-line)
  • 跳转到第n行nG
  • 跳转到文本起始位置 gg
  • 跳转到文本末尾 G

命令模式的开启:: / ?

编辑

插入
  • a (after) 在光标后插入 A 在光标所在行的末尾插入
  • i (before) 在光标前插入 I 在光标所在行的起始位置插入
  • o 在光标所在行下方新建行插入 O 在光标所在行的上方位置新建行并插入
  • r 替换光标位置处的字符(only one time),执行后返回到普通模式 R 在光标位置处连续替换,直到ESC 被按下为止
替换
范围 s/old-chars/new-chars

(update 6.30) 这几天在处理bash文件 的时候经常要将连续几行文字给注释了。也就是在若干行的句首添加# 字符。
方法如下:

:.,$s/^/#        (将当前行到文件末尾的所有行句首添加#)

:1,3s/^/#         (档案的第1~3行添加注释#)

估计^ 是行开头的标志,看得出来这种方法也是替换的一种应用方式。

(udpate7.1)
既然讲到了句首,那么也说说句尾。

^ 代表句首一样,$ 代表的是句尾。

  1 #linux 
  2 #linux 
  3 #Redhat 
  4 #Redhat 
~                                                                                                                                                      
~                                                                                                                                                      
~                                                                                                                                                      

~                                                                                                                                                      
:%s/$/ --this is line end symbol

替换后就成了

  1 #linux --this is line end symbol
  2 #linux --this is line end symbol
  3 #Redhat --this is line end symbol
  4 #Redhat --this is line end symbol

其中%s/ 代表了文件中的每一行,和1,$s/ 是一个意思

update(7.2)

  • 要用到注释光标下4行的内容,可以使用:.,+4s/^/#/g ,注释后光标下移4行。向上用-range 符号

  • :start-line,endline s/old-words/new-words/gold-words 是正则匹配pattern ,今天才知道。因此替换功能更加强大了。

同时,也测试了一下是否/ 查找命令也支持正则,结果是不支持。。

删除
  • 删除光标所在行 dd
  • 删除光标后n行 ndd
  • 向后删除光标所在的单个字符 x ,向前删除光标所在的单个字符 X

复制:行复制yy
粘贴:p or P (取决于粘贴方向)
剪切:dd (delete,行操作)

undo: 撤销 u
redo:恢复 ctrl+r (为什么不是r,因为r已经是开启编辑模式的功能键了)

查找

查找:/searchWord 向下查询,向上为?searchWord
继续寻找为:n (sublime 下的F3)

保存那些太常规了,基本上不会变化,没必要细讲。

update 7.2

  • 查找光标所在位置当前词。一个简单的方法可以让你查找下一个和当前词一样的词,你不必输入/currentword,你可以直接按下*就可以查找下一个currentword。#可以让你向上查找同一个单词。

从命令中得到的一般规律,有待考证:

$ 应该和正则一样,是个行后缀标志,作用范围为当前行内
G 应该是个跨度标志 如 10G,即从开头跨越到第10行, yG 表示光标所在行到最后一行全被复制

组合命令

  • 删除全文
1.跳转到文件第一个字符 gg
2.删除到文件结尾      dG

小技巧

晚上查文档发现了一些小技巧

切换显示行号开关

:set number
:set nonumber

竟然也可以这么写
原来 也可以表示关闭的意思

:set number
:set number!

在命令行下同样可以执行bash 快捷键

  • ctrl+u 删除命令
  • ctrl+p 显示上一条命令

等等等等,原来执行的是bash 操作。

文章中涉及的参考链接

vim 查找替换 和高级应用 vim的多行注释和替换

休息五分钟,学几个bash快捷键

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
vim数据库连接插件,便于数据库SQL调试,支持几乎所有的常见数据库, For instructions on installing this file, type :help add-local-help |add-local-help| inside Vim. Homepage: http://vim.sourceforge.net/script.php?script_id=356 SourceForge: $Revision: 1.23 $ *dbext* *dbext.vim* *db_ext* *db_ext.vim* *database-extension* *pgsql* *mysql* *asa* *ase* *ingres* *interbase* *sqlite* *sqlsrv* *ora* *db2* 1. Overview |dbext-overview| 2. Installation |dbext-install| 3. Configuration |dbext-configure| 3.1 Displaying Results |dbext-configure-results| 3.2 Script Variables |dbext-configure-variables| 3.3 Database Specific Options |dbext-configure-options| 3.4 DB2 Modes |dbext-configure-db2| 4. Mappings and commands |dbext-mappings| 5. Adding new database types |dbext-newdb| 6. Prompting for input parameters |dbext-prompting| 7. Setting up connection information |dbext-connect| 7.1 Connection Parameters |dbext-connect-parameters| 7.2 Prompting for Parameters |dbext-connect-prompting| 7.3 Connection profiles |dbext-connect-profiles| 7.4 Connection information in modelines |dbext-connect-modelines| 7.5 Asking for connection parameters |dbext-connect-ask| 8. Creating mappings using dbext commands |dbext-in-mappings| 9. Object Completion |dbext-completion| 10. Listing Objects in the Database |dbext-list-objects| 11. Plugin integration |dbext-integration| 11.1 OMNI completion integration |dbext-omni-completion| 11.2 Intellisense integration |dbext-intellisense| 12. Filetype support |dbext-filetypes| 12.1 Using filetype support |dbext-filetypes-using| 12.2 Adding new filetypes |dbext-filetypes-adding| 13. Using SQL History |dbext-history| 14. Open Source |dbext-sourceforge| 15. Tutorial |dbext-tutorial| {Vi does not have any of this} ------------------------------------------------------------------------------ What's New *dbext-new* Version 4.20 New Features ------------ - Improved support for Cygwin. If you are using a Cygwin compiled Vim (on Windows) and are accessing Windows compiled binaries (i.e. sqlplus.exe) the binary will complain since it does not understand Unix path names. Added the option g:dbext_default_use_win32_filenames which allows you to indicate the binaries must use translated Windows paths instead. (Richard) - DBGetOption displays more information. Bug Fixes ------------ - SQL Server support had issues with the queries when running DBCompleteTable, DBCompleteProcedure, DBCompleteView which also affected the sqlcomplete.vim plugin included with Vim7 (Albie Janse van Rensburg). Version 4.10 New Features ------------ - Updated DBGetOption to additionally display a list of all database profiles and their types. All dbext options that have been overriden via the vimrc are also displayed. Bug Fixes ------------ - db2 support had issues with the queries when running DBCompleteTable, DBCompleteProcedure, DBCompleteView which also affected the sqlcomplete.vim plugin included with Vim7 (Peter Princz). - The documentation was still indicating there was a plugin dependency which has been removed with Vim7. Version 4.00 New Features ------------ - dbext.vim now requires Vim7. - dbext.vim required 2 additional plugins multvals and genutil to operate. These dependencies have been removed by taking advantage of the new Vim7 features (Lists and Dictionaries). - When using the DBCompleteTable, DBCompleteProcedure, DBCompleteView commands errors are displayed instead of silently ignored. This makes them more useful with the sqlComplete plugin (see |sql.txt|). - Added new option, dbext_default_MYSQL_version, for MySQL to indicate the version you using. - You can optionally define a function, DBextPostResult, in your .vimrc, this function will be called each time the result window is updated. This function can be used to do anything, for example, syntax highlighting the result set in the result window.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值