Sunday, March 31, 2013

More Vim stuff, fix indentation and and remove blank lines

I've been using Vim as my ide, and it's been wonderful.

some additional cool things I've found.

you can have your whole file's indentation fixed with gg=G
it may be helpful to :set sw= and :set tabstop= to 4 or 2, and turn cindent on :set cindent, to handle brackets.

gg goes to the top of the file = fixes indentation, and GG does the same to the bottom of the file

you can erase blank lines with :g/^$/d

:g makes it a global command executed on all instances which match your search pattern, ^$ (start of line and end of line with nothing in between) matches blank lines, and d deletes

you might also use something like :g/^\s*$/d to remove all lines with either blanks or only whitespace

for Perl, I recently used :%s/\(\S\+\)\s*\(#.*\)/\r\U\2/g which cuts any comments from the end of a line and inserts them on a new line, in uppercase and :%s/\s*\(#.*\)/U\1/g which removes any spaces between a comment and the beginning of the line and makes the comment uppercase to be useful.



No comments:

Post a Comment