4
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?

  • Vim has modes so moving depends on what mode you are in. You can do what you are looking to but not in insert mode (as far as i know). If you are in normal mode you will want to use a movement. You could for example use f! (in command mode) which would move you forward to the next ! character. Also unless you have the tab character mapped already you could remap the tab key to advance to the next non-whitespace character and enter insert mode. Your command would still be something like <esc> <tab> – user1794469 Jul 12 '15 at 16:04
  • Exclamatory mark is just a marker position where i desire the cursor to go and it is not the real character in place. – Madhavan Jul 12 '15 at 16:10
  • Are the fields separated by a single tab or are they visually aligned? If you don't know you can see the formatting symbols with :set list. if you see blanks they are spaces, tabs will show up as ^I – user1794469 Jul 12 '15 at 16:36
0
  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.

  • I don't think OP is trying to do this. I think they want to have the cursor at the end of the third line and with tab, advance it to the !. – user1794469 Jul 12 '15 at 16:06
0

You want to move through each cell. So, in normal mode, w or b command will help you to move forward or backwards through every word.

To get the same facility in insert mode, you can use map.

    :imap  <Tab> <Esc>wi

Put this in command line.

When you are editing, you can press tab to move to next cell. The mapping I have done will come out of insert mode, then move forward to next word (w) and then changes to insert mode.

-1

You can do this:

$vim +number_line file

and after press Shift+A. Alternatively, you can do /word_to_find and then press i to edit.

  • Omg, I hate the people that down scores because they didn't understand. Tell me what didn't you understand. I do this everyday, ask me (I want someone down scores you). Ask me before it, I answered yours question, tell me!! (I am angry with people like you) – Joe Mantil Jul 12 '15 at 17:23
  • 3
    This answer seems very limited if I'm reading it correctly. OP wants a method where pressing tab will space out to the same column as the previous line, and they probably want to do that repeatedly so they can easily enter many rows of data. You gave a way to jump to the end of a particular line when opening a file or to search for a particular string; neither of those is going to solve their problem. – Michael Mrozek Jul 12 '15 at 18:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.