惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

人人都是产品经理
人人都是产品经理
博客园_首页
博客园 - 三生石上(FineUI控件)
V
Visual Studio Blog
Hugging Face - Blog
Hugging Face - Blog
美团技术团队
小众软件
小众软件
T
Tailwind CSS Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
月光博客
月光博客
有赞技术团队
有赞技术团队
WordPress大学
WordPress大学
博客园 - 【当耐特】
Apple Machine Learning Research
Apple Machine Learning Research
罗磊的独立博客
V
V2EX
酷 壳 – CoolShell
酷 壳 – CoolShell
IT之家
IT之家
量子位
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Recent Announcements
Recent Announcements
M
MIT News - Artificial intelligence
阮一峰的网络日志
阮一峰的网络日志
The GitHub Blog
The GitHub Blog

jdhao's digital space

Conversion between base64 and OpenCV or PIL Image 腾讯云对象存储博客图床开启 CDN 加速(不需要购买额外域名) Search and Replace in Multiple Files in Vim/Neovim Change Table Column Width in LaTeX Image or Table Side by Side in LaTeX LaTeX 并排显示图像或表格 Firenvim: Neovim inside Your Browser Content inside HTML tags missing in Latest Hugo? Creating Markdown Front Matter with Ultisnips Labelme JSON 标注格式转 voc XML 格式 Nifty Nvim Techniques That Make My Life Easier -- Series 6 macOS 下如何为视频制作字幕 Running Command Asynchronously inside Neovim Resolving Merge Conflict after Git Stash Pop Pylint: command not found? A Hands-on Experience with Neovim's Built-in LSP Support How to Convert PDF to Images with Imagemagick 互联网上常用缩略语集锦 File Backup in Neovim Converting PDF Pages to Images with Poppler Nifty Nvim Techniques That Make My Life Easier -- Series 5 Neovim Configuration for System-wide Use How to sort a list of tuple or list in Python -- lambda or itemgetter? Building A Vim Statusline from Scratch 人类第一颗原子弹爆炸始末 Distributed Training in PyTorch with Horovod Learning Expect Programming Essential Knowledge about SSH Nifty LaTeX Techniques -- Series 1 更改 Adsense 邮寄地址,重新寄送 PIN
Nifty Nvim/Vim Techniques That Make My Life Easier -- Ser...
2020-09-22 · via jdhao's digital space

This is the 7th post of my post series on nifty Nvim/Vim techniques that will make my editing experience easier.

Click here to check other posts in this series.

Copy several lines to destination line#

Use :copy command:

[range] is a line range that has very flexible syntax, see :h cmdline-ranges for the details. {address} is the destination address you want to copy text to.

Let’s see some concrete examples.

  • Copy line 1 to 3 to below line 11:

  • Copy three lines from current cursor position to the end of the file:

Ref:

Save state of all opened files and open them later#

Sometimes, we want to restart Vim/Neovim, but do not want to lose the current state since we may have opened a lot of files. A simple way is to use :mksession command. It will create a file named Session.vim. Or you can provide a custom name for it :mksession my-sess.vim.

When you start Vim/Neovim later, you can use :source my-sess.vim to restore the state of previous state of Vim, with all the previous files opened.

There is also vim plugins such as vim-obession that helps you simplify the management of sessions.

Ref:

Delete lines matching/not matching a pattern?#

To delete lines matching a pattern, we can use the :global command:

Some explanation on this command:

  • %: specify the whole file. We can also specify a custom range, e.g., 2,10 (line 2 to line 10). See also : h cmdline-ranges.
  • some pattern: The pattern we want to match. It can be normal text or regular expressions.
  • d: For command :delete.

To delete lines not matching a pattern, we simply reverse the :global command via :global!:

which will delete lines not matching some pattern.

:g! is also equivalent to :vglobal (or :v) command (think of it as grep -v):

Ref:

Close the help window quickly?#

According to answer here, we can simply the use the :helpclose command to close the help window, which is by far the simplest way I have found.

Jump to the first occurence of a search term?#

When we search a pattern, we may want to go to the first occurence of the search pattern. Just press ggn in normal mode:

  • gg: go the begining of the file
  • n: search forward for the pattern.

Ref:

Keep only the lines matching a pattern from command output?#

A vim command may output a lot of text, making it hard for us to find what we want. For example, :highlight command will print a lot of lines of the highlight group info.

We can use :filter to get only what we are interested. The syntax is:

where pattern is the string pattern we want to search and [cmd] is a vim command. If we want to ignore cases, we can add \c before pattern:

:filter /\cpattern/ [cmd]

For example, to search highlight groups that contains the word search (ignoring the case), we use the following comamnd:

:filter /\csearch/ highlight

we only get the following three lines instead of the hundreds of lines:

IncSearch      xxx cterm=reverse gui=reverse guifg=#fe8019 guibg=#1d2021
Search         xxx cterm=reverse ctermfg=0 ctermbg=11 gui=reverse guifg=#fabd2f guibg=#1d2021
Searchlight    xxx links to ErrorMsg

Ref: