vimvim-plugin

Vim align text to left side


Given something like:

dadscasd
  cas
    casdc 

How, in vim, can I alight all lines to left side?

dadscasd
cas
casdc 

I installed vim tabular. I know how to align a pattern but have no idea about how to align everything to left. Also not sure vim tabular is the right tool for the job.


Solution

  • To do this easily without any plugins
    In normal mode, press:

    ggVG<<
    

    and then press . as many times as you need to.

    An explanation of the commands

    If you don't want to do all the lines, you only need to select the lines you want to move, using v or V. Then press << or >> to start indenting. Once again, . will repeat the last command issued to make your life easier.

    To learn more, open vim and without typing anything else, type :h << and hit enter.

    A faster way, without visual confirmation, is to type

    :%left
    

    where % in this case means the whole range of the current buffer, as it is an alias for 1, $.
    see :h left and :h range