programing

숭고한 텍스트 3, 공백을 탭으로 변환

new-time 2020. 5. 25. 21:41
반응형

숭고한 텍스트 3, 공백을 탭으로 변환


나는 이것에 관한 많은 게시물이 있다는 것을 알고 있지만 그것을 작동시키지 못했습니다.
코딩에 탭을 사용합니다. 항상 공백을 탭으로 변환하는 방법이 있습니까? 즉 파일 열기 및 저장? 누구나 아이디어가 있습니까?

// 편집 :
이 작업을 자동으로 수행하는 것이 좋습니다 ! -> 열거 나 저장하거나 즉석
에서 누구든지 어떻게해야하는지 알고 있습니까?


나는 노력 :

import sublime, sublime_plugin, os

class ExpandTabsOnSave(sublime_plugin.EventListener):
  # Run ST's 'expand_tabs' command when saving a file
  def on_pre_save(self, view):
    if view.settings().get('expand_tabs_on_save') == 1:
      view.window().run_command('expand_tabs')

그리고 내 사용자 설정은 다음과 같습니다.

{
    "auto_complete_selector": "source - comment, meta.tag - punctuation.definition.tag.begin",
    "auto_indent": true,
    "detect_indentation": true,
    "draw_white_space": "all",
    "ensure_newline_at_eof_on_save": true,
    "expand_tabs_on_save": true,
    "font_face": "SourceCodePro-Regular",
    "font_size": 10,
    "format_on_save": true,
    "ignored_packages":
    [
        "Vintage"
    ],
    "indent_to_bracket": true,
    "open_files_in_new_window": false,
    "smart_indent": true,
    "tab_size": 4,
    "translate_tabs_to_spaces": false,
    "trim_automatic_white_space": true,
    "trim_trailing_white_space_on_save": true,
    "use_tab_stops": false,
    "word_wrap": false
}

Sublime Text 창의 오른쪽 하단에 다음과 같은 들여 쓰기 표시기가 나타납니다.

들여 쓰기 옵션 메뉴

클릭하면 들여 쓰기 환경 설정을 조정하고 공백을 탭으로 변환하거나 그 반대로 변환하는 옵션이있는 메뉴가 열립니다.

같은 메뉴가 아래에 나열됩니다 View -> Indentation.


Sublime 창 하단에 탭 / 공간 설정을 나타내는 것이 표시됩니다.

그런 다음 다양한 옵션이 포함 된 드롭 다운이 표시됩니다. 관심있는 옵션은 다음과 같습니다.

  • 들여 쓰기를 공백으로 변환
  • 들여 쓰기를 탭으로 변환

원하는 설정을 전체 문서에 적용하십시오.

도움이 되었기를 바랍니다.


이미 알고 있듯이 다음과 같이 indention 설정을 사용자 정의 할 수 있습니다 Preferences.sublime-settings.

"detect_indentation": true,
"tab_size": 4,
"translate_tabs_to_spaces": false

이렇게하면 편집기가 4 칸 너비의 탭을 사용하도록 설정하고 Sublime이 편집중인 파일의 들여 쓰기와 일치하는 기본 동작을 무시합니다. 이 설정을 사용하면 파일을 다시 들여 쓰기하면 공백이 탭으로 바뀝니다.

As far as automatically re-indenting when opening a file, that's not quite as easy (but probably isn't a great idea since whitespace changes wreak havoc on file diffs). What might be a better course of action: you can map a shortcut for re-indention and just trigger that when you open a new file that needs fixing.


You can use the command palette to solve this issue.

Step 1: Ctrl + Shift + P (to activate the command palette)

Step 2: Type "Indentation", Choose "Indentation: Convert to Tabs"


In my case, this line solved the problem:

"translate_tabs_to_spaces": false

Here is a solution that will automatically convert to tabs whenever you open a file.

Create this file: .../Packages/User/on_file_load.py:

import sublime
import sublime_plugin

class OnFileLoadEventListener(sublime_plugin.EventListener):

    def on_load_async(self, view):
        view.run_command("unexpand_tabs")

NOTE. It causes the file to be in an unsaved state after opening it, even if no actual space-to-tab conversion took place... maybe some can help with a fix for that...


save 에서 공백을 탭으로 자동 변환하려면 "$ SUBLIME_HOME $ \ Packages \"내의 "UnexpandTabsOnSave"라는 새로 생성 된 하위 폴더에 다음 Python 스크립트를 추가하십시오.

import sublime, sublime_plugin, os

class ConvertSpacesToTabsOnSave( sublime_plugin.EventListener ):
  # Run Sublime's 'unexpand_tabs' command when saving any file
  def on_pre_save( self, view ):
    view.window().run_command( 'unexpand_tabs' )

초기 리소스에 감사드립니다.


저장시 자동으로 수행하는 방법은 다음과 같습니다. https://coderwall.com/p/zvyg7a/convert-tabs-to-spaces-on-file-save

불행히도 패키지 관리자에서 패키지를 설치할 때 패키지가 작동하지 않습니다.

참고 URL : https://stackoverflow.com/questions/22529265/sublime-text-3-convert-spaces-to-tabs

반응형