question for the vim users

Discuss the security implications of the various flavors of linux and unix

question for the vim users

Post by pretentious on Wed Nov 06, 2013 12:07 am
([msg=78062]see question for the vim users[/msg])

I've started to use vim for programming, hoping to get a really elegant workflow. I've got 2 questions about it that google isn't really going to cut it for. First the simple one. while in the opposite to insert mode, whatever it's called, i can't position the cursor at the absolute end of the line, the block is on the last character so when i go into insert mode, and say i back space everything, there is still that last character. Is this a feature or am i doing something wrong?

the second question is how do you efficiently use vim? In a normal text editor you would use the mouse or arrow keys to move around which might take a while but it's just one button click. In vim, you need to hit esc|ctrl+c|ctrl+{ to get out of insert mode and then move the cursor around, then hit i, then you can make your simple correction and often my corrections seem to be only a few characters away from where the cursor is at, say i want to move one space to the right. Is this an incorrect workflow or is it just something that takes a while to become efficient?
Goatboy wrote:Oh, that's simple. All you need to do is dedicate many years of your life to studying security.

IF you feel like exchanging ASCII arrays, let me know ;)
pretentious wrote:Welcome to bat country
User avatar
pretentious
Contributor
Contributor
 
Posts: 573
Joined: Wed Mar 03, 2010 12:48 am
Blog: View Blog (0)


Re: question for the vim users

Post by centip3de on Wed Nov 06, 2013 12:36 am
([msg=78063]see Re: question for the vim users[/msg])

pretentious wrote:I've started to use vim for programming, hoping to get a really elegant workflow. I've got 2 questions about it that google isn't really going to cut it for. First the simple one. while in the opposite to insert mode, whatever it's called, i can't position the cursor at the absolute end of the line, the block is on the last character so when i go into insert mode, and say i back space everything, there is still that last character. Is this a feature or am i doing something wrong?


To go to the end of the line, use '$'. To go to the end of the line and go into insert mode, use 'A' (for append).

pretentious wrote:the second question is how do you efficiently use vim? In a normal text editor you would use the mouse or arrow keys to move around which might take a while but it's just one button click. In vim, you need to hit esc|ctrl+c|ctrl+{ to get out of insert mode and then move the cursor around, then hit i, then you can make your simple correction and often my corrections seem to be only a few characters away from where the cursor is at, say i want to move one space to the right. Is this an incorrect workflow or is it just something that takes a while to become efficient?


First off, remap ESC. Way back in the day, when Vi was around, ESC was where the tab key is now and thus made sense to be used. However, nowadays, people usually remap ESC to Caps Lock or Ctrl+Caps Lock. Secondly, you can still use the arrow keys in insert mode if you want to move over one character instead of going ESC -> L -> I -> Text. Some people use a little hack to make it work (http://vim.wikia.com/wiki/Insert_a_single_character), but I personally have never minded it.

To use VIM efficiently, just remember to use the proper key-presses to navigate around the file, rather than just using HJKL. Here are some I use on an almost daily basis:

R = Replace single character
x = Delete single character
w = Go forward 1 word
b = Go back 1 word
gg = Go to top of file
G = Go to bottom of file
! = External command (e.g. !mkdir MooCowsAreKewl)
:xa = Save and close all windows/tabs (really useful when having multiple tabs open, or using NERDTree)

If you want to find more, you can always just look up all the key-bindings on the Internet. Happy VIM-ing!
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. -Rick Cook
User avatar
centip3de
Moderator
Moderator
 
Posts: 1412
Joined: Fri Aug 20, 2010 5:46 pm
Blog: View Blog (0)


Re: question for the vim users

Post by fashizzlepop on Wed Nov 06, 2013 3:42 pm
([msg=78069]see Re: question for the vim users[/msg])

Instead of hitting 'i' to go into insert, use 'a' and it will bring the cursor over to the right one spot before inserting.

You should never be using your mouse when in vim.
The glass is neither half-full nor half-empty; it's merely twice as big as it needs to be.
User avatar
fashizzlepop
Developer
Developer
 
Posts: 2304
Joined: Sat May 24, 2008 1:20 pm
Blog: View Blog (0)


Re: question for the vim users

Post by pretentious on Thu Nov 07, 2013 3:17 am
([msg=78078]see Re: question for the vim users[/msg])

Thanks for the responses. I had a look at http://stackoverflow.com/questions/397229/reaching-up-to-hit-the-escape-key-sucks-especially-in-vim and thought it would be a good idea to try jj and Ima play with the different commands. I'm starting to see advantages in things like '/' searching for a word then 'v' and 'w' then deleting. Good stuff
Goatboy wrote:Oh, that's simple. All you need to do is dedicate many years of your life to studying security.

IF you feel like exchanging ASCII arrays, let me know ;)
pretentious wrote:Welcome to bat country
User avatar
pretentious
Contributor
Contributor
 
Posts: 573
Joined: Wed Mar 03, 2010 12:48 am
Blog: View Blog (0)


Re: question for the vim users

Post by centip3de on Thu Nov 07, 2013 1:02 pm
([msg=78080]see Re: question for the vim users[/msg])

A few more good tips are:

'd' is your friend for deleting things. 'd' plus another letter, will delete the next thing following that rule. For example:
'dw' will delete the next word.
'dk' will delete the current line, and one line up.
'dd' will just delete the current line.

Visual mode is really cool for moving blocks of text. In visual mode (accessed to by hitting 'v'), some good commands are:

'>' Indents all highlighted blocks exactly 1 time.
'<' Unindents all highlighted blocks exactly 1 time.
'c' = cut
'p' = paste
'y' = copy (though it stands for yank)
'x' = delete all highlighted text
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. -Rick Cook
User avatar
centip3de
Moderator
Moderator
 
Posts: 1412
Joined: Fri Aug 20, 2010 5:46 pm
Blog: View Blog (0)


Re: question for the vim users

Post by fashizzlepop on Thu Nov 07, 2013 3:42 pm
([msg=78085]see Re: question for the vim users[/msg])

centip3de wrote:'>' Indents all highlighted blocks exactly 1 time.
'<' Unindents all highlighted blocks exactly 1 time.
'c' = cut
'p' = paste
'y' = copy (though it stands for yank)
'x' = delete all highlighted text



In Normal mode you can do similar things.

'>>' will indent the line you are on.
'25>>' will indent the line you're on as well as the next 24 lines.
'<<' same but indent.
'25dd' cuts 25 lines and p will then paste it.
'25yy' will yank 25 lines allowing you to paste.
The glass is neither half-full nor half-empty; it's merely twice as big as it needs to be.
User avatar
fashizzlepop
Developer
Developer
 
Posts: 2304
Joined: Sat May 24, 2008 1:20 pm
Blog: View Blog (0)


Re: question for the vim users

Post by -Ninjex- on Fri Nov 08, 2013 2:10 pm
([msg=78095]see Re: question for the vim users[/msg])

I'm sure you may have stumbled upon it already, but in case you haven't: http://www.openvim.com has great tutorials for vim.
If you're not willing to learn, no one can help you. If you're determined to learn, no one can stop you.⠠⠵
The absence of evidence is not evidence of absence.
I can explain it for you, but I can't understand it for you.
User avatar
-Ninjex-
Addict
Addict
 
Posts: 1184
Joined: Sun Sep 02, 2012 8:02 pm
Blog: View Blog (0)



Return to *nix

Who is online

Users browsing this forum: No registered users and 0 guests