Thread: VIM: The (un)official thread

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    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. #2
    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. #3
    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. #4
    Registered User
    Join Date
    Aug 2003
    Posts
    1,218
    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.

  5. #5
    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)

  6. #6
    {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.

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

  8. #8
    {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.

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

  10. #10
    {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?

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

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

  13. #13
    Registered User
    Join Date
    Aug 2009
    Posts
    198
    I occasionally play around with vim, and it has a lot of commands that I like that don't exist on other editors (especially "o"), though it still puts me off that I have to switch modes to reposition the cursor. And I do remap my caps lock key to ESC, it is much faster to press and strains my hand less, and I would say that Caps Lock is 99% nuisance and 1% helpful anyway.

    I also think that GVIM is better when possible (I don't use the mouse and menus, I like it because I find the shape-changing cursor very handy).

  14. #14
    and the hat of copycat stevesmithx's Avatar
    Join Date
    Sep 2007
    Posts
    587
    I've been using vim for a few days now. Darn good editor for touch typists. Every key seems to have a feature in normal mode. Initially I was annoyed by this, as i would accidentally turn some feature ON (like macro instead of exiting (by typing 'q' instead of ':q') but later as I understood them, I was really surprised at how easy and productive vim can be.

    My previous post seems to be deleted during the restoration of server backup. Anyways here is the link to the google video where Bram Moolenaar delivers a lecture on effective text editing using Vim.
    7 Habits For Effective Text Editing 2.0 that i posted previously.

    Another good article article on why you should use vi:
    Why, oh WHY, do those #?@! nutheads use vi?
    Not everything that can be counted counts, and not everything that counts can be counted
    - Albert Einstein.


    No programming language is perfect. There is not even a single best language; there are only languages well suited or perhaps poorly suited for particular purposes.
    - Herbert Mayer

  15. #15
    Registered User
    Join Date
    Jul 2010
    Posts
    86
    I gave it up. I had a sudden realization that Vim had become just as big as the programming. Training myself on the commands, trying out plugins, developing the dexterity to not hit a stray key and end up saying, "WTF" aloud.

    I'd much rather just be a little bit slower, but worrying a lot more about what I'm doing than how speedy and badass I am while doing it. I'm using a barebones IDE named Geany on Ubuntu for when I need that type of thing currently.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 02-26-2009, 11:48 PM
  2. Terminating secondary thread from another thread
    By wssoh85 in forum C++ Programming
    Replies: 13
    Last Post: 12-19-2008, 05:14 AM
  3. CreateThread ?!
    By Devil Panther in forum Windows Programming
    Replies: 13
    Last Post: 11-15-2005, 10: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