[I have a bold idea] Set shortcut keys in gvim to quickly beautify RTL (1)

Preface

Ming Ren clearly stated: What is the most important thing about the code! Answer: beautiful!

Therefore, I have been thinking for a long time, how to beautify the code quickly and easily?

If you can directly beautify with one click in vim, perform automatic code alignment, line break typesetting, etc., wouldn't it be niubilitable!

So I need to solve a problem first: how to quickly call a script in gvim, of course, not in the way of xxx.py.

Prepare a script

The prepared script is very simple, that is, the input in the input file is turned into INPUT, ok is ready, the script name is py_test

#! /usr/bin/python

import sys
import re

mid_handle = []
file = sys.argv[1]
with open(file, "r") as handle:
    mid_handle = handle.readlines()
    for line in mid_handle:
        out = line.rstrip()
        out = re.sub(r"^\s+input\s", "INPUT ", out)
        print(out)

Tinker with vimrc

The goal is clear, I want to set a shortcut key in vim, which can take the currently opened file as input, and use the current file as output to modify the current code;

Of course, in the future, there will definitely be a need to use the current file as input and output a new file. This will be done later.

After checking a lot of things, I found that this is fine:

command! F :execute '%! /home/xiaotu/Desktop/py_test %'

After this setting, use :F as a shortcut to call this script, and the last% indicates the current file accepted by the script as input.

By default, the output terminal of the script is the current file.

have a test

What the test file looks like:

When typing: F in the reading mode:

Press Enter to transform and update directly to the current document~~~~

It can be said to be perfect, ready to plan for the next step

Guess you like

Origin blog.csdn.net/moon9999/article/details/114420958