Блог пользователя duckladydinh

Автор duckladydinh, история, 6 лет назад, По-английски

Hi Codeforcers,

I often hear people talking about the greatness of VIM and that many red coders use VIM for competitions and VIM is so extensible and powerful of all sorts with numerous plugins available. I also tried some default configurations on the Internet and it looked not that terrible, but since VIM depends so much on plugins to be a great IDE, I am really curious how you installed them during a contest without Internet connection?

Can VIM users share your experience in using VIM for CP :)? I really want to find a good IDE for C++ :V. Even CLion is not too nice :'( .

Thank you so much.

  • Проголосовать: нравится
  • +17
  • Проголосовать: не нравится

»
6 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

You pretty much can't install any plugins so you just don't do it. If you become somewhat proficient at it you can use it barebone with the simplest setup. In my case, I always change indention and that's it. VIM with plugins is great but VIM without plugins is not bad either. You just have to get used to it.

  • »
    »
    6 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    Thank you very much :'( and I got my hopes up for nothing. The same happens to VS Code, when it is installed without C++ extension and others.

    Wonder why they can't just provide some nice standard configuration :V?

»
6 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

I started using VIM with the mindset of using it in CP. So I didn't use any plugin to start with. Also got used to the shitty color schemes that comes with VIM (I use 'morning') :3 My vimrc is also 4-5 lines that I can write myself during contest. So, I don't face any problem using VIM in onsite contests. :D

For fast compiling, I pre-compile headers and add this line at the beginning of my code:

Then do chmod +x main.cpp. Now I can compile + run with just switching tab and ./main.cpp. :D

  • »
    »
    6 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    You can do it simpler way. Vim has :make command which by default invokes make program, but you can change it by setting makeprg option. Add to your .vimrc the following line and restart Vim:

    makeprg=g++\ -g\ -std=c++17\ -Wall\ -Wextra\ -Wshadow\ -o\ %< %

    As you can see each space must be escaped with \. % is the Vim variable which holds filename of the current file and %< is the variable which holds filename without extension. Now if you edit e.g. test.cpp file you can compile it at any time by issuing :make command in Vim. It will invoke:

    g++ -g -std=c++17 -Wall -Wextra -Wshadow -o test test.cpp

    This of course isn't faster than switching tab and invoking ./main.cpp so let's make it faster. In Vim you can map command to keys. Vim works in two modes: insert mode — in which you actually type code, and normal mode — in which you invoke Vim commands. To map key in insert mode you use imap and to map key in normal mode you use nmap. Let's map F9 key as the compile command key. Add the following lines to your .vimrc and restart Vim:

    imap <F9> <Esc>:w<CR>:make<CR> — When you will press F9 it will: exit insert mode, save file, compile file.

    nmap <F9> :w<CR>:make<CR> — In normal mode it's the same except we don't exit insert mode

    Now compilation is as simple as pressing F9 :)

    By using imap and nmap you can map much more for example invoking gdb:

    imap <F10> <Esc>:!gdb %< <CR>

    nmap <F10> :!gdb %< <CR>

    • »
      »
      »
      6 лет назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      It is better to prepend these commands with autocmd FileType cpp: in CP (or SP?) and in real world we switch between languages in VIM: python, bash etc. For example, I want python not to be compiled with g++ but run with python3

      All my bindings

      So, F8 —  run any file, C-F9 —  compile, F9 —  compile & run
      P.S. I wish CF had monospaced font

      • »
        »
        »
        »
        4 года назад, # ^ |
          Проголосовать: нравится -8 Проголосовать: не нравится

        which font do u use for vim?

        • »
          »
          »
          »
          »
          4 года назад, # ^ |
            Проголосовать: нравится 0 Проголосовать: не нравится
          Bundle 'altercation/vim-colors-solarized'
          
          let g:solarized_termcolors=256
          colorscheme solarized
          set background=dark
          
  • »
    »
    6 лет назад, # ^ |
    Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

    I find something like this simpler. When the file is saved with :w , it also compiles using g++. In order to do this, I have the following in my .vimrc file:

    :autocmd BufWritePost *.cpp !g++ <afile>
    

    Now whenever I save, the errors are shown inside Vim and I can run in another terminal ./a.out

    I don't know whether this will work with multi-file setups.

»
6 лет назад, # |
  Проголосовать: нравится -18 Проголосовать: не нравится

just don’t use vim it was made by a schitsofrenic man. use nano like normal people.

  • »
    »
    6 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    Normal people would use Visual Studio Community to edit text file :) and Word to code.

    Serious :3 : I cannot see why you would use nano? It is not popular like VIM. It lacks beauty and functions compared to SUBL, VSCode... Just why?

    • »
      »
      »
      6 лет назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      ohhh yeah right you wanna be a cool hacker kid you need PROFRSSIONAL programs to be able to CODE better. make it all green and black to code better evaluate that’s what matters.

  • »
    »
    6 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    you can't be serious? if you're not using ed you might as well stop coding at all

»
6 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

I use vim for all languages, except for based on JVM: for them IDEA with vim plugin is best choice (although plugin hasn't full support of all features, has many bugs, it supports basic functionality and helps a lot)
For C++ only one plugin is needed: Valloric/YouCompleteMe. It has smartest autocomplete for C++ I ever seen (haven't tried last CLion yet, but one year ago it was far from ideal). You can also fix some typos, e.g. forgotten semicolon without leaving normal mode with :YcmCompleter FixIt
As for language-independent plugins:

For CP (SP?) I recommend using my plugin for CF: Igorjan94/codeforces.vim with some bindings to coderick14's AcEdit or gabrielsimoes's gabrielsimoes/cfparser.vim