Edit columnar data in vim

editorsvim

Data

Name                     Age
Madhavan                 29
saravana<Tab Press>      !

How can i edit this data in vim in a tabular fashion?

When i press tab key from column 1 in row 3, the cursor must move to the exclamatory mark position.

Note: Exclamatory mark is just a marker position where i desire the cursor to go and it is not the real character in place.

This can be done using org-table mode in emacs but it is overkill at times.

So i am looking for simpler ways in vim/shell?

Best Answer

  1. Move the cursor to the uppermost character (if you’re selecting lines the way down, bottom if you’re going up) before which you want to insert text
  2. Enter Visual Block Mode by pressing Ctrl+v (unless you mapped the paste action to it, in which case you probably already know how to column insert)
  3. Select the column using the arrow keys and
  4. Press Shift+i (switching into Insert Mode)
  5. Type the text you want to insert (will be displayed only on the first line)
  6. Press esc two times. In case you want to delete text, follow steps 1 through 3 and simply select all text you wish to delete, then press x and you’re done!

Note: If you need more specific functions, you can search vim plugins, other choice is export the xx column in other file (with cut or awk) if you want more solutions.

Related Question