Standard word order of declarative sentences in English is first the subject, then the verb. But, there is a literary technique in English requiring changing the standard word order which makes the sentences difficult to understand for the beginners.
In normal everyday English, inversion is used:
− to make questions: Does he? Can you?
− after «so», «neither», «nor»: So do I, neither do I, nor do I. 
In learning English grammar, most learners don’t pay attention to the use of other types of inversion and the sentences with complex inversion are considered as sentences with an error of punctuation by them. Because, the learners analyze the sentences and consider them as interrogative sentences according to the order of auxiliary verbs or so, but cannot understand or translate them into their native language. So, they have to come to the conclusion that the sentences are not grammatically correct.
Inversion is a structure in which a verb or an auxiliary verb is put before the subject even if the sentence is not an interrogative one. We can use inversion before several negative words such as «never,nowhere, no, not, not only, rarely». In general, inversions are used to emphasize the speaker’s idea. It is a literary technique generally used for emphasis or for special effect. It also sounds quite formal. So, sentences with inversion doesn’t occur in everyday English:
Example 1 (sentence without an inversion): I have never seen such a beautiful girl!
Example 2 (the same sentence with an inversion): Never have I seen such a beautiful girl!
In example 2 inversion is used to emphasize the fact that I have not seen such a beautiful girl in my whole lifetime.
Adverbs such as never, rarely, and seldom occur in inverted sentences to emphasize the unique situation in the sentences they are used. These adverbs are usually used with one of the perfect tense forms and often with modals:
Never have I been more insulted!
Seldom has he seen anything stranger.
Rarely has someone been so wrong as you. 
Adverbs such as hardly, barely, no sooner or scarcely are used with an inversion in sentences to express the quick succession of two or more actions in the past. As these adverbs, express time there are when sentences with inversion:
No sooner had they called Santa, when he came into the room (=there was really little time between the time «they called Santa» and «He came into the room»).
Never could she understand how he cared.
Rarely did anyone declare the true size of his property.
When the words here and there are adverbs of place, we can use inversion and in this case, an auxiliary verb can be omitted while the main verb used alone and in some sentences like these even the subject comes after the verb.
Here comes the bus!
Here’s your coffee.
I opened the door and there stood Michael, all covered in mud.
She looked out and there was Pamela, walking along arm in arm with Goldie. 
Inversion with here and there usually occurs when there is an exclamation in the sentences.
In turn, conditional sentences can also be inverted. Sometimes they are inverted to sound more formal. In these kinds of sentences the conditional word if is omitted and the auxiliary word is put before the subject of the sentence and that’s why these kinds of sentences are much like question forms. So they often call misunderstanding among new learners of English. In order to help differ the resemblance we have decided to give both normal and inverted forms of these kinds of sentences in examples:
Normal conditional (1): If I had known that you were ill, I would have gone to see you.
Inverted version (1): Had I known that you were ill, I would have gone to see you.
Normal conditional (2): If you should receive, any letter from him let me know about it.
Inverted version (2): Should you receive any letter from him let me know about it.
Normal conditional (3): If you had gone there, you would have learnt lots of things.
Inverted version (3): Had you gone there, you would have learnt lots of things.
There are are also some uses of inversion in direct speech. Inversion is used in sentences in direct speech with verbs such as said, asked.
«I’ll help you with your homework», said Jane.
«What’s the matter?», asked the teacher.
If the subject of the direct speech sentences in current English is expressed by a personal pronoun, the verb is usually placed after the subject without inversion:
«I’ll help you with your homework», she said.
«What’s the matter?», he asked.
But, even inversions with personal pronouns can be found in literary works of the past centuries:
«I am not afraid of you», said he, smilingly. (Jane Austen)
«Where is the Prince?», said he. (Charles Dickens)
«That's a fire», said I. (Mark Twain) 
If there is a direct object after the word ask, we cannot use inversion in such sentences:
«Would you like me to help you with your homework?»? Jane asked her boyfriend.
If the verbs asked and said is put at the beginning of the sentences in direct speech inversion is not used:
Jane asked, «Would you like me to help you with your homework?»
- Cambridge Advanced Learners’ Dictionary, 3rd edition.
- Longman Dictionary of Contemporary English, 5th edition