Advertisement
Advertisement
-
Re: Tips Thread
Wed, October 22, 2003 - 4:40 PMWhat constitutes new?
" Put the current line in register y, then
" run the commands in it.
" Mnemonic: * marks executible files in 'ls -F'
map * "yyy@y
One of my most used macros. It allows me to type a command out, hit esc, and run it. Often I use it for :r! commands and for complex :s/// stuff that I might need to run, undo, debug, and run again.
-
Unsu...
Re: Tips Thread
Tue, October 28, 2003 - 10:47 AMIf certain commands seem to lack certain features (i.e. the 'e' command not having tab completion) you might want to make sure your default shell offers those features. In certain types of BSD the default shell is csh (not tcsh) which doesn't support tab completion. -
-
Re: Tips Thread
Tue, October 28, 2003 - 11:07 AMGood tip, i'd be lost without tab completion.
Here is a fun one for new vi'ers.
Put this in your .vimrc to break yourself of arrow navigation, now they will toggle between open buffers. Worked like a charm when i was getting started.
"remap arrows to buffer navigation
noremap <left> :bn!<cr>
noremap <right> :bp!<cr>
noremap <down> :blast!<cr> -
-
Unsu...
Re: Tips Thread
Wed, November 5, 2003 - 10:18 AMWhat a bunch of geeks......... :-}
Ok, I am past that now.
Fairly new to the vi thing, got started on it while working on a project and was amazed at how
much faster my co-workers could get their editing done.
Oh yeah, get to the point.
Not sure I understand what this modification is going to do for me.
(y o u h a v e t o t a l k r e a l s l o w)
Another thing that is bugging me, everytime I am in vi I want to grab my mouse, the dual operation mode is driving me batty, any help breaking the mouse habit? -
-
Re: Tips Thread
Wed, November 5, 2003 - 4:06 PMunplug it. ;)
but seriously... mouse habit is hard to break. Though it is still useful for say pasting from a putty session into some other window or visa versa.
Other than putting it on top of your monitor while you code i don't know what to suggest for you. -
-
Re: Tips Thread
Wed, February 11, 2004 - 3:50 AMPut your mouse away just because you're coding? This is _insane_! It's true that you hardly ever need to do things like copy&paste when programming, and that you can learn to move your cursor around really quickly and efficiently just with the keyboard, but when I want to quickly mark up a block of text, you know, "select everythign from HERE to THERE", I really can't see why it would be bad to do that with my pointing device. For example, I select a few lines of code and then say, "now put a 'try/catch' block around these lines, which catches every checked exception that could be thrown in these lines, so I only have to fill in the exception handling code." This is exactly what pointing devices are there for, they're much better at it than keyboards.
Of course, other people use vi for other tasks. If you're writing text and need to select exactly the last paragraph you just wrote, and you do exactly that _often_, it's of course beneficial to learn the appropriate keyboard shortcut, so you don't have to move your hand over to the mouse every time. However, imagine one time you have to select the last paragraph, next time you have to select the last but one paragraph, next time you have to select the next paragraph except for the first and the last line, and so on. In that case, I just can't imagine you'd benefit from 'breaking your mouse habit'. This just reminds me of guys who are proud to be be Real Programmers(tm) who use ancient, clunky systems and tell others that these are really better than modern software, mainly so they're admired for their obscure, elite hacking skills. I'd say, use the mouse, but use it wisely. -
-
Re: Tips Thread
Wed, February 11, 2004 - 1:41 PM" Put your mouse away just because you're coding? This is _insane_!"
Guess I'm crazy then.
"It's true that you hardly ever need to do things like copy&paste when programming"
Um, sure I use cut&paste all the time. Things like that printf is very close to what I need, I'll just put a copy here and edit to fit.
"but when I want to quickly mark up a block of text, you know, "select everythign from HERE to THERE", I really can't see why it would be bad to do that with my pointing device."
Suit yourself, but I use marks. Between the 'f', 't', '/', '?', '#', '*', '?', '/', 'L', 'H', 'M', 'G', '|', '{', '}', '^', '$', '%', and ':num' commands I can move around pretty fast in vi. (Though '*' and '#' are vim only, and I have remaped '*' to '_'.)
"This just reminds me of guys who are proud to be be Real Programmers(tm) who use ancient, clunky systems and tell others that these are really better than modern software,"
But Ed is the standard text editor!
www.cs.hmc.edu/~smikes/emacs/ed.html
"I'd say, use the mouse, but use it wisely."
It is handy for changing window focus quickly. -
-
Re: Tips Thread
Wed, February 11, 2004 - 5:53 PMCopy&paste programming, a.k.a. snarf&barf programming, is usually a mistake. If you write good, clean code, and use copy&pasting in the process, of course there's nothing wrong with that. In my projects, I usually don't consider that option though, because clone&modifying isn't really comfortable when you have the power of a smart editor (read: IDE). If I need a printf(""); with the cursor between the double quotes, ready to fill in some text, I just type pri and hit ctrl+space. The clone&modify methode pales in comparison.
OTOH, I occasionally see code in which it clearly shows that it was created by copy&paste programming. In that case, that's a CodeSmell ( c2.com/cgi/wiki ) and violates many principles of good software development.
The marks feature is of absolutely no help in the problem I described above, as you can only jump to marks you placed before. If I want to move the cursor 17 lines up, the appropriate :num command is only helpful if I _know_ that the target line is exactly 17 lines above, which I usually don't. I know that there are people who can navigate with keyboard commands really really quickly, and I don't doubt that you're a master of that art, but I'd say just pointing at the spot where I want the cursor to be isn't so bad either.
Anyway, I don't doubt you know what you're doing, I just wanted to point out that in most situations "breaking the mouse habit" altogether is a bit over the top, and hiding your mouse clearly is something that belongs in the 'jokes' directory, right next to ed.html.
-
Re: Tips Thread
Thu, March 4, 2004 - 9:53 PMAt the company I work for when they hired the network administrator they harassed him into thinking that we were an emacs shop to see if he would stand up for Vi. He did, we hired him. ;)
it went something vaguely like this:
"So what editor do you prefer?"
"Vi."
"Would you consider using emacs?"
"uh, why would I?"
"Well if you had to use emacs, would you?"
"well, if I had to, but really I'd just install Vi."
lol
-
-
-
-
-
Re: Tips Thread
Thu, November 6, 2003 - 6:38 PMHeh, I like using my arrow keys. I'm also going to be looking into how to define your own syntax highlighting as currently I'm lacking a good highlighter for perl code. I'm sure someone has written one already, but it'll be a good learning experience for me. -
-
Re: Tips Thread
Wed, November 12, 2003 - 8:50 AMI used to use my arrow keys, too. I didn't even consciously wean myself off them, the home-row letter keys just grew on me.
What version of vim are you using? I assume you're using vim.
If you are, it should have built-in highlighting for Perl. On my RedHat system, it's located in
/usr/share/vim/vim61/syntax/perl.vim
I have written a syntax highlighting file. It's challenging but not too difficult, especially if you've got any experience with regular expressions.
For information on writing a syntax file, type
:help syntax
...which has an overview of syntax highlighting in general, and a link to usr_44.txt, which tells you how to write your own definitions.
But you really shouldn't need to write one for perl, unless you're just unhappy with the existing one. -
-
Re: Tips Thread
Thu, November 13, 2003 - 11:10 AMI hate syntax highlighting, and I'm sure I can come up with valid perl that will confuse any syntax highlighter yet made.
#!/usr/bin/perl
$_ = qq qjust another perl hackerq;
s s(\b[japh])suc$1seg;
print
__END__ -
-
Re: Tips Thread
Wed, February 25, 2004 - 8:40 PMWe can only assume then that he prefers maintainable code. -
-
Re: Tips Thread
Thu, February 26, 2004 - 3:00 PMI prefer not to trust third party parsers. The compiler and the reader need to understand it, not the editor. -
-
Re: Tips Thread
Wed, March 3, 2004 - 2:35 PMI find syntax highlighting makes it much easier for the "reader" to understand, at least when that reader is me. Sometimes the syntax is incorrectly highlighted. My forgiving nature allows for these small transgressions.
Good thing we aren't forced to write/edit code in each other's environments of choice. ;)
-
-
-
-
-
-
-
-
Re: Tips Thread
Tue, February 10, 2004 - 10:18 AMwow!
vim never ceases to impress me.
export current source file to html WITH current env. syntax highlighting:
:runtime! syntax/2html.vim
-
Re: Tips Thread
Thu, March 11, 2004 - 10:19 PMFor tab completion freaks...
Having trouble locating a :help topic?
try...
:help string<ctrl-D>
rather than just cycling the tab complete options... it spits them all out for you to see. Similiar to bash behavior.
-
-
Re: Tips Thread
Sun, April 18, 2004 - 10:52 PMnice avitar! Wallace and Grommit rock! -
-
Re: Tips Thread
Mon, April 19, 2004 - 2:28 PM -
-
Re: Tips Thread
Sun, April 25, 2004 - 12:42 AMthanks for the link, now i am. :)
-
-
-
-
Re: Tips Thread
Tue, June 15, 2004 - 2:15 AMI've recently re-discovered CTRL-X mode and am loving it again.
while in insert mode (vim):
<ctrl>x
(lists other ctrl-foo combinations in this mode)
auto-complete current word using current file as dictionary:
ctrl-x is completely optional with this one:
<ctrl>n i.e next word match
<ctrl>p i.e previous word match
auto-complete current word using vim enviorment dictionary set
up by you:
<ctrl>x <ctrl>k <ctrl>n (next)
<ctrl>p (previous)
auto-complete current line using current file as match source:
<ctrl>x <ctrl>l (line match)
<ctrl>n (next line match)
<ctrl>p (previous line match)
scroll window without leaving insert mode:
<ctrl>x <ctrl>y (up)
<ctrl>e (down)
I don't find the other ones that useful but then maybe i'm doing something wrong ;)
-
Re: Tips Thread
Thu, September 29, 2005 - 5:30 PMI'm a whitespace neatnik, and end up maintaining code written by people who don't understand the difference between a tab character and several space characters. Clean whitespace is next to godliness.
So I wrote these snippits, to visually display tab characters, EOL characters and trailing spaces.
"""""""""""""""""""""""""
" Display special characters
set list
" Display special characters as DarkGray, to keep them subtle against
" a black background.
highlight SpecialKey ctermfg=DarkGray
" Display tabs with ". " trailing spaces with ....
set listchars=tab:.\ ,trail:.
" Display end-of-line character with a Pilcrow character
" Terminal must support Unicode
set listchars=eol:¶
"""""""""""""""""""""""""
These work in VIM, and work in VIM's compatability mode.
Ideally, I want to display a tab as an ellipsis (…) or something other then a period. But if I save a file containing an ellipsis, VIM throws the error "CONVERSION ERROR". I just haven't investigated why this happens.
I bet your browser needs to support UTF-8 to see the Pilcrow character.