0

I have been using the Sublime editor and is making a switch to vim (Because I have to) . I have heard that Vim is the best editor there is, if you can master all the shortcuts. Given below are some of my needs. Please tell me which shortcut/plug-in I should use to achieve them.

  1. Switch-case statement in C : I need like 10 cases. So How can I add them quickly? Is there something like case n:10+ ?
  2. Curly Bracket completion : I need an auto closing curly bracket }. Same need with parenthesis.
  3. In CSS : Code completion for properties.
  4. Code shrink option : In Sublime u could shrink the code present in a block (like a function or loop) by pressing an > like symbol to the left of line number. Is this possible in Vim?
  5. Any other shortcut / plug-in that programmer ( C, C++, php, CSS, HTML ) can use to increase his/her productivity.

Any help is appreciated.

0aslam0
  • 1,797
  • 5
  • 25
  • 42

2 Answers2

2
  1. Switch-case statement in C : I need like 10 cases. So How can I add them quickly? Is there something like case n:10+ ?

    ocase :<CR>break;<Esc>
    9.
    

    See :help repeating.

    Take a look at SnipMate or Ultisnips, though.

  2. Curly Bracket completion : I need an auto closing curly bracket }. Same need with parenthesis.

    That "feature" is not that useful but if you didn't already grow tired of it, you can find a good list on the Vim wiki..

  3. In CSS : Code completion for properties.

    It's built-in. Try <C-x><C-o> after a couple of characters. If you don't like the default <C-x><C-o>, create your own with:

    inoremap <key> <C-x><C-o>
    

    See :help key-mapping and :help key-notation.

  4. Code shrink option : In Sublime u could shrink the code present in a block (like a function or loop) by pressing an > like symbol to the left of line number. Is this possible in Vim?

    That feature is universally called "folding". You can close a fold with zc, open it with zo, toggle it with za and much more. See :help folding.

  5. Any other shortcut / plug-in that programmer ( C, C++, php, CSS, HTML ) can use to increase his/her productivity.

    Learn Vim before looking for plugins.

romainl
  • 186,200
  • 21
  • 280
  • 313
  • Thank you. I am thorough with the basics of vim. – 0aslam0 Oct 02 '14 at 15:07
  • I'd recommend "surround", and either Taglist or Tagbar, for any coding. Other than that it really comes down to preferences...there are a LOT of good plugins out there and you won't ever find a definitive list of "must have" plugins. Such a list would be off-topic on StackOverflow anyway. There is a software recommendations stack exchange where that is on-topic: http://softwarerecs.stackexchange.com – Ben Oct 02 '14 at 16:03
1
  1. With a ctags database correctly configured and up-to-date, if your switch is on an enum, then lh-cpp provides (through mu-template) the CTRL-X_se mapping that will generate your switch-case. If your want to generate it from integers, it will be possible (but a little bit tricky without mappings/commands to encapsulate it)

    :call MuTemplate('c/switch', {'values':reverse(range(1,5)), "name": "foo"})

  2. lh-cpp embeds lh-brackets that'll offer a nice brackets support.

  3. (SO renumbers 4 to 3 if I write no "3." -> this empty and useless answer)

  4. This is called folding in Vim. Usually people are using syntax or indent foldingmethod. I got tired of it and reworked and old plugin for C and C++ -- the plugin still needs many improvements.

  5. There are many. In C and C++ YouComplete is a must have. Then I use my plugins to integrates CMake, have a project notion. Other people use other things. There is no definitive answer to this question.

Luc Hermitte
  • 31,979
  • 7
  • 69
  • 83
  • Thank you. Can you send me link about this ctags database please. I can't digest all of it. Any cheatsheat or reference would suffice – 0aslam0 Oct 02 '14 at 12:07
  • You'll need a software like _exuberant ctags_ installed. Then, For your given project you'll need to tell vim where to find the tags files (`:h tags`). And regarding C++, I generate my ctags database with the following options: `--c++-kinds=+p --fields=+imaS --extra=+q --language-force=C++` (and I do it through 2 plugins: one for project management, and one for generating ctags DB, plus some tuning) – Luc Hermitte Oct 02 '14 at 12:16