watching a screencast (can't link it since you need to have a peepcode pro subscription) I've seen a developer indenting his source code (a ruby file) graphically using the visual mode inside vim. He did the following steps: press "v" selecting lines and then pressing something else I didn't get (because there is no representation of what's being pressed on the keyboard), then he got the whole source perfectly indented, without the need to write something on the command line.
Is there a plugin you know to do it that way from visual mode?
You can press = in visual mode to automatically indent your code.
Or you can use > and < in visual mode to change the indentation level
of the selected code.
This plugin does exactly what you want: https://github.com/Chiel92/vim-autoformat.
That would be V(motion)=.
See :help = for details.
Related
I recently started using vim for writing markdown and latex files. Visual mode works great when copying lines or blocks of code, but when I'm writing, I often need to copy non-rectangular chunks of text. For example, what I'd like to be able to do is this:
But, with visual mode I can only seem to do this:
or this:
l
Is there a way to select the entire first line and only a portion of the second line?
All of Vim's modes are listed under :help vim-modes. Here is what it says about visual mode:
Visual mode This is like Normal mode, but the movement commands
extend a highlighted area. When a non-movement
command is used, it is executed for the highlighted
area. See |Visual-mode|.
Where you get a handy link to :help visual-mode, which is a whole section delving into every detail of the three visual modes, started with v, V, and <C-v>.
Note that it says this near the top:
This is introduced in section |04.4| of the user manual.
This means that visual mode is taught very early in the user manual and, by consequence, that it is a very basic and foundational topic. It also implies that going through the linked section of the user manual is a prerequisite.
This is the second paragraph of that very basic section:
You start Visual mode by pressing "v". You move the cursor over the text you
want to work on. While you do this, the text is highlighted. Finally type
the operator command.
Note that it says v, not V.
Visual mode, by way of v, again, is also casually introduced in lesson 5.3 of $ vimtutor.
All that to say that, everywhere visual mode is mentioned in the built-in documentation, from the very basic vimtutor to the very extensive reference manual, v is systematically mentioned first.
It used to be part of my Vim vocabulary... change to visual mode, place cursor to a search word, type * and all text between first and next search word would be highlighted. The highlighting can continue as long as you repeat pressing * and there is the next matching search word. Perfect set of commands to copy text, or simply as visual aid.
Coming back to Vim now after some time, this is not working on my configuration. What happens now is that only the letter under the cursor and all other such letters get highlighted.
I wonder if I have some conflict in my mappings or else? I use Vim v7.3. Anyone can help?
Vim does not have a visual mode command for *; this only works in normal mode. However, many people have a customization that supplies the super star visual variant, from Search for visually selected text - or a plugin like my SearchHighlighting plugin; its plugin page has links to many alternative plugins.
I guess you had something like that, too, but forgot about it. I also doubt that is was triggered by Ctrl + *; combinations of Ctrl and non-alphabetical letters mostly aren't available as unique mappings. The usual mapping is just *, overloading the original normal mode command for visual mode.
Vim 7.3 is from 2010 and very outdated. To become reacquainted with Vim (which I commend!), please choose a modern variant. It should be possible to install the latest version 8.1; if you can't find a proper package for your distribution (for Windows, check the binaries from either vim-win32-installer or tuxproject; on Linux, it's also not very difficult to compile it yourself (e.g. from the GitHub sources).
I have a vim plugin that works mainly with the visual mode. One of its commands sends the visually selected region to an interpreter.
However, I would like to select the first 3105 lines of a file.
1,3105mycommand does not work, this is not implemented in the plugin.
Is there a vim command xx that, after invoking 1,3105xx would visually select the first 3105 lines?
An alternate method:
If the plugin only looks at visual mode's marks, then this might suffice:
1k<
3015k>
If it actually needs the visual mode to be on, then you would need to also add
normal gv
:help :k, :help gv
Note that nvim will start in character-wise visual mode, so change the last line to normal gvV for nvim.
The solution is simple: in visual mode one can use the 3105G command in command mode, typed blindly and that extends the visually selected region.
Like Visual Studio when you type-in a tooltip shows you the summary (documentation) of lib/objects/functions etc.
Suppose, I'm experimenting with DataMapper. I would like to see what it has and what each of them can do (purpose) without leaving vim. Is this possible?
Although I'm doing PHP development, not Ruby, I think this will also work for Ruby:
For PHP (Drupal) I generate a tags file with ctags and configure vim to use this tagfile by setting the tags-option. (see :help tags).
Now when I start typing a function-name I can press CTRL-X CTRL-O to start Omnicompletion. Vim show a list of all possible completions and you can select next/previous suggestions with CTRL-N and CTRL-P. When selecting a completion Vim also shows the function declaration in a preview window.
You can close the preview window with the :pclose-command.
The preview will only show up if the completeopt-settings contains the preview value (see :help 'completeopt')
I program using java and vim and I want to figure out how to do code completion in vim. I downloaded the vim plugin javacompletion and it works, but it only for j2se but not for android source code.
Is there any code completion in vim for andriod source code? I would like that when I, for example, enter "TextView." (the class in android.jar) and press ctrl+x ctrl+o, it should show the functions in TextView.
Have look at Vjde vim plugin.
I remember using it before and you just have to tell it to also look inside android.jar for the stuff to autocomplete.