6

Manually toggling :set paste/:set nopaste as suggested by francois P is cumbersome, and resetting the TERM variable as evaristegd suggests is a very bad idea as explained in the comments (which hint at the better solution below). The best solutions that I could find are explained here, and I'll briefly repeat them below. Background The central concept for ...


4

" tell which cinoption take effect for current line com! WhichCinoption call s:which_cinoption() function s:which_cinoption() abort " test if cindent take effect if !empty(&indentexpr) echo "'indentexpr' exists, it overrides 'cindent'." return endif if !&cindent echo "'cindent' is currently disabled." return endif " ...


4

A working, hacky solution function! Visual_indent_with_space() range abort '<,'>g/./exe "normal! " v:count1 . "I " endfunction vnoremap <leader><space> :call Visual_indent_with_space()<cr> Breaking down: '<,'>g/./exe "normal! " v:count1 . "I " '<,'>: use the selected range g/./: ...


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, ...


3

In the absence of a complete solution, I thought I'd just write a quick answer that shows one way you can achieve the first part of your question. Try the following mapping (for F3): nnoremap <F3> :s/%>%/&\r/g<CR>V``j=gv>> How it works Splitting the line First, it breaks the line on the pipes: :s/%>%/&\r/g :s/ #...


3

You can reproduce this behavior in stock Vim with no extra plug-ins. The reason why this issue happens is that 'indentkeys' includes 0#, which triggers automatic reindentation of a line when you type # as the first character of the line. (Note that this is mostly meant for the C/C++ language, for directives such as #define or #include which are meant to ...


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 ...


3

Try the most recent updated of Goneovim, not the current release 0.4.6. It's not pure vim but a neovim gui, and it does not gain much attention. The indent guides feature of goneovim is native, and works much better than vim/neovim plugins.


3

What you're seeing is the result of having 'softtabstop' (alias 'sts') set to a non-zero value. It makes a lot of sense for this to be set in Python files where spacing matters since backspacing over individual spaces in indentation can lead to invalid Python. If you really want to change it set 'sts' to 0. But you can't just put set sts=0 in your vimrc. It'...


3

Using :h sub-replace-special: %s@^ \+@\=repeat("\t", strlen(submatch(0)) / &ts)


2

@dedoswdi's answer was extremely helpful! I adapted it somewhat to produce the result for each line on the buffer. My adapted script can be found in this Gist. After applying it to the original C++ code, I got the results with both cinoptions= (none of them set) and cinoptions=N-s (which triggers the odd behavior with the second struct.) Here are the ...


2

This is :h cino-+. It looks like get_c_indent() (from src/cindent.c) doesn't know about template and treats it like an ordinary expression split over several lines (here namespace serves as "a function" from :h cino-+). The relevant piece of code from src/cindent.c is 2831 else if (lookfor == LOOKFOR_UNTERM) 2832 { 2833 if (cont_amount > 0) 2834 ...


2

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 ...


2

With the help of this, this, and this, I come up with this: nnoremap >> 0i<tab><esc>^ nnoremap << :norm 0ldF<tab><enter>^ For multiline selection (works on VISUAL, VISUAL BLOCK and VISUAL LINE): vnoremap > :norm 0i<tab><enter>gv vnoremap < :norm 0ldF<tab><enter>gv Put them on your ~/.vimrc....


2

If you open :e $VIMRUNTIME/ftplugin/markdown.vim you will find that it loads ALL filetype plugins for html runtime! ftplugin/html.vim ftplugin/html_*.vim ftplugin/html/*.vim Command runtime! with an exclamation mark will source all matched files found in your runtime path, including your local .vim/ftplugin/html.vim. To properly override any settings you ...


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 ...


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 ...


2

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=...


2

Indentation of C++ (and also C, Objective-C and even Java) is typically handled by enabling the 'cindent' option, which uses Vim's built-in C-indenting implementation, which recognizes elements of these languages (such as curly braces, semi-colons, etc.) and uses them as cues to decide whether to indent or unindent a specific line. This indentation engine ...


2

Vim runs in (virtual) terminal, thus it's not allowed to combine arbitrary pixels over existing glyphs. The "conceal" feature is supposed to be used for displaying one character instead of another actually stored in memory buffer. To repeat it again: indentation bar here is a different character (U+00A6 or whatever), not a bunch of pixels drawn on ...


2

Instead of using an external fmt program to format your text by filtering it through the external command, consider using Vim built-in commands gq or gw. Both commands take a motion or text object to determine which lines of text to act on (by the way, the same is true for the ! command, which also takes a motion, so you can use !}fmt to format from the ...


2

In your screenshot, all the lines which end with %> also start with <%=, except this one: <= render 'shared/footer' %> ^^ ✘ If you add a percent character between the leading < and the following =: <%= render 'shared/footer' %> ^ ✔ Then gg=G indents your file like this: <!DOCTYPE html> <html> <head> <title&...


1

When you paste something in insert mode, paste option makes a huge difference. And if you don't want to toggle it then try using normal mode pasting invoked from insert mode mapping. This is the naive attempt to solve your pasting issue: inoremap <S-Insert> <ESC>"*p`]a go to normal mode with <ESC> paste from * register with "*p ...


1

You could use an autocmd to set the syntax to htmldjango when editing an HTML file: autocmd FileType html set syntax=htmldjango This preserves filetype while using the default htmldjango syntax file. See: :help :autocmd :help 'syntax'


1

There are two options that can be set to run arbitrary programs to format text (code). When they aren't set, vim will work with lots of other (often complex, and often somewhat hacky) options to indent or format your text. These options are equalprg (trigged by =) and formatprg (triggered by gq). Technically one is for indenting and the other for formatting, ...


1

I just do column selection + copy for such unaligned movement of my code. So... first I have expandtab (et) as part of my settings at the bottom of my file like so: // vim: ts=4 sw=4 et This means the tabstop is at 4 characters, the shiftwidth is also at 4 characters, and expandtab is also turned on (so no tabs anywhere, just spaces). When I have a problem ...


1

I'm aware of two possible approaches from within Vim. On the fly formatting My C and C++ snippets defined in lh-cpp (as abbreviations) and in mu-template+lh-cpp (as more traditional snippets) are expanded according to the current stylistic preferences (through another plugin: lh-style). Pros: The correct style is used from the start No external dependences (...


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

setlocal cinoptions=E-s See :h cinoptions-values. Also make sure that :h 'equalprg' is set to empty, so the internal Vim formatter is used. If not, see man pages of an external formatter tool whatever it is.


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