New answers tagged

2

I'd say the easiest way to insert text at the correct indentation is to use the o or O Normal-mode commands. From :help o: When 'autoindent' is on, the indent for a new line is obtained from the previous line. When 'smartindent' or 'cindent' is on, the indent for a line is automatically adjusted for C programs. Of course, these two commands will insert ...


0

Note that it's possible to use Visual Block even if the comments are not aligned in the original text. For example, say you want to align the comments in this block: var1 = 0 # Var 1 var22 = 0 # Var 22 var333 = 0 # Var 333 var4444 = 0 # Var 4444 variable = 234 # Var Into: var1 = 0 # Var 1 var22 = 0 # Var 22 var333 = 0 # Var 333 var4444 = 0 ...


1

Plugin vim-visual-multi E.g. to align by # 3 lines: [cursor at start of 1st line] Ctrl-V jj \\c f# \\a Esc Note: \\ can be other keys, in link: Pay attention: in this page as in others, leader- is your g:VM_leader (default \\). Also, don't trust the pics for mappings.


1

This issue has already been answered, but I though I could also add my solution: As suggested by filbranden, it's better to not modified vim's system files. Instead, he suggested to use skip_defaults_vim=1 or create a .vimrc file in my home directory to disable the default features. If I want any of the default features, I can add them to my .vimrc file. In ...


3

A solution I discovered while answering a duplicate: it should be faster than the existing answer, as it uses just a couple of matches/builtin functions, rather than looping over lines. The algorithm is simpler, too. However, it may not work if there are blank lines or comments between the { and the case, or comments at the front of those lines—I would ...


2

I put together a little function that defaults to using cindent() for the indent, unless we are indenting a { line that directly follows a case statement (I've been twiddling a lot with indentexpr lately): function s:indent(lnum, offset) abort return a:lnum <= 0 \ ? indent('.') \ : indent(a:lnum) + a:offset endfunction function! c#...


2

Indentation of C/C++ code is typically done by enabling the 'cindent' option (built-in to Vim), which is in turn controlled by options set in 'cinoptions'. There are two interesting settings in 'cinoptions' that somewhat do what you want. The first is :set cinoptions==0, which instructs Vim to not indent the block under a case statement. So you do get this ...


4

You can align statements following the case label with the =N member of 'cinoptions'. The following will fix your specific example: :set cinoptions+==0 Unfortunately, it breaks indentation if you don't use a block: switch(x) { case a: { y(); } case b: y(); } You've indicated in the comments that this solution works for you, ...


1

The problem occurred because there is an inconsistency between the spaces and tabs used for indentation in your code. You have probably opened a tab indented code, and started editing it, while vim was set to indent using spaces. To solve this issue, first, set your tabbing space setting in your ~/.vim/vimrc by set softtabstop=4 set tabstop=4 set shiftwidth=...


Top 50 recent answers are included