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

推荐订阅源

小众软件
小众软件
WordPress大学
WordPress大学
IT之家
IT之家
G
Google Developers Blog
Vercel News
Vercel News
阮一峰的网络日志
阮一峰的网络日志
博客园 - 三生石上(FineUI控件)
Engineering at Meta
Engineering at Meta
Martin Fowler
Martin Fowler
V
V2EX
爱范儿
爱范儿
Hugging Face - Blog
Hugging Face - Blog
Apple Machine Learning Research
Apple Machine Learning Research
B
Blog
V
Visual Studio Blog
有赞技术团队
有赞技术团队
I
InfoQ
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
月光博客
月光博客
J
Java Code Geeks
Stack Overflow Blog
Stack Overflow Blog
P
Proofpoint News Feed
云风的 BLOG
云风的 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
Line Number Settings for More Efficient Movement in Neovim
2019-01-11 · via jdhao's digital space

In this post, I would like to share line number settings in Neovim to move the cursor more efficiently.

Absolute number and relative number in Neovim#

Show absolute line number#

To know where we are in a file, it is useful to show the line number on the leftmost column of the window. To show line numbers in neovim, we can set the number option:

The absolute line number will be shown at the leftmost column of current window.

Combine absolute number and relative number#

While the number option is useful, it is not convenient for us to move the cursor to other lines. Because cursor movement in Neovim is based on relative distance. For example, to go to 3 lines above or below the current line, we use 3k or 3j. If we want to go to a specific line, we have to manually calculate the distance between current cursor line and the destination line, which is cumbersome and error-prone.

To alleviate this issue, Neovim also support showing relative number:

This option can be combined with the number option. The end result is that only the cursor line shows absolute line number, and all the other lines show relative number( or distance) relative to current line.

Automatic toggle of relative line number#

In some situations, it is more convenient to see absolute line numbers, e.g., when we want to debug a file and run to specific lines. We can the use plugin vim-numbertoggle to automatically toggle relative number based on several events. e.g., when we enter insert mode or lost focus of a window.

Automatic number toggle does not work inside Tmux?#

I have found that the number toggle function does not work inside tmux sessions by default1. If I open two tmux panes side by side and open a file in Neovim in one pane and then switch to another tmux pane, the relative line number in Neovim does not change to absolute number.

I opened an issue on the Neovim GitHub repo and get the right answer from the developer. We need to turn on the focus-events option for tmux. From the Tmux documentaion:

focus-events [on | off]
        When enabled, focus events are requested from the terminal if
        supported and passed through to applications running in tmux. Attached
        clients should be detached and attached again after changing this
        option.

We need to edit the tmux config file ~/.tmux.conf and add the following setting:

Refresh the tmux session or start a new tmux session and automatic relative number toggle should work as expected now.

References#