Wednesday, June 27, 2007
grip? Rip? darn! No, that doesn't work. Changes you back into insert mode.
cip? okay, yes.
g?ip? Yes, kinda silly though.
'ip' is just inner paragraph. You could do various kinds of inner blocks and quotes.
Wednesday, May 23, 2007
" Close a split and then open it in a new tab:
:ca tb let a=bufnr("%")
:command! Tb :let a=bufnr("%") | q | tabnew | exe "b ". a
" Close the current tab and open as a split in another existing tab:
:command! Ts :let a=bufnr("%") | tabprev | sp | exe "b ". a | tabnext | q | tabprev
:ca ts :let a=bufnr("%")
Note these obviously aren't that smart. If you have no splits, its not gonna act quite right. I've made the order open X, then close Y so that vim still has *something* open. Hopefully that means your Vim session won't disappear out from underneath you.
Yep, I just tested it out. Vim doesn't close, and the 'tb' command works fine regardless of the # of windows open. The 'ts' command acts a little funny when there is more than one split open in a tab. It removes one split, sticks it in another tab but doesn't completely remove the other tab b/c there's still a window in it. Not so bad. Just a little wierd.
Monday, May 21, 2007
Well, I had a chance to try the thing out and I have to say that I am happier doing:
:r ! diff -r --brief
and then making my own quick macro to diff any files mentioned in the diff results. I just like the ability to filter out any lines I already know aren't a factor in my diffing. The DirDiff plugin doesn't allow you to change the contents of the 'diff results'. Well, I was at first. Until I figured out all I had to do was type:
Then I could delete the 'results' screen willy nilly. Much better. It still complained if I tried to insert text or what not...so its kind of a toss up. If I needed to quickly copy the contents back and forth then this DirDiff tool would be just the thing.
The trouble is most of the time I'm actually looking for a needle in the haystack. Some little change in a text file is causing a world of havoc for me. I don't want to filter out 'types' of files, and copy whole swathes of differences between the trees. In this case, I think manually reading in the diff and recording your own little quick diff macro is the way to go. DirDiff is slightly too constrained in what it wants to let you do.
In summary: a good plugin if you need to copy back and forth changes, or you don't want to spend the extra 3 minutes it takes to record your own diffing macro. I've rated this script 'Helpful'.
Tuesday, May 15, 2007
:ruby VIM.command(String(rand(VIM::Buffer.current.count-1)+1) +"|d")
To repeat the command several times I couldn't think of anything better than a macro recording:
:let @l=':ruby VIM.command(String(rand(VIM::Buffer.current.count-1)+1) +"|d")^M'
Where '^M' is really Control-J cariage return. Then to do it...uh, 30,000 times I just typed 30000@l
Saturday, February 17, 2007
There was on my part some assumption that someone had already done what I wanted to do, which is to highlight each successive indent level in a file. This would be particularly helpful for python files, but other programming languages as well. The BlockHL looked like just what I was looking for. Interesting, and helpful, but not quite.
Delving into the documentation I eventually found after much scratching of the head how to do exactly what I wanted to. Piddling around with the highlight colors I came up with three variations. I think I like the right most one best.
|BlockHL syntax plugin||Progressively darker indenting, kinda loud.|
|Alternate coloring. Better.||Alternate color, with progressively darker shading. Best.|
I've posted the very simple coloring script on vim, as a script plugin. See its page for further details.
*** update ***
Well well well, apparently some poeple actually read my postings sometimes and call me out on my shoddy programming skillz. Yes, its true. This plugin only works with TABs. Maybe if I get less lazy, I'll make it work with the tabstop/shiftwidth settings for you non tab users.
Tuesday, February 06, 2007
For the most part only a few search replaces are required. Most of the tme I need to convert a dos batch to a bash script. The first round of conversion includes:
There is always additional work to do, but these replaces do most of the tedious portion for me.
Thursday, January 11, 2007
I often forget about the "newer" searching features in VIM's regular expression quiver: line aware regular expressions. Today, I needed to detect when certain requests had occured twice in a row without any response in between.
First, I grepped the patterns important:
grep "REQ\|RSP" file.txt | vim -
Then I searched for two REQ's in a row:
Tada! Wow, that was just so easy.
I haven't played with these kinds of regexps enough to know if you can extend it to say three lines in a row or say two lines with the pattern, and one without, etc. But, I expect it is quite possible with a little work.
Monday, January 08, 2007
Every now and then I have to read the results of a SQL query on the command line, and I find the following setup to work wonders in VIM. At least this works well with MySQL, as its command line query tool is kind enough to spit out the output in tab-delineated form.
Say you have a query to perform. Do the following:
echo "select * from tableX;" | mysql -uUser -pPassword databaseName | vim +'set scb sbo+=hor sbo-=ver nowrap ts=30 bt=nofile| sp | exe "norm \<c-w>j\<c-w>_\<c-e>"' -
This will automatically space out the tabs so you can see each of the search result columns with the data, and then it creates two panes - one for the column descriptions, and one for the data. The scroll options are setup so that you can navigate around the data and always see the column description with the data (particularly helpful for large result sets).
The only real improvement I can think of is to use the VIM dbext plugin. I often find myself on several different machines I don't use often enough to warrant customizing plugins/settings, so this quick and dirty sql result browser setting is very handy to have around.
Friday, January 05, 2007
Nevertheless, sometimes I do want to compose a message in VIM. When I do, its usually so that I can take advantage of the automatic formatting features in VIM. Here are the typical settings I use to setup a text editing session:
This gets me just the basics: when I insert/delete text in VIM, the text is automatically wrapped/unwrapped.
But I really want my numbered lists to be formatted correctly. In that case I add on an extra flag:
Of course, in VIM 7 you can add spell check to that:
Use the the z= command to find alternate spellings underneath your cursor.