VIM: The (un)official thread

This is a discussion on VIM: The (un)official thread within the Programming Book and Product Reviews forums, part of the General Programming Boards category; Hey I just noticed that vim won last year's LinuxQuestions.org's "Member's Choice Awards" for Best Text Editor by a whopping ...

  1. #16
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300

    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.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  2. #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

  3. #18
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    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).
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  4. #19
    Registered User
    Join Date
    Aug 2003
    Posts
    1,197
    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 Attached Images  

  5. #20
    {Jaxom,Imriel,Liam}'s Dad Kennedy's Avatar
    Join Date
    Aug 2006
    Location
    Alabama
    Posts
    1,065
    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.

  6. #21
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,246
    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.

  7. #22
    {Jaxom,Imriel,Liam}'s Dad Kennedy's Avatar
    Join Date
    Aug 2006
    Location
    Alabama
    Posts
    1,065
    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.

  8. #23
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,246
    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.

  9. #24
    {Jaxom,Imriel,Liam}'s Dad Kennedy's Avatar
    Join Date
    Aug 2006
    Location
    Alabama
    Posts
    1,065
    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?

  10. #25
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    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.
    Last edited by MK27; 08-16-2009 at 12:09 PM.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  11. #26
    Maz
    Maz is offline
    Registered User Maz's Avatar
    Join Date
    Nov 2005
    Location
    Finland
    Posts
    194
    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

  12. #27
    Registered User
    Join Date
    Jul 2007
    Posts
    131
    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)

  13. #28
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    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.
    Last edited by MK27; 08-31-2009 at 11:46 AM.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  14. #29
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    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.

  15. #30
    Registered User
    Join Date
    Jul 2007
    Posts
    131
    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.

Page 2 of 3 FirstFirst 123 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 02-26-2009, 10:48 PM
  2. Terminating secondary thread from another thread
    By wssoh85 in forum C++ Programming
    Replies: 13
    Last Post: 12-19-2008, 04:14 AM
  3. CreateThread ?!
    By Devil Panther in forum Windows Programming
    Replies: 13
    Last Post: 11-15-2005, 09:55 AM
  4. pointer to main thread from worker thread?
    By draegon in forum C++ Programming
    Replies: 2
    Last Post: 10-27-2005, 06:35 AM
  5. Critical Sections, destroying
    By Hunter2 in forum Windows Programming
    Replies: 4
    Last Post: 09-02-2003, 10:36 PM

Tags for this Thread


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