Setup Vim to indent only after colons - vim

I am editing yaml files with Vim and oddly enough it indents every new line. How can I get it to only indent if I put a semicolon at the end of the previous line?
I have searched the internet, but I could only find some instructions on auto indentation, etc.

If you are using neovim, use coc-nvim. After installation of the coc-nvim install coc-yaml with command :CocInstall coc-yaml. After this, you'll get full support for YAML (syntax checker, syntax highligther, indentation, etc.)

YAML indenting should be more or less correct if you have any of the following lines in you vimrc and Vim recognises your files as yaml:
filetype indent on
filetype indent plugin on
filetype plugin indent on
Also, it's a colon, not a "semicolon".

Related

How to use four spaces for indent in vim editing?

The default editing is indenting with tab, I tried to change ~/.vimrc to indent with 4 spaces, but I failed. I find it is useful to use the setting Text Editor Indentation here in Jupyter config:
hmm, I think 2 tools is not related. jupyter-lab is web-based, and .vimrc is config for your vim in local computer. Therefore, you can not config in .vimrc to make it works in jupyter-lab

Vim not indenting the c file like c++ file according to the specifiations mentioned in the vimrc file

I am using the following vimrc file in my vim editor
https://gist.github.com/rocarvaj/2513367
I have changed the tabs and spaces section like this
" configure tabwidth and insert spaces instead of tabs
set tabstop=2 " tab width is 4 spaces
set shiftwidth=2 " indent also with 4 spaces
Now, I am using gg=G to indent my code and it is working for C++ file but not for C files. The C files get 4 space indentation instead of 2 as I have mentioned.
Add the following to your .vimrc, it ensures that indentation rules and plugins are loaded according to the detected filetype:
" Uncomment the following to have Vim load indentation rules and plugins
" according to the detected filetype.
if has("autocmd")
filetype plugin indent on
endif
If you only want indentation rules according to the filetype, remove the "plugin" on the second last line of the snippet.

How to turn on syntax highlighting for vim

Whenever I try editing code in vim, every character is completely grey.
My ~/.vimrc has syntax on and filetype plugin on included.
I noticed that I didn't have a ~/.vim/colors/ folder and then downloaded a colorscheme (monokai.vim) and put it in this directory. The problem was not fixed.
When typing :colo <SPACE> <TAB> vim does not return anything.
I've looked everywhere and can't find a solution to this.

How to turn on syntax highlighting in VIM 7.3 OSX

System = OSX 10.9.4
I am trying to turn on syntax highlighting in vim while using the terminal. However, I am unable to get it to work properly.
Things I've tried:
located the vimrc file and added the following code:
set ai " auto indenting
set history=100 " keep 100 lines of history
set ruler " show the cursor position
syntax on " syntax highlighting
set hlsearch " highlight the last searched term
filetype plugin on " use the file type plugins
Located vimrc under directory:
cd /usr/share/vim/
The interesting thing is that once I add the code to the vimrc using vim, followed by exiting (x), and re-opening the file again, syntax is correctly highlighted in the vimrc.
However, when I try to make a new vim file called "test", copy the same code, save and exit. Re-open it, the syntax is not highlighted at all.
It appears that syntax highlighting only works when I open the actually vimrc file---and not when I try to create a new one or open another file that should have syntax highlighting.
I've also tried to create a .vimrc (exact copy) under the ~/ (directory). No success.
Made a new file called "test" and tried turning it on while active as well:
vim test
"then within vim"
:syntax on
I am really confused as to why this partially works.
Any help is much appreciated.
Cheers!
p.s. I have followed these instructions as well from: http://geekology.co.za/article/2009/03/how-to-enable-syntax-highlighting-and-other-options-in-vim
*I am aware of macvim, but would like a solution for the native vim in terminal. Thanks.
NEVER do anything in $VIM as it will work only by luck, cause unexpected behaviors and likely be overwritten next time Vim is updated.
What you have put in /usr/share/vim/vimrc should be in ~/.vimrc.
filetype on and syntax on are the bare minimum you need in your ~/.vimrc for syntax highlighting to work.
$ vim ~/.vimrc gives you syntax highlighting because the file is recognized by Vim as a vim file. Filetype detection is mostly dependent on file extensions so you can't expect any syntax highlighting in a file called test.
$ vim test.py, on the other hand, should give you syntax highlighting.
If the filetype is not detected, you can force it with :set filetype=python.
You most probably want to enable indentation along with syntax highlighting, so add these to lines to ~/.vimrc
filetype plugin indent on
syntax on
Steps with screenshots can be found here
http://osxandiosdaily.com/how-to-enable-vim-syntax-highlighting-on-mac-osx/
Inside of your file, enter command mode and enter the command
:syntax on

GoLang Highlighting in vim not working

I've seen multiple places(including here) that to add syntax highlighting you have to add certain lines to the .vimrc:
"Stuff for GoLang"
filetype off
filetype plugin indent off
set runtimepath+=$GOROOT/misc/vim
filetype plugin indent on
syntax on
That is what's currently in my .vimrc
Restarted vim, terminal, system, and still no highlighting. Any suggestions?
Okay guys, I go the answer:
$GOROOT needs to be defined or you can simply put the location of your go installation.
Ensure that the corresponding runtime files are actually there.
$GOROOT must be defined; check with :echo $GOROOT
There must a syntax plugin (syntax/go.vim) below $GOROOT/misc/vim. Check with :echo filereadable($GOROOT . '/misc/vim/syntax/go.vim').
After opening a Go file, you can check again via :scriptnames and :syntax list.

Resources