vim 在指定行的行首,添加行号

原文

  • 想要在每行前面加行号以及’. ',效果如1. https://leetcode.com...
https://leetcode.com/problems/peak-index-in-a-mountain-array/
https://leetcode.com/problems/find-positive-integer-solution-for-a-given-equation/
https://leetcode.com/problems/binary-search/
https://leetcode.com/problems/capacity-to-ship-packages-within-d-days/
https://leetcode.com/problems/koko-eating-bananas/
https://leetcode.com/problems/find-the-smallest-divisor-given-a-threshold/
https://leetcode.com/problems/sum-of-mutated-array-closest-to-target/

命令

在visual模式下,选定要修改的行之后

'<,'>:s/^/\=(line('.') - line("'<") + 1).'. '/

\\=(line('.') - line("'<") + 1)可以得到选定段的行号。原理是当前行减去选定行的首行以后,获得了相对位置,再+1,从1开始计算,便达到目的

如果后面还需跟一些内容,可以用.'***'来添加,其中***就是要添加的东西

效果

1. https://leetcode.com/problems/peak-index-in-a-mountain-array/
2. https://leetcode.com/problems/find-positive-integer-solution-for-a-given-equation/
3. https://leetcode.com/problems/binary-search/
4. https://leetcode.com/problems/capacity-to-ship-packages-within-d-days/
5. https://leetcode.com/problems/koko-eating-bananas/
6. https://leetcode.com/problems/find-the-smallest-divisor-given-a-threshold/
7. https://leetcode.com/problems/sum-of-mutated-array-closest-to-target/

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章