How do I make Vim respect .editorconfig? - vim

I used Vundle to install editorconfig-vim plugin. It loads correctly and is listed in :scriptnames. But when I create a new file, say, x.js, indentation settings aren't picked from ~/.editorconfig file (although, no .editorconfig in CWD), and I have 2-space indentation instead of 4-space as I defined in my ~/.editorconfig.
What do I do wrong? Should I invoke a certain command in ~/.vimrc to make EditorConfig config work?
My ~/.editorconfig:
root = true
[*]
end_of_line = lf
insert_final_newline = true
charset = utf-8
indent_style = space
indent_size = 4
[{package.json,.travis.yml,Gruntfile.js,gulpfile.js,webpack.config.js}]
indent_style = space
indent_size = 2
And my ~/.vimrc config:
set nocompatible " be iMproved, required
filetype off " required
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'gmarik/Vundle.vim'
Plugin 'tpope/vim-fugitive'
Plugin 'tomasr/molokai'
Plugin 'moll/vim-node'
Plugin 'jelera/vim-javascript-syntax'
Plugin 'pangloss/vim-javascript'
Plugin 'editorconfig/editorconfig-vim'
call vundle#end() " required
filetype plugin indent on " required
" set tw=80
" set wrap linebreak nolist
let g:jsx_ext_required = 0 " Allow JSX in normal JS files
let g:syntastic_javascript_checkers = ['eslint']
let g:EditorConfig_core_mode = 'external_command'
syntax on
set number
set ruler
colorscheme molokai

You may want to use :verbose set tabstop? to check which plugin set it for you.
If it doesn't say Last set from ..., it uses the default option.
And then, editorconfig doesn't have the corresponding settings, and you may want to check which .editorconfig is used.

It is possible that another plugin is overriding the editorconfig plugin.
This happened to me. I had forgotten about installing https://github.com/Raimondi/YAIFA (Yet Another Indent Finder, Almost). I probably would have found the problem sooner in my case, if the plugin functionality was easier to parse from its name.

It helped for me in init.lua to set:
vim.cmd('filetype plugin on')
vim.cmd('filetype indent off')
Also :verbose set autoindent? gives the actual setting value and the place from where it was loaded. Filetype settings is loaded after global settings. After disabling filetype indentation my editorconfig started to work the way i expected it to work. You can also disable all filetype options by filetype off

Related

Easy way to get syntax highlighting for Julia in Vim

I am trying to get Julia to have syntax highlighting in Vim. Unfortunately, at the moment, I there is no syntax highlighting (here is a small snippet of my code so you can see what it currently looks like). I tried installing julia-vim and putting it in the .vimrc file and installing it, but it doesn't actually change the highlighting. Below is the .vimrc file:
set nocompatible " be iMproved, required
filetype off " required
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')
" let Vundle manage Vundle, required
Plugin 'VundleVim/Vundle.vim'
" The following are examples of different formats supported.
" Keep Plugin commands between vundle#begin/end.
" plugin on GitHub repo
Plugin 'tpope/vim-fugitive'
" plugin from http://vim-scripts.org/vim/scripts.html
" Plugin 'L9'
" Git plugin not hosted on GitHub
Plugin 'git://git.wincent.com/command-t.git'
" git repos on your local machine (i.e. when working on your own
plugin)
Plugin 'file:///home/gmarik/path/to/plugin'
" The sparkup vim script is in a subdirectory of this repo called vim.
" Pass the path to set the runtimepath properly.
Plugin 'rstacruz/sparkup', {'rtp': 'vim/'}
" Install L9 and avoid a Naming conflict if you've already installed a
" different version somewhere else.
" Plugin 'ascenator/L9', {'name': 'newL9'}
" All of your Plugins must be added before the following line
call vundle#end() " required
filetype plugin indent on " required
" To ignore plugin indent changes, instead use:
"filetype plugin on
"
" Brief help
" :PluginList - lists configured plugins
" :PluginInstall - installs plugins; append `!` to update or
just :PluginUpdate
" :PluginSearch foo - searches for foo; append `!` to refresh local cache
" :PluginClean - confirms removal of unused plugins; append
`!` to auto-approve removal
"
Plugin 'JuliaEditorSupport/julia-vim'
"
"
"
" see :h vundle for more details or wiki for FAQ
" Put your non-Plugin stuff after this line
I'm also note sure how to fix it after reading the julia-vim documentation. Am I doing anything incorrectly, or is there another way to add some syntax highlighting to Julia?
I have seen from one of the answers to this question asked by #Thomas that it might be how I have set up my terminal, but I'd prefer to keep the terminal with the present color scheme if possible. See here for my current settings.
EDIT: Thanks to #axwr, I was able to get some syntax highlighting by putting
syntax on
at the end of the .vimrc file and then running
:so %
while editing the .vimrc file. However, as you can see here, the color coding seems to be less than ideal. Only certain packages come up as yellow, the majority is still green, and random things (usually numbers) come up as purple. Is this how julia-vim colors things, or am I doing something wrong?
Okay, so.
There are two steps to syntax highlighting in Vim; actually turning it on, and, having the ability to highlight the specific language you want to work in. For most languages vim can do this by default, however some languages, like Julia, require a little help. In this case you have done step two by using vundle to install a Julia plugin.
To acheive step one, you just need the line: syntax on in your vimrc file.
A minimal example vimrc for you, might look like:
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'VundleVim/Vundle.vim'
Plugin 'JuliaEditorSupport/julia-vim'
call vundle#end()
set nocompatible
set backspace=indent,eol,start
set number
set hidden
syntax on
filetype plugin indent on
Given the above settings, and a terminal that has the "solarised" colorscheme, a julia file looks like:
Here is the little fizzbuzz julia snippet so you can compare against your highlighting:
for i in 1:100
if i % 15 == 0
println("FizzBuzz")
elseif i % 3 == 0
println("Fizz")
elseif i % 5 == 0
println("Buzz")
else
println(i)
end
end
So, Step by step:
Add syntax on to your .vimrc
Add filetype plugin indent on to your .vimrc
Install the relevant plugin
Source your .vimrc or close vim.
open a file with the correct extension, i.e: test.jl

How can I open NERDTree at left side?

I am new to vim and trying to use NERDTree. Well, I think I succeeded to install it but every time I open NERDTree, it opens at the right part of the window as shown below. I want it to open at the left as default but I don't know how. How can I open NERDTree at the left side of the window by default?
I tried to put let g:NERDTreeWinPos = "LEFT" or let g:NERDTreeWinPos = "left" in vimrc file but it didn't work.
For more details my .vimrc code looks like this
I use ultimate vim.'
set nocompatible " be iMproved, required
filetype off " required
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')
" let Vundle manage Vundle, required
Plugin 'VundleVim/Vundle.vim'
" All of your Plugins must be added before the following line
call vundle#end() " required
filetype plugin indent on " required
let g:NERDTreeWinPos = "LEFT"
set runtimepath+=~/.vim_runtime
set showcmd
set number
source ~/.vim_runtime/vimrcs/basic.vim
source ~/.vim_runtime/vimrcs/filetypes.vim
source ~/.vim_runtime/vimrcs/plugins_config.vim
source ~/.vim_runtime/vimrcs/extended.vim
try
source ~/.vim_runtime/my_configs.vim
catch
endtry
In case this has not been answered, access the ~/.vim_runtime/vimrcs/plugins_config.vim file and change the NERDTree position in that file.

Vundle doesn't load plugin

This is my .vimrc located under $HOME/.vimrc. I've installed Vundle.
set nocompatible " be iMproved, required
filetype off " required
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" let Vundle manage Vundle, required
Plugin 'VundleVim/Vundle.vim'
Plugin 'dracula/dracula-theme'
call vundle#end() " required
filetype plugin indent on " required
" Put your non-Plugin stuff after this line
I'm able to execute :PluginInstall successfully installing dracula-theme. Unfortunately the theme is not applied and the style remains unchanged? Any clues?
Adding Plugin 'dracula/dracula-theme' to your vimrc and using :PluginInstall make the colorscheme available to Vim but it doesn't say to Vim to use it.
As #dNitro said in the comment you have to use the command colorscheme to set the desired colorscheme. Thus you need to add a line colorscheme dracula to your vimrc after the line " Put your non-Plugin stuff after this line.

YouCompleteme works but can not complete using TAB

I installed YouCompleteMe using vundle.
Then installed all plugins and installed YCM using
./install.sh --clang-completer
This is how my vimrc looks:
syntax on
set expandtab
set cindent
set tabstop=4
retab
set shiftwidth=4
set hlsearch
set paste
set ic
set number
colorscheme molokai
set t_Co=256
set nocompatible " be iMproved, required
filetype off " required
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'gmarik/Vundle.vim'
Plugin 'tpope/vim-fugitive'
Plugin 'tpope/vim-repeat'
Plugin 'kien/ctrlp.vim'
Plugin 'sjl/gundo.vim'
Plugin 'Valloric/YouCompleteMe'
Plugin 'scrooloose/syntastic'
Plugin 'Valloric/ListToggle'
call vundle#end() " required
filetype plugin indent on
"options for syntastic"
set statusline+=%#warningmsg#
set statusline+=%{SyntasticStatuslineFlag()}
set statusline+=%*
let g:syntastic_python_checkers=['pep8', 'pylint', 'python']
let g:syntastic_enable_signs=1
let g:syntastic_auto_loc_list=1
let g:syntastic_check_on_open = 1
let g:syntastic_check_on_wq = 1
let g:syntastic_error_symbol = "X"
let g:syntastic_style_error_symbol = ">"
let g:syntastic_warning_symbol = "!"
let g:syntastic_style_warning_symbol = ">"
let g:syntastic_echo_current_error=1
let g:syntastic_enable_balloons = 1
let g:syntastic_auto_jump=1
"Gundo options"
nnoremap <F5> :GundoToggle<CR>
"CtrlP options"
let g:ctrlp_map = '<c-p>'
let g:ctrlp_cmd = 'CtrlP'
"Powerline stuff"
python from powerline.vim import setup as powerline_setup
python powerline_setup()
python del powerline_setup
set laststatus=2
YCM works but I can't switch between the suggestions using TAB, only using Down and Up arrows and accepting with Enter.
Why is happening this? Is another program using the TAB key?
thanks a lot for the help
By configuring set paste, you're effectively disabling all mappings and abbreviations.
You only need that set when you actually paste text in terminal Vim! It's best to bind this to a key. As mappings cannot be used when the option is set, Vim provides a special option for this:
:set pastetoggle=<F10>
Further commentary
As the ~/.vimrc is sourced at the beginning of Vim startup (when files passed to it haven't yet been loaded), the retab is ineffective; just drop it. If you really want automatic reindenting for opened files, you'd have to employ an :autocmd BufRead * retab for that, but I'd advise against that.
The problem was due to the "set paste" line in my .vimrc
so, I removed it, and when I want to paste large blocks of code in vim, I just write :set paste to enable it or :set nopaste to disable it. This toggle can be also mapped to f10 or any key.

Possible conflict between langmap and Vimroom

Having recently gotten 'serious'(-ish) about using Vim, I was really pleased to come across the 'VimRooom' script.
Problem
The problem is that I've also just discovered the langmap option for re-configuring the hjkl keys and there seems to be some sort of conflict which stops the new configuration of movement keys from working with Vimroom toggled on.
Question
I'm afraid to say that I don't understand the langmap command enough to know why such a conflict is possible and I was hoping someone could explain the problem/suggest a fix please?
My current .vimrc:
set nocompatible " be iMproved
filetype off " required!
set rtp+=~/.vim/bundle/vundle/
call vundle#rc()
" let Vundle manage Vundle
Bundle 'gmarik/vundle'
" My Bundles here:
"Bundle 'flazz/vim-colorschemes'
"Bundle 'vim-scripts/CSApprox'
Bundle 'altercation/vim-colors-solarized'
Bundle 'dnebauer/AutomaticLaTeXPlugin'
Bundle 'mikewest/vimroom'
" vim-scripts repos
Bundle 'L9'
Bundle 'FuzzyFinder'
" non github repos
Bundle 'git://git.wincent.com/command-t.git'
" Colour scheme options
syntax on
set background=dark
set t_Co=16
let g:solarized_termcolors=16
colorscheme solarized
"Line formatting options
set linebreak
set tw=100
set fo+=t
"set foldcolumn=12
set tabstop=4
"Basic Keybindings
"Movement
set langmap=hk,mj,th,nl,kt,jm,ln
"Display options
set scrolloff=999
"Settings for Automatic LaTeX
filetype plugin on
filetype indent on
filetype on
"Search Settings
set smartcase
"Vimroom Settings
let g:vimroom_sidebar_height=0
N.B. The desired hjkl remapping(for lack of a better phrase) only makes sense when using the Dvorak layout.

Resources