Refactoring in Vim

前端 未结 15 1946
醉梦人生
醉梦人生 2021-01-29 17:44

Of course the fact that you can refactor on IDEs is priceless for many, I hardly ever do it when I am coding but I may try to do it when editing some one else\'s source. How do

相关标签:
15条回答
  • 2021-01-29 18:32

    Plugin Factorus

    There is another vim plugin dedicated for refactoring called factorus which is available on github.

    Currently (2017-12), it supports the languages

    • c,
    • java, and
    • python.
    0 讨论(0)
  • 2021-01-29 18:35

    Go

    1. The tool godoctor (github) supports several refactoring capabilities
    • Rename
    • Extract Function
    • Extract Local Variable
    • Toggle var ⇔ :=
    • Add Godoc stubs

    There is a vim plugin https://github.com/godoctor/godoctor.vim which makes them available

    With cursor in thing to rename:

    :Rename <newname>
    

    Highlighting block to extract:

    :Refactor extract newfunc
    
    1. vim-go

      • Precise type-safe renaming of identifiers with :GoRename.
    2. Language server gopls

      • https://github.com/golang/tools/blob/master/gopls/doc/status.md#rename
    0 讨论(0)
  • 2021-01-29 18:38

    I write a lot of C/C++ code in vim. The most common refactoring that I do is renaming variables, class names, etc. Usually, I use :bufdo :%s/source/dest/g to do a search/replace in files, which is almost the same as renaming provided by big IDE's.
    However, in my case, I found that I usually rename similar entities, spelled in different cases (i.e CamelCase, snake_case, etc.), so I decided to write a small utility to help with this kind of "smart-case" search/replace, it is hosted here. It is a command-line utility, not a plugin for vim, I hope that you can find it useful.

    0 讨论(0)
提交回复
热议问题