if self.settings.sort_by_file_name:
    fields = name_field, 'group', 'tab'
elif self.settings.sort_by_folder:
    fields = 'folder', name_field
elif self.settings.sort_by_syntax:
    fields = 'syntax', name_field
elif self.settings.sort_by_indexes:
    fields = 'group', 'tab'
self.view_items.sort(key=attrgetter(*fields))
Set part of a lambda function in advance to avoid repeated code