Podcast #128: We chat with Kent C Dodds about why he loves React and discuss what life was like in the dark days before Git. Listen now.

Hot answers tagged

48

I do this one of two ways. Indent adjusted paste First, if the code in the buffer is formatted, but at a different level of indentation, I use ]p instead of p, which pastes the code as is, but with the indentation shifted such that the first line pasted is the same depth as the line I'm on. E.G. source copied to buffer while (1) { dostuff(); } E.G. ...


42

There are many different flavors of autocomplete in vim. One way might be to use SuperTab. This provides a way to use tab-completion at more or less any time. This would enable you to hit Tab after you've partially typed the word to get a completion list. For instance, typing eatF followed by Tab to expand to eatFood. Please Note: these pictures all link to ...


33

Among all the plugins I have tried, I found ConqueGDB to be the best approach. ConqueGDB uses Conque Shell to embed an interactive shell inside vim, that is used by GDB. The workflow with ConqueGDB consists not entering GDB commands on the GDB terminal, you use shortcuts on the vim source code. But you can continue using the GDB prompt if you want, for more ...


27

I really like clang_complete for this. It does require clang, and you need to tell it where libclang resides in your system. After that, it works wonderfully. People might suggest YouCompleteMe, but to be honest, that plugin is hugely bloated for what it says it does, and it requires way too many steps to install. I also had it segfault Vim on multiple ...


24

Such functionality - i.e., searching the current file (and all open files) for auto-completion, should be enabled by default with Ctrl+P: You can go to the next suggestion with Ctrl+N, the previous suggestion with Ctrl+P and select it by typing any letter (which will be appended right after the suggestion).


20

Vim has support for completion natively. You can read about the various different completions that Vim supports at :h ins-completion. In general, for all purposes I have found, ins-completions are enough for my liking, however there are some completion plugins that add more value beyond what ins-completions offers. NeoComplete, YCM (YouCompleteMe) are a few ...


15

Here are a few ways to do it. 1 | $color = "#fff"; 2 | function PickColor () { 3 | $color = "#bbb"; 4 | $newColors = ["#000", "#fbf", $color]; 5 | foreach ($newColors as $c) { 6 | if ($c == "#fff") { 7 | break; 8 | } 9 | } 10 | } 11 | $differentColor = $color; I've modified your example to include line ...


15

The = command can be used to reindent. Like most normal mode commands it can be applied to a motion, so you can reindent the just pasted code with =']. This reindents from the current cursor position to the '] mark, which is the last line of the paste. = can also be used from visual mode. Another useful command is ]p, which pastes at the same indent ...


13

Exuberant ctags is the simplest way to achieve this. Under GNU/Linux (e.g. Ubuntu or Debian) you should be able to just do sudo apt-get install exuberant-ctags (For OSX "$ brew install ctags" should suffice; for Windows you might want to visit http://ctags.sourceforge.net/ and download the standalone executable) Then navigate to your project's root ...


12

You can just use the usual workflow search and replace: /original cwreplaced n.n. You can take also advantage of the gn motion: /original<CR> cgnreplaced<ESC> ..... cgn will change the next matched pattern, so instead of using n.n. to go to next and repeat you can just .. which means replace next. gn means "search for next occurence and ...


11

This can be done using a combination of the autoindent option and the filetype plugin. The autoindent option will copy your current indentation when creating a new line. So if your current indentation level is 4 when you start the new line, the cursor will be moved to the same indentation level on the next line. In your ~/.vimrc file, you would put set ...


11

You have several plugins that integrates gdb. We used to have pyclewn. The project has been discontinued after version 2.3. The last commit has been made in 2016. For the curious ones there is still a mirror on github where its author has archived his work. Note: pyclewn used to be the last stage step in the evolution of the other Xavier Degaye's *clewn ...


11

"Include search" is one such tool: [I and ]I " search current buffer and included files for " the word under the cursor, skipping comments :ilist foo " same as above but for 'foo' :ilist /foo " same as above but for a word containing 'foo' Related to "include search", "definition search" is interesting, too: [D and ]D " ...


10

By default, (with a minimal vimrc, and no plugins installed), this is already possible. Vim ships with multiple filetype plugins and some of these plugins offer omni-completion right out of the box. For example, python comes with pythoncomplete.vim. If you use the default pythoncomplete.vim that ships with Vim, (i.e. no YouCompleteMe, no python-mode, no ...


9

Vim doesn't come with PHP syntax folding built-in. However, if all of your code is properly indented (as your example is), you can use a different fold method: :set foldmethod=indent


9

Yes, auto completion scripts for vim exist. The "best" choice is depending on your programming language. As your example code is Python I suggest to take a look at Jedi. Build on top of that You complete me exists, which also has support for other languages, but is sometimes seen as too big. For other languages you can browse through the long set on vim ...


8

YouCompleteMe (Link) plugin has been work great for me. It uses libclang to generate the autocomplete feature, providing accurate completion. It has a lot of customization, specially when working with compilation flags. You can edit the "flag generator" editing a python script per project (Example). But, to me the main advantage is that it supports Clang ...


8

This an odd question, and would be equally odd if asked of any editor IMHO. No, vim (nor any other vi-variant) has ever hindered any of my work. I've only ever been hindered when not using it. I'm not sure how vim would hinder my social interaction with other team members. It's not like vim gives you bad breath. My colleagues and bosses couldn't care less ...


8

Vim displays the "Press ENTER" prompt when the number of lines printed in the command area is greater than the number of lines it has available. This is to ensure the user doesn't miss a message. The issue has been documented in Vim's help (:h press-enter) and also addressed on the VimTips wiki. Make more space for messages An easy and reliable fix is to ...


7

In insert mode, type the first couple of characters of a word, then press: Ctrl-N to insert the next matching word; or Ctrl-P to insert the previous matching word. This is particularly useful when entering the names of variables in a program. The 'complete' option controls where the keywords are searched (include files, tag files, buffers, and more). ...


7

Using =ap (mnemonic is 'format a paragraph') will have vim attempt to autoformat the current paragraph. If you want to pay careful attention to what you're potentially reformatting, you might find it saner and quicker to use vap to visually select the current paragraph (giving you a visual indication of what is being reformatted), followed by =. I find ...


7

GDB edit command Opens an editor on the current line using the command: $EDITOR +<current-line> <current-file> The default editor is ex, but vim also understands the +<current-line> format. When you quit the editor, you get back into gdb. This allows you to browse the source freely and is specially powerfull if you have ctags ...


6

Use :set cindent (:set cin for short) or :set smartindent (:set si for short). If your line ends in an opening brace, and you hit Enter, the following line will automatically be indented one additional level. (This is better than :set autoindent, which merely indents the next line at the same level.) cindent is better tailored to C-like languages, while ...


6

I can only answer the second part of your question. You can tell Vim that you're editing a Prolog file with this command: :set syntax=prolog If you never work in Perl, then it wouldn't seem "dictatorial" to add custom configuration in your ~/.vimrc: autocmd BufNewFile,BufRead *.pl setfiletype prolog syntax=prolog


6

If you're comfortable taking the plugin route, there's NrrwRgn. You visually select a block, then run the :NR command, which opens a new buffer (in a split) with the selected text. You can make modifications to this buffer, and when you save to it, it gets saved back to the original file as well. In my opinion, this plugin solves the problem very well, ...


6

Depending on how you update your ./tags file: If you do not commit your ./tags file to your branch/repository you can use a git hook that calls ctags -R . on each pull/checkout you do - this way your ./tags file will always contain data on all present files in the current version you have checked out. If you do want to commit your ./tags file, you can ...


5

You could add the following to the top or the bottom of the file. %vim: ft=prolog This will tell Vim to treat the file as a Prolog file. See “Modelines” in the user manual and :help modeline.


5

phpfolding.vim provides this. The advantage of this over :set foldmethod=indent is that it's "smarter" because it looks at the actual PHP syntax, and not just the indentation. From the README: It remembers fold settings. If you add functions and execute the script again, your opened folds will not be closed. It will not be confused by brackets in ...


5

There are a lot of ways for navigating through code (included in Vim and external), I still discover them. What I use in daily work is: Greping text in the project files and navigating via quickfix window (I use silver searcher for greping). Using language related plugins, I know there are ones for javascript, ruby, go, that allow to jump between modules of ...


5

You can use the external program exuberant cTags to help you doing that: It will create a tags file indexing the keywords of your codebase and allow you to navigate through them. (The first steps comes from another answer) Install exuberant cTags: $ sudo apt-get install exuberant-ctags (or the equivalent command for your distribution). Generate the tags ...


Only top voted, non community-wiki answers of a minimum length are eligible