Showing posts with label vim. Show all posts
Showing posts with label vim. Show all posts

Wednesday, April 18, 2018

Syntax highlight in vim not working at all

Leave a Comment

I've just been busy configuring vim to look like an IDE with the help of this and this source, but i can't seem to get the syntax highlighting to work.

In my ~/.vimrc i have the following two settings filetype plugin indent on and syntax on that supposed to highlight the syntax, but whenever i open a file (Javascript for example) it doesn't work.

When i open the file and do :syntax list i get the following response: No syntax items defined for this buffer

I (quick) search on the internet al refer to the settings i mentioned (and are defined correctly).

What am i missing?

Below my whole .vimrc content

set nocompatible  """" Config Vundle plugin manager """"" filetype off  set rtp=~/.vim/bundle/Vundle.vim call vundle#begin()  Plugin 'VundleVim/Vundle.vim'  """" Plugins """" Plugin 'altercation/vim-colors-solarized' Plugin 'tomasr/molokai' Plugin 'vim-airline/vim-airline' Plugin 'vim-airline/vim-airline-themes' Plugin 'scrooloose/nerdtree' Plugin 'jistr/vim-nerdtree-tabs' Plugin 'vim-syntastic/syntastic' Plugin 'xolox/vim-misc' Plugin 'xolox/vim-easytags' Plugin 'majutsushi/tagbar' Plugin 'ctrlpvim/ctrlp.vim' Plugin 'vim-scripts/a.vim' Plugin 'airblade/vim-gitgutter' Plugin 'tpope/vim-fugitive' Plugin 'Raimondi/delimitMate' Plugin 'jez/vim-superman' Plugin 'christoomey/vim-tmux-navigator' Plugin 'jez/vim-c0' Plugin 'jez/vim-ispc' Plugin 'kchmck/vim-coffee-script' Plugin 'godlygeek/tabular' Plugin 'HTML-AutoCloseTag' Plugin 'ekalinin/Dockerfile.vim' Plugin 'cakebaker/scss-syntax.vim' Plugin 'tpope/vim-surround' Plugin 'ntpeters/vim-better-whitespace' Plugin 'edkolev/tmuxline.vim'  """" OSX stupid backspace fix """" set backspace=indent,eol,start  call vundle#end() filetype plugin indent on syntax on  """" General settings """" set backspace=indent,eol,start set ruler set number set showcmd set incsearch set hlsearch  """" Set tabs """" set tabstop=2 set shiftwidth=2 set smarttab set expandtab  """" Enable mouse support """" set mouse=a  """" Enable highlighting of the current line """" set cursorline  """" Support symbols in the title bar """" hi clear SignColumn  """" Colorscheme (Solarized) """" set background=dark colorscheme solarized  " Always show statusbar set laststatus=2  """" Enable Menlo font """" let g:airline_powerline_fonts = 1  " Show PASTE if in paste mode let g:airline_detect_paste=1  " Show airline for tabs too let g:airline#extensions#tabline#enabled = 1  " Use the solarized theme for the Airline status bar let g:airline_theme='solarized'  """" Nerdtree config """" " Open/close NERDTree Tabs with \t nmap <silent> <leader>t :NERDTreeTabsToggle<CR> " To have NERDTree always open on startup let g:nerdtree_tabs_open_on_console_startup = 1  """" Scrooloose/syntastic settings """" let g:syntastic_error_symbol = '✘' let g:syntastic_warning_symbol = "▲" augroup mySyntastic   au!   au FileType tex let b:syntastic_mode = "passive" augroup END  """" Easytags settings """ set tags=./tags;,~/.vimtags " Sensible defaults let g:easytags_events = ['BufReadPost', 'BufWritePost'] let g:easytags_async = 1 let g:easytags_dynamic_files = 2 let g:easytags_resolve_links = 1 let g:easytags_suppress_ctags_warning = 1  """" Tagbar settings """" " Open/close tagbar with \b nmap <silent> <leader>b :TagbarToggle<CR> " Open tagbar automatically whenever possible autocmd BufEnter * nested :call tagbar#autoopen(0)  """" Vimgutter settings """ " In vim-airline, only display "hunks" if the diff is non-zero let g:airline#extensions#hunks#non_zero_only = 1  """" delimitMate settings """ let delimitMate_expand_cr = 1 augroup mydelimitMate   au!   au FileType markdown let b:delimitMate_nesting_quotes = ["`"]   au FileType tex let b:delimitMate_quotes = ""   au FileType tex let b:delimitMate_matchpairs = "(:),[:],{:},`:'"   au FileType python let b:delimitMate_nesting_quotes = ['"', "'"] augroup END  """" Superman config """" noremap K :SuperMan <cword><CR> 

EDIT:

Below the response of vim --version

VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Nov 29 2017 18:37:46) Included patches: 1-503, 505-680, 682-1283 Compiled by root@apple.com Normal version without GUI.  Features included (+) or not (-): +acl             +file_in_path    -mouse_sgr       +tag_old_static -arabic          +find_in_path    -mouse_sysmouse  -tag_any_white +autocmd         +float           -mouse_urxvt     -tcl -balloon_eval    +folding         +mouse_xterm     -termguicolors -browse          -footer          +multi_byte      -terminal +builtin_terms   +fork()          +multi_lang      +terminfo +byte_offset     -gettext         -mzscheme        +termresponse +channel         -hangul_input    +netbeans_intg   +textobjects +cindent         +iconv           +num64           +timers -clientserver    +insert_expand   +packages        +title -clipboard       +job             +path_extra      -toolbar +cmdline_compl   +jumplist        -perl            +user_commands +cmdline_hist    -keymap          +persistent_undo +vertsplit +cmdline_info    +lambda          +postscript      +virtualedit +comments        -langmap         +printer         +visual -conceal         +libcall         -profile         +visualextra +cryptv          +linebreak       +python/dyn      +viminfo +cscope          +lispindent      -python3         +vreplace +cursorbind      +listcmds        +quickfix        +wildignore +cursorshape     +localmap        +reltime         +wildmenu +dialog_con      -lua             -rightleft       +windows +diff            +menu            +ruby/dyn        +writebackup +digraphs        +mksession       +scrollbind      -X11 -dnd             +modify_fname    +signs           -xfontset -ebcdic          +mouse           +smartindent     -xim -emacs_tags      -mouseshape      +startuptime     -xpm +eval            -mouse_dec       +statusline      -xsmp +ex_extra        -mouse_gpm       -sun_workshop    -xterm_clipboard +extra_search    -mouse_jsbterm   +syntax          -xterm_save -farsi           -mouse_netterm   +tag_binary    system vimrc file: "$VIM/vimrc"      user vimrc file: "$HOME/.vimrc"  2nd user vimrc file: "~/.vim/vimrc"       user exrc file: "$HOME/.exrc"        defaults file: "$VIMRUNTIME/defaults.vim"   fall-back for $VIM: "/usr/share/vim" Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H   -DMACOS_X_UNIX  -g -O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 Linking: gcc   -L/usr/local/lib -o vim        -lm -lncurses  -liconv -framework Cocoa 

EDIT 2

I now noticed that when i try to reload my .vimrc file, i get the following error:

Error detected while processing /usr/share/vim/vim80/syntax/syntax.vim: line   42: E216: No such group or event: filetypedetect BufRead 

Which points me in the direction of changing my runtimepath value, but i don't have that defined anywhere. I've tried adding it to my .vimrc, but i still get the same error after reloading.

I've placed it at the top of the document (right after set nocompatible, so perhaps the position could be the issue, but if so, where should i place it then?

2 Answers

Answers 1

Damnit, i was missing a + character in line 6

set set rtp=~/.vim/bundle/Vundle.vim should have been set rtp+=~/.vim/bundle/Vundle.vim. Now it works!

Answers 2

Make sure you can :source ~/.vimrc successfully with no error when you edit update ~/.vimrc.

Step to do source vimrc:

  1. vim ~/.vimrc
  2. type :source ~/.vimrc
  3. enter
Read More

Wednesday, March 21, 2018

How to call js completion in html file instead of js file?

Leave a Comment

I had installed tern_for_vim and YouCompleteMe for js completion this way.

1 install node

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.2/install.sh | bash source ~/.nvm/nvm.sh nvm install node 

2 install tern_for_vim

$ cd ~/.vim/bundle git clone https://github.com/marijnh/tern_for_vim 

3 install YouCompleteMe

cd ~/.vim/bundle/YouCompleteMe $ ./install.sh --clang-completer --tern-completer 

4 edit .tern-project

vim  .tern-project   {     "libs": [         "browser",         "underscore",         "jquery"     ],     "plugins": {         "node": {}     } } 

Now to vim test.js.
The js completion pop up after inputing document. in test.js file.
enter image description here

Then to vim test.html
No js completion pop up after inputing document. in test.html file.
How to fix it?

2 Answers

Answers 1

Unfortunately this is not officially supported by tern. You can see the response in a closed issue

https://github.com/ternjs/tern_for_vim/issues/170

Because the parsing logic for separating HTML and scripts hasn't been implemented. This could be done as a plugin, if you want to take a shot at it, but it's out of scope for this repository.

But then there is another thread on SO which may help you

Using tern_for_vim plugin in HTML files

So best is to include your code in the html through a JS file and then edit the JS file. Else look at some other plugin/IDE environment. I would explore the below option as well

https://github.com/Shougo/deoplete.nvim#install

Answers 2

I'm unfamiliar with tern_for_vim and YouCompleteMe for js completion, however you could always use vim's built in omni-func completion.

If you add:

filetype on filetype plugin on set omnifunc=syntaxcomplete#Complete 

to your vimrc file, you can then manually set the filetype of your html file to javascript with :set filetype=javascript whilst in vim. Following that, when in insert mode, you can then use <C-x> followed by <C-o> to access javascript language specific omni completion.

The resulting completion menu is then navigable by the standard <C-p> for up and <C-n> for down hotkeys.

This, along with other bits of built in completion functionality are discussed in a nice thoughtbot talk.

Read More

Wednesday, May 31, 2017

How to create the strings sequence into specified line in edited text?

Leave a Comment

Here is the initial text.

test1 test2 

Only two lines in the text.

I want to insert strings sequence into from 5th line into 16th line. I have tried it with below codes.

for i in range(1,12)       echo ".item".i."," endfor   

1.the initial text.
enter image description here 2.to enter into command mode and input the codes

enter image description here

Two problems to be solved.
1.echo command output the first string .item1 before endfor.

for i in range(1,12)       echo ".item".i."," 

2.How create the strings sequence into specified line:from 5th till 16th in edited text with vimscript?

The desired result is as below.

enter image description here

Almost done!
What i get is as below with the command :pu! =map(range(1,12), 'printf(''item%1d'', v:val)').

Both of them can't work.

:5pu! =map(range(1,12), 'printf(''item%1d'', v:val)') :5,16pu! =map(range(1,12), 'printf(''item%1d'', v:val)') 

enter image description here

The last issue for my desired format is when the cursor is on the 3th line ,how to create the desired output?

2 Answers

Answers 1

In order to insert the missing lines, without inserting unrequired empty lines (-> append() + repeat([''], nb) + possible negative nb)

:let lin = 5 - 1 :call append('$', repeat([''], lin-line('$'))) 

Then, in order to insert what you're looking for (no need for printf() if you don't want to format the numbers)

:call append(lin, map(range(1,12), '"item".v:val')) 

PS: I'd rather avoid :put when I can as it's kind of difficult to use with complex expressions.

Answers 2

Assuming you are in a Unix based operating system, you have a seq command. So you can do:

$ seq -f 'Item %.0f' 20 Item 1 Item 2 ... Item 20 

Inside vim you can try the reading from external command approach:

:r! seq -f 'Item \%.0f' 20 
Read More

Wednesday, April 26, 2017

Vim YouCompeleteMe doesn't update list as I type?

Leave a Comment

There is a popup list as I type Python, but it doesn't get updated (narrow down) with what I've already typed. Weirdly, as soon as I start deleting a character, the suggestion list gets updated correctly (as shown below).

enter image description here

I am using the default config. In my .vimrc, I only have one line for YCM

let g:ycm_global_ycm_extra_conf='~/.ycm_extra_conf.py' 

and that .ycm_extra_conf.py is the one shipped together with YCM in YouCompleteMe/third_party/ycmd/examples/.

How can I fix this?

1 Answers

Answers 1

You need to set this in your .vimrc

let g:ycm_auto_trigger = 1   

See here for this.

Read More

Wednesday, September 28, 2016

Show multilayer function relationship by cscope in vim

Leave a Comment

I know source insight can show multilayer function relationship in one window.

For example, we have four functions as below

void example_A() {     example_B(); }  void example_B() {     example_C(); }  void example_C() {     example_D(); }  void example_D(); {     return 5; } 

When I click example_D() in source insight, source insight show example_C() is calling the function.

Moreover, when I click example_C(), I see example_B() is calling the function.

The relationship is like this:

Example_D()    |    -->Example_C()          |          -->Example_B()                |                -->Example_A() 

Could I see the relationship in one window by using cscope in vim?

Thank you.

1 Answers

Answers 1

CCTRee plugin for vim does this kind of visualization using cscope

https://sites.google.com/site/vimcctree/

http://www.vim.org/scripts/script.php?script_id=2368

https://github.com/hari-rangarajan/CCTree

Read More

Friday, April 22, 2016

How can I fix this error when making vim on Fedora 23

Leave a Comment

I am trying to build vim with the following options on my Fedora 23

I want +python +python3 +perl +lua +ruby +gui +conceal +gui for some plugins.

I could not find a version with all those built in (so I do it myself)

The journey started by following Valloric

sudo yum install -y ruby ruby-devel lua lua-devel luajit \     luajit-devel ctags git python python-devel \     python3 python3-devel tcl-devel \     perl perl-devel perl-ExtUtils-ParseXS \     perl-ExtUtils-XSpp perl-ExtUtils-CBuilder \     perl-ExtUtils-Embed 

I also have ncurses (raw,devel,static,...)

Then

$ cd $HOME/Sources $ git clone https://github.com/vim/vim.git $ cd vim $ ./configure --with-tlib=ncurses \               --with-features=huge \               --enable-fail-if-missing \               --enable-luainterp=yes \               --enable-mzschemeinterp \               --enable-perlinterp \               --enable-pythoninterp=yes \               --with-python-config-dir=/usr/lib64/python2.7/config \               --enable-python3interp=yes \               --enable-tclinterp=yes \               --enable-rubyinterp=yes \               --enable-cscope \               --enable-multibyte \               --enable-gui=auto \               --prefix=$HOME/Build/vim \               --with-compiledby=statquant | tee configure.log 

The following is printed on screen:

/home/statquant/Sources/vim/src/config-PyMake3137:1478: warning: overriding recipe for target 'Modules/_math.o' /home/statquant/Sources/vim/src/config-PyMake3137:1475: warning: ignoring old recipe for target 'Modules/_math.o' /home/statquant/Sources/vim/src/config-PyMake3137:1517: warning: overriding recipe for target 'Modules/timemodule.o' /home/statquant/Sources/vim/src/config-PyMake3137:1482: warning: ignoring old recipe for target 'Modules/timemodule.o' configure: error: NOT FOUND!       You need to install a terminal library; for example ncurses.       Or specify the name of the library with --with-tlib. 

Then I

make | tee make.log

I realized that it actually built vim in $HOME/Sources/vim/src instead of $HOME/Build/vim (maybe I was wrong to expect that)

When I run :version on ./vim -g (vim has been build with GUI support) there is NO python NO python3 .... enter image description here

configure.log is there, make.log is there

EDIT1: the following works, I now only miss +perl +ruby

./configure --with-features=huge \        --enable-tclinterp=yes \        --enable-luainterp=yes \        --enable-pythoninterp=yes \        --enable-python3interp=yes \        --with-compiledby=statquant \        --prefix=$HOME/Build/vim \  make install # and yes it installs in $HOME/Build/vim   

enter image description here

EDIT2 Here is what happen when I try to add

  1. +perl

I can run

./configure --with-features=huge \             --enable-tclinterp=yes \             --enable-luainterp=yes \             --enable-pythoninterp=yes \             --enable-python3interp=yes \             --enable-perlinterp=yes \             --prefix=$HOME/Build/vim \             --with-compiledby=statquant | tee configure.log 

It appears to work (no error) : configure.log

make | tee make.log [...] cc1: error: -Wformat-security ignored without -Wformat [-Werror=format-security] <command-line>:0:0: warning: "_FORTIFY_SOURCE" redefined <command-line>:0:0: note: this is the location of the previous definition cc1: some warnings being treated as errors make[1]: *** [objects/option.o] Error 1 Makefile:2907: recipe for target 'objects/option.o' failed make[1]: Leaving directory '/home/statquant/Sources/vim/src' make: *** [first] Error 2 Makefile:26: recipe for target 'first' failed 

I get no vim built in /home/statquant/Sources/vim/src : make.log

  1. +ruby

    ./configure --with-features=huge \ --enable-tclinterp=yes \ --enable-luainterp=yes \ --enable-pythoninterp=yes \ --enable-python3interp=yes \ --enable-rubyinterp=yes \ --prefix=$HOME/Build/vim \ --with-compiledby=statquant | tee configure.log

It does not even run configure

checking --with-tlib argument... empty: automatic terminal library selection checking for tgetent in -ltinfo... no checking for tgetent in -lncurses... no checking for tgetent in -ltermlib... no checking for tgetent in -ltermcap... no checking for tgetent in -lcurses... no no terminal library found checking for tgetent()... configure: error: NOT FOUND!       You need to install a terminal library; for example ncurses.       Or specify the name of the library with --with-tlib. 

Here is the log: configure.log

3 Answers

Answers 1

You have enabled -Werror=format-security. This treats any susceptible usage of format of printf or scanf currently treated as `error.

You can either fix the usage in if_perl.c, I believe this is generated file. or remove the flag -Werror=format-security

Answers 2

The python problem was this...

--with-python-config-dir=/usr/lib64/python2.7/config \ --enable-python3interp=yes \ 

Version 2 config with a version 3 interpreter.

Your missing the ncurses-devel library, I can see that you dropped it from configure.

sudo yum install ncurses-devel 

configure actually worked for me even when I didn't have the perl dev packages installed ie it didn't fail asking me to install them which I found odd. Do you have all the dev packages you need installed.

sudo yum install perl-devel sudo yum install ruby-devel 

Answers 3

If you are missing some dev package for ruby or perl the configure script say something like : "disabling this option". Just did this with ruby. After installing the ruby-dev package the ruby option is enabled in vim. Same with libperl-dev.

Read More

Thursday, March 31, 2016

Internal ruby error in vim

Leave a Comment

I've been having this problem for a while with vim. The first time I do anything that interacts with ruby, such as :ruby puts "test", I get <internal:gem_prelude>:1:in 'require': cannot load such file -- rubygems.rb (LoadError).

Some diagnostic information that may be useful : my OS is OS X 10.11.2, Vim is version 7.4, ruby is 2.1.2 installed with rvm, my shell is zsh (but this also happens with bash), and my vim is completely vanilla.

 $  ruby --version ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-darwin13.0]  $  rvm list  rvm rubies  =* ruby-2.1.2 [ x86_64 ]  # => - current # =* - current && default #  * - default   $  which -a ruby /Users/marcusbuffett/.rvm/rubies/ruby-2.1.2/bin/ruby /usr/local/bin/ruby /usr/local/bin/ruby /usr/bin/ruby  $  vim --version VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Mar 18 2016 09:07:16) MacOS X (unix) version Included patches: 1-1401 Compiled by Homebrew Huge version without GUI.  Features included (+) or not (-): +acl             +farsi           +mouse_netterm   +syntax +arabic          +file_in_path    +mouse_sgr       +tag_binary +autocmd         +find_in_path    -mouse_sysmouse  +tag_old_static -balloon_eval    +float           +mouse_urxvt     -tag_any_white -browse          +folding         +mouse_xterm     -tcl ++builtin_terms  -footer          +multi_byte      +terminfo +byte_offset     +fork()          +multi_lang      +termresponse +channel         -gettext         -mzscheme        +textobjects +cindent         -hangul_input    +netbeans_intg   +title -clientserver    +iconv           +packages        -toolbar +clipboard       +insert_expand   +path_extra      +user_commands +cmdline_compl   +job             +perl            +vertsplit +cmdline_hist    +jumplist        +persistent_undo +virtualedit +cmdline_info    +keymap          +postscript      +visual +comments        +langmap         +printer         +visualextra +conceal         +libcall         +profile         +viminfo +cryptv          +linebreak       +python          +vreplace +cscope          +lispindent      -python3         +wildignore +cursorbind      +listcmds        +quickfix        +wildmenu +cursorshape     +localmap        +reltime         +windows +dialog_con      -lua             +rightleft       +writebackup +diff            +menu            +ruby            -X11 +digraphs        +mksession       +scrollbind      -xfontset -dnd             +modify_fname    +signs           -xim -ebcdic          +mouse           +smartindent     -xsmp +emacs_tags      -mouseshape      -sniff           -xterm_clipboard +eval            +mouse_dec       +startuptime     -xterm_save +ex_extra        -mouse_gpm       +statusline      -xpm +extra_search    -mouse_jsbterm   -sun_workshop    system vimrc file: "$VIM/vimrc"      user vimrc file: "$HOME/.vimrc"  2nd user vimrc file: "~/.vim/vimrc"       user exrc file: "$HOME/.exrc"   fall-back for $VIM: "/usr/local/share/vim" Compilation: /usr/bin/clang -c -I. -Iproto -DHAVE_CONFIG_H   -F/usr/local/Frameworks -DMACOS_X_UNIX  -Os -w -pipe -march=native -mmacosx-version-min=10.11 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 Linking: /usr/bin/clang   -L. -L/Users/travis/.sm/pkg/active/lib -fPIC -Bstatic -fstack-protector -L/usr/local/lib -F/usr/local/Frameworks -Wl,-headerpad_max_install_names -o vim        -lm  -lncurses -liconv -framework Cocoa   -fstack-protector  -L/System/Library/Perl/5.18/darwin-thread-multi-2level/CORE -lperl -framework Python   -lruby-static -framework CoreFoundation -lobjc -L/Users/marcusbuffett/.rvm/rubies/ruby-2.1.2/lib 

1 Answers

Answers 1

Assuming that ruby works for you normally when using from the command line, I suspect that the problem comes from the fact that you are trying to use a RVM ruby in VIM and VIM doesn't use a login shell by default. RVM, on the other hand has it's initialization done in the shell init scripts, which are run only in login shells, which you get e.g. when you open a terminal.

Now, as you have also a system ruby installed in /usr/local, VIM sees this system ruby instead of the RVM one. And I guess you don't have rubygems installed in the system ruby.

So, one quick method is to force VIM to use the login shell, so that it behaves the same way as your command line. This is answered in this SO question, and I quote from there:

# ~/.vimrc set shell=bash\ -l 

Another option would be to manually set the VIM PATH so that the first found ruby is the one from RVM, not the system one.

Read More