Hot answers tagged

3

There are plenty of implementations for indent text objects -- I guess due to different way "indent" object is defined. I have my own: check https://gist.github.com/habamax/4662821a1dad716f5c18205489203a67 With following snippet in your vimrc you will be able to vii or vai to select indent: "" Indent text object "" Useful for ...


3

All "long" jump commands, such as gg, automatically save the bookmark for the previous poisition (note that G here is a "motion", so it does not overwrite the bookmark again), so all you have to do is to go back by that bookmark with two backticks: nnoremap <leader>= gg=G`` Or you can use CTRLO and CTRLI to navigate through the jumplist (:h jumplist) ...


3

As discussed in the comments, this behaviour is caused by cindent. You can check what's setting this with the command: :verbose set cindent?


2

Looks like you are missing the closing round brace for print(). print("The sum of {0} and {1} is {2}" .format(x, y, x+y)) It should indent correctly after fixing that.


2

Add autocmd BufNewFile,BufRead *.my_cpp setlocal filetype=cpp Read :help :setfiletype and decide if it applies to your or not. Even better would be to create ~/.vim/ftdetect/my_cpp.vim with autcmd BufRead,BufNewFile *.my_cpp setlocal filetype=cpp You won't need to set syntax. If you do instead :setlocal filetype=my_cpp than you can create ~/.vim/after/...


1

The question is invalid. Maybe XY problem or something. If &indentexpr is set to some function then that function calculates on-the-fly the number of spaces to indent a line. If also &expandtab is not set then Vim is allowed to minimize that number by outputting tabs - one hard tab per &tabstop spaces. But if you set expandtab then you say: "...


1

As Matt notes, smartindent is enough. Not only this, but cindent is actively harmful! Many years ago, when I first got started with vim, I had these both set globally in my vimrc. Eventually, through spurious indenting issues such as these, I came to realize that in fact they make bad global settings. cindent is too specific; it works for C stuff. Don't set ...


1

When in doubt look into the standard Vim runtime files. ts sts et sw should be set by after/ftplugin. sta is basically no-op, as you have &sw == &sts anyway. si ai are basically no-op as you have &cindent on. And also, in general, there's nothing in setting ai si on if you have any meaningful indent/xyz.vim. cino should probably be set by after/...


1

I guess all bracketing plugins have this behaviour for brackets at least. This is the case of lh-brackets for instance. And it's quite easy to extend to anything else. The important part is CR+ESC+O, O is what will ensure a correct indent. See this related answer on SO: https://stackoverflow.com/questions/35708395/how-to-move-opening-curly-braces-to-a-new-...


1

My recommendation to get this resulting effect is: Right after typing { at the end of the first line, press "Enter", you will get something like below, with the cursor on an indented line: updateCollections: collectionMap => { _ Then, and only then, press }. This will unindent the line and you'll get this, with the cursor on the }: updateCollections: ...


1

I don't have a personal vimrc. Then Vim sources $VIMRUNTIME/defaults.vim You can see this by issuing :scriptnames Why are the last 2 lines in my vimrc ignored? They are not. The last line gets effectively cancelled by the line filetype plugin indent on from defaults.vim, because it gets sourced after it. The last 2 lines are: This is a huge mistake, ...


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