C Board  

Go Back   C Board > General Programming Boards > Programming Book and Product Reviews

Reply
 
LinkBack Thread Tools Display Modes
Old 05-09-2009, 10:15 AM   #16
critical genius
 
MK27's Avatar
 
Join Date: Jul 2008
Location: SE Queens
Posts: 5,166
Cool Vim wins LinuxQuestions User Poll!

Hey I just noticed that vim won last year's LinuxQuestions.org's "Member's Choice Awards" for Best Text Editor by a whopping margin (400 to 2nd place gedit at 155, out of a field of 15!*). Much surprised.

Also surprised: Midnight Commander, the *second* best piece of software of all time, placed 3rd in "File Manager". Under "Best Programming Langauge", Python beat C++ 226 to 129...

*IDE's were in a seperate catagory, but the winner there (Eclipse) only recieved 129 votes.
__________________

"A man can't just sit around." -- Larry Walters
MK27 is offline   Reply With Quote
Old 05-09-2009, 10:17 AM   #17
Complete Beginner
 
Join Date: Feb 2009
Posts: 312
:s/<regexp>/<replace>/g
Replaces <regexp> with <replace> globally.

:v
:V

Start selecting text per character/per line.


:y
..."yank", i.e. copy the selected text...

:p
:P

...and paste at the current cursor position or the next one.

:r
Enter replace-mode for exactly one character. Handy for fixing typos.

:help uganda
Make Bram Moolenaar happy.

Greets,
Philip

PS: what is an emac and why do I need several of them to edit text?
__________________
All things begin as source code.
Source code begins with an empty file.
-- Tao Te Chip
Snafuist is offline   Reply With Quote
Old 05-10-2009, 09:49 AM   #18
critical genius
 
MK27's Avatar
 
Join Date: Jul 2008
Location: SE Queens
Posts: 5,166
Quote:
Originally Posted by Snafuist View Post

:v
:V

Start selecting text per character/per line.
Sorry, Snafusist, but this is wrong; a command prefaced by a colon is an "ex"tended command that appears at the bottom allowing you to add extensions. ":v" is a real ex command not to be confused with just pushing "v" while in ex mode, which I think is what you meant. "v" enters VISUAL mode where you can select text (personally, I prefer yy & yw).

I won't try and describe ":v" since I never use it except to say that is a variant of ":g", which is incredibly useful. Let's say you have a block of text containing some printf lines that all have some character or sequence in them (eg, "+") that you want to replace all instances of (with "->"), but you don't want to replace "+" globally. You could go line to line and just repeat the command
:s/+/->/
which since you won't have to type that more than once, is pretty easy. Now say there are twenty of them, on every other line (and the line in between has a + you want to leave). That's ":g"
:11,46g/printf/s/+/->/
"11,46" limits the command to lines 11-46 (otherwise global). "printf" -- only lines containing printf. The next part (beginning with "s") can be any other command (except, unfortunately, another g, but you can make up for that with a little regexp know-how in your pattern) -- in this case the substitution.
:v is a slightly useless seeming variation you'll have to look up yourself

Quote:
Originally Posted by Snafuist View Post
:r
Enter replace-mode for exactly one character. Handy for fixing typos.
This is why I like using the actual "Insert" key to enter "insert" mode: because if you press Insert in insert mode, you can switch in and out of "replace" (just like most other places in the universe).
__________________

"A man can't just sit around." -- Larry Walters
MK27 is offline   Reply With Quote
Old 05-21-2009, 09:24 AM   #19
Registered User
 
Join Date: Aug 2003
Posts: 782
To get code completion to work with vim:
http://blogs.gnome.org/lharris/2008/...on-with-vim-7/

When you are done with that i suggest you run
:h omnicppcomplete
in vim and check through chapter 4 to see what options you can change. For instance to have prototypes show up in the dropdown list you add this line to your .vimrc file:
let OmniCpp_ShowPrototypeInAbbr=1

To get rid of the preview window add this to .vimrc
set completeopt=menuone,menu,longest

If you dont have any colorscheme by default i suggest you add this to .vimrc
colorscheme default

This however has some uglyass colors for the dropdown (magenta and a completely white line) so i added these lines to the default.vim file in /usr/share/vim/vim71/colors/
let colors_name = "default"
hi Pmenu ctermbg=3 ctermfg=0
hi PmenuSel ctermbg=3 ctermfg=1
hi PmenuSbar ctermbg=7
hi PmenuThumb ctermbg=0 cterm=NONE

Ive included a screenshot of my vim with these settings. To see a list of colors you can use go here:
Vim documentation: syntax
And scroll down to cterm-colors section.
Attached Images
 
Shakti is offline   Reply With Quote
Old 08-06-2009, 03:42 PM   #20
Jaxom's & Imriel's Dad
 
Kennedy's Avatar
 
Join Date: Aug 2006
Location: Alabama
Posts: 874
Maybe you folks already know this, but maybe you don't. One of the coolest things I found lately is CTRL-SHIFT-v for block select. Comes in really handy from time to time.

NOTE: this is NOT the same thing as v or V as those are character and line select.
Kennedy is offline   Reply With Quote
Old 08-06-2009, 03:46 PM   #21
Registered User
 
Join Date: Sep 2004
Location: California
Posts: 3,020
Quote:
Originally Posted by Kennedy View Post
Maybe you folks already know this, but maybe you don't. One of the coolest things I found lately is CTRL-SHIFT-v for block select. Comes in really handy from time to time.

NOTE: this is NOT the same thing as v or V as those are character and line select.
Hmm, I've never heard of that, and it didn't work in my version of VIM. I usually use v-% to select a block.
__________________
bit∙hub [bit-huhb] n. A source and destination for information.
bithub is offline   Reply With Quote
Old 08-06-2009, 03:50 PM   #22
Jaxom's & Imriel's Dad
 
Kennedy's Avatar
 
Join Date: Aug 2006
Location: Alabama
Posts: 874
Quote:
Originally Posted by bithub View Post
Hmm, I've never heard of that, and it didn't work in my version of VIM. I usually use v-% to select a block.
You have to be in command mode (didn't say that part). Try that again. I'm using
Quote:
Originally Posted by vim
VIM - Vi IMproved 7.2 (2008 Aug 9, compiled Sep 17 2008 01:21:50)

EDIT: What I've been using it to do is to block copy my enums to put into switch case statements. I can dup case : then paste it in between the case and :.

Last edited by Kennedy; 08-06-2009 at 03:53 PM.
Kennedy is offline   Reply With Quote
Old 08-06-2009, 04:36 PM   #23
Registered User
 
Join Date: Sep 2004
Location: California
Posts: 3,020
I was in command mode, so that's not it. I'm using VIM 7.0, so I guess it may be a version issue. I also have set up quite a few custom commands in my vimrc, so one of those may be conflicting with (and messing up) the ctrl-shift-v. At any rate, I think v-% does the same thing (unless I misunderstand what you mean by block select), so I'm not missing out on anything.
__________________
bit∙hub [bit-huhb] n. A source and destination for information.
bithub is offline   Reply With Quote
Old 08-13-2009, 09:20 PM   #24
Jaxom's & Imriel's Dad
 
Kennedy's Avatar
 
Join Date: Aug 2006
Location: Alabama
Posts: 874
What is v-%???? When I do that all that happens is that it smart selects a block of code. What I'm talking about is something like this:
Code:
1234567
1234567
1234567
1234567
then do a ctrl-shift-v on the 3, press right arrow then down the colum, then d to delete just 3 and 4 from each line. . . get it?
Kennedy is offline   Reply With Quote
Old 08-16-2009, 11:16 AM   #25
critical genius
 
MK27's Avatar
 
Join Date: Jul 2008
Location: SE Queens
Posts: 5,166
They are different:

v-% is VISUAL
ctrl-v is VISUAL BLOCK

Here's my new found vim feature. I'm always using either remote from file browser to load (see first post in this thread) or :e. The problem with :e is there is only macro, #, which is the last file edited. I'd really prefer a list of all the files I have been editing this session. So it turns out

:b

will do that; regardless of how the file was loaded, if you now type the first few characters of it's short name, you can get a tab completion of the full path and return loads the file same as :e.

Another new found thing:

:set wildmenu

This will give you a horizontal bar of possibilities when using tab completion with any command (or no command, eg, :br tab will give you a bar of possibilities beginning with br). Without wildmenu on, tab completion starts with the first cantidate...

And another: you can add your own commands to abbreviate others with options, etc, using :command. So here's a nice one for the .vimrc:

command SpellOn setlocal spell spelllang=en_us
command SpellOff setlocal nospell


As usual there is more advanced syntax for including parameters, etc. So now, with wildmenu on, you just type :Sp, hit tab, and you will get a choice between SpellOn and SpellOff.
__________________

"A man can't just sit around." -- Larry Walters

Last edited by MK27; 08-16-2009 at 12:09 PM.
MK27 is offline   Reply With Quote
Old 08-30-2009, 02:14 PM   #26
Maz
Registered User
 
Join Date: Nov 2005
Posts: 150
Well, my most used vim things.

1. run ctags -R in root of your source folders.
2. edit vimrc so vim can find the tags file ( set tags=./tags;../../../../ )

Now, when you want to find the implementation of some function, definition, enum, ..., ... just save file, move cursor on name, and press ctrl+altgr+]
Then ctrl+t will bring you back.
Autocompletion with ctrl+n

What I also do, :new <filename> to split the window and open new file to splitted part. ctrl+ww will change active window.
Running shell commands
:!command
Running shell commands and reading output to file (I use this to correct compile bugs by splitting window when source file is open, and runnin make in empty window.)
:r!command
Maz is offline   Reply With Quote
Old 08-31-2009, 06:48 AM   #27
Registered User
 
Join Date: Jul 2007
Posts: 62
Quote:
Originally Posted by MK27 View Post
a command prefaced by a colon is an "ex"tended command that appears at the bottom allowing you to add extensions. ":v" is a real ex command not to be confused with just pushing "v" while in ex mode, which I think is what you meant. "v" enters VISUAL mode where you can select text (personally, I prefer yy & yw).
Er, command that begins is with colon is a ex command, which means that the command means same thing in ex and in vi. That means, entering v in ex prompt means same thing as entering :v in vi. So you can not confuse command v and "just pushing v while in ex mode", because they are the same thing.

Or, that's the case in nvi which I use (current version of original vi, read about lawsuits if you want to hear more). I believe the situation is the same in vim and other clones.

EDIT: Yay, emacs lost pitifully in linuxquestions poll. 8)
fronty is offline   Reply With Quote
Old 08-31-2009, 11:40 AM   #28
critical genius
 
MK27's Avatar
 
Join Date: Jul 2008
Location: SE Queens
Posts: 5,166
Quote:
Originally Posted by fronty View Post
That means, entering v in ex prompt means same thing as entering :v in vi. So you can not confuse command v and "just pushing v while in ex mode", because they are the same thing.

Or, that's the case in nvi which I use (current version of original vi, read about lawsuits if you want to hear more). I believe the situation is the same in vim and other clones.
I don't use vi, but what I said in that post is true for vim. :v and v ARE NOT THE SAME. I even documented the difference between them. Did you think my explanation of the :v command (which is different than VISUAL, just try it*) referred to some kind of hallucination of something that does not exist?

* you could also just look at "help v" and "help :v" for the difference.
__________________

"A man can't just sit around." -- Larry Walters

Last edited by MK27; 08-31-2009 at 11:46 AM.
MK27 is offline   Reply With Quote
Old 08-31-2009, 12:09 PM   #29
and the Hat of Guessing
 
tabstop's Avatar
 
Join Date: Nov 2007
Posts: 8,809
Quote:
Originally Posted by MK27 View Post
I don't use vi, but what I said in that post is true for vim. :v and v ARE NOT THE SAME. I even documented the difference between them. Did you think my explanation of the :v command (which is different than VISUAL, just try it*) referred to some kind of hallucination of something that does not exist?

* you could also just look at "help v" and "help :v" for the difference.
He means that what you are calling "ex mode" is called "command mode" and that what is actually called "ex mode" is something else.
tabstop is offline   Reply With Quote
Old 09-01-2009, 11:17 AM   #30
Registered User
 
Join Date: Jul 2007
Posts: 62
You are free to try v in ex and :v in vi. I think you will notice that commands that begin with : in vi are same as ex commands. :/

ex commands are commands of line editor ex. ex's prompt is colon, hence vi's command line commands begin with colon (with some exceptions). If you enter a command that begins with colon in visual mode, you are really executing ex's command with same name and syntax and meaning. In fact ex and vi are the same program, it just has two user interfaces, line editor interface and screen editor interface. Visual mode has some commands that aren't present in line editor mode and they share some commands.

EDIT: And by visual mode I mean screen editor mode, the mode you can enter with ex command vi.
fronty is offline   Reply With Quote
Reply

Tags
"vi", vim
Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
pthreads, I created the thread, passed a function, function never runs. mr_coffee Linux Programming 2 02-26-2009 11:48 PM
Terminating secondary thread from another thread wssoh85 C++ Programming 13 12-19-2008 05:14 AM
CreateThread ?! Devil Panther Windows Programming 13 11-15-2005 10:55 AM
pointer to main thread from worker thread? draegon C++ Programming 2 10-27-2005 06:35 AM
Critical Sections, destroying Hunter2 Windows Programming 4 09-02-2003 10:36 PM


All times are GMT -6. The time now is 11:51 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22