Consider a scenario, when you are editing a C file in vim
. & you have used a mix of spaces & tabss. & you need to convert all of them to spaces.
There is a utility, called expand
, which performs this task intelligently & it's a preferred way than s/\t/<4 spaces>/g
. We can use this command in vim using :%!expand -t4
. Typically, I map a function key, say F11 for this.
Similarly, we can use any other command in vim.
The problem is when you run any such operation on entire buffer, the cursor position changes & can be irritating at times.
Hence, the question is, how to perform an operation on entire buffer, without changing cursor position?