Millet Porridge

English version of https://corvo.myseu.cn

0%

Linux Tips (III)

Counting Words in Vim

1
g Ctrl-g

It counts not only the words of the whole document — text selected in visual mode can be counted too.

ctrl-g

Using Vim modeline magic

It all started with this question: how to use your own vim config in Python files. It revealed a skill (okay, I admit I didn’t read the docs well — there are really too many docs, impossible to finish), something called Modeline magic. Its use is specifying the format vim should use when opening a given file: spaces or tabs, whether to show line numbers — it can do all of this.

So later, when writing Python code, I insert this line right at the top; that way even on other vims that aren’t configured, the display style is basically preserved. Not black magic — just a little trick.

1
2
3
4
5
6
7
8
9
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# vim: ts=4 sw=4 tw=99 et:

"""
@Date : July 26, 2018
@Author : corvo

"""

Multi-Line Operations in Vim

  1. First press Ctrl-q or Ctrl-v,
  2. after selecting some rows and columns,
  3. press capital I to enter insert mode,
  4. do something on the first line,
  5. press ESC and the operation is applied to all

The two images below demonstrate inserting spaces and deleting spaces.

ctrl-v

ctrl-v-del

The Tabularize Plugin

Enough talk — straight to the pictures.

tabu1 tabu2

This part refers to the tabular article. If you use my configured vim, you can use it right after installing the plugins. Or add Plug 'vim-scripts/Tabular' to your own vundle section to install it. The blog above is worth a careful read.