Vim autocomplete

Does anyone use autocomplete in Vim? I’ve been trying to get it working with one or the other of the available plugins. The first does not work at all and the second kinda-sorta works but the results bear little resemblance to the animation on its Github page, or compared to the excellent way autocomplete works in Sublime Text. Does anyone have any advice? If so then I’ll give a fuller description (quite a saga, actually) of the steps I went through.

Bro I’m clueless, but I found this

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

I use YCM, but haven’t touched rust in a few months. What part of it works, and which part of it doesn’t?

Yes it works, you can use my dot files if you want. It uses YCM to do autocomplete via racer. GitHub - dirvine/dotfiles: my dotfiles, probably no use to anyone else vim/tmux/zsh etc. in there

3 Likes

Thanks for the offer of your dotfiles @dirvine . Your .vimrc is completely different from mine (which is much simpler) but the main thing is you are using Vim-addon-manager while I’m using Vundle for managing my three plugins, and YCM says in its readme to use Vundle. I’d like to try a bit longer to get it working rather than tear my .vimrc apart and rebuild it with many things that I don’t understand.

@smacz this is what YCM looks like when it works (but most of the time when i’m typing, it doesn’t pop up anything. As you can see, the list is not as helpful as what is shown in the YCM Git page’s animation, in particular it contains long useless paths to definition files.

Following is my .vimrc. Note also that I compiled Vim with the Python enabled flag set, and have the latest Python 2 (i.e., version 2.7.12)

"------------------------------------------------------------
" Vundle Setup

set nocompatible				" Required by Vundle
filetype off					" Required by Vundle
syntax on                       " Enable syntax highlighting

" Set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()


"------------------------------------------------------------
" Plugins

" Let Vundle manage Vundle, required
Plugin 'VundleVim/Vundle.vim'

" Autoformat
Plugin 'Chiel92/vim-autoformat'

" Rust syntax highlighting
Plugin 'rust-lang/rust.vim'


" Rust settings
set hidden
filetype on
let RUST_SRC_PATH="/home/user/rust/src/"

" YouCompleteMe autocompleter
Plugin 'Valloric/YouCompleteMe'

" 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
" ":Autoformat" to automatically format your code (for Rust or any other
"		formatter that is installed)

" see :h vundle for more details or wiki for FAQ
" Put your non-Plugin stuff after this line


"------------------------------------------------------------
" Features and Options

" Better command-line completion
set wildmenu

" Show partial commands in the last line of the screen
set showcmd

" Highlight searches (use  to temporarily turn off highlighting; see the
" mapping of  below)
set hlsearch

" Modelines have historically been a source of security vulnerabilities. As
" such, it may be a good idea to disable them and use the securemodelines
" script, .
" set nomodeline

" Use case insensitive search, except when using capital letters
set ignorecase
set smartcase

" Allow backspacing over autoindent, line breaks and start of insert action
set backspace=indent,eol,start

" When opening a new line and no filetype-specific indenting is enabled, keep
" the same indent as the line you're currently on. Useful for READMEs, etc.
set autoindent

" Stop certain movements from always going to the first character of a line.
" While this behaviour deviates from that of Vi, it does what most users
" coming from other editors would expect.
set nostartofline

" Display the cursor position on the last line of the screen or in the status
" line of a window
set ruler

" Always display the status line, even if only one window is displayed
set laststatus=2

" Instead of failing a command because of unsaved changes, instead raise a
" dialogue asking if you wish to save changed files.
set confirm

" Use visual bell instead of beeping when doing something wrong
" set visualbell

" And reset the terminal code for the visual bell. If visualbell is set, and
" this line is also included, vim will neither flash nor beep. If visualbell
" is unset, this does nothing.
set t_vb=

" Enable use of the mouse for all modes
set mouse=a

" Display line numbers
set number

" Quickly time out on keycodes, but never time out on mappings
set notimeout ttimeout ttimeoutlen=200

" Use  to toggle between 'paste' and 'nopaste'
set pastetoggle=

" Autoformat on save
au BufWrite * :Autoformat

" Make it obvious where 80 characters is
set textwidth=80
set colorcolumn=+1

" Turn off swapfile (an annoyance if Vim crashes)
" Unnecessary on modern systems
set noswapfile

" Turn off startup message when no file is specified
set shortmess+=I

" Make positioning of new windows more intuitive
set splitbelow
set splitright

"------------------------------------------------------------
" Indentation options

" Indentation settings for using 4 spaces instead of tabs.
" Do not change 'tabstop' from its default value of 8 with this setup.
"set shiftwidth=4
"set softtabstop=4
"set expandtab

" Indentation settings for using hard tabs for indent. Display tabs as
" four characters wide.
set shiftwidth=4
set tabstop=4


"------------------------------------------------------------
" Mappings

" Map the navigation keys to be consistent with both with touch-typing and i3
noremap ; l
noremap l k
noremap k j
noremap j h

" Map Y to act like D and C, i.e. to yank until EOL, rather than act as yy,
" which is the default
map Y y$

" F12 to run Autoformat
map  :Autoformat

" Type a number followed by CR to jump to that line, and
" CR by itself to jump to last line.
nnoremap  G

" e to open Vexplore (explorer, split always, left/right)
noremap e :Vexplore

" s to mean save (not insert)
noremap s :w

" zz to mean save and exit
noremap zz :wq

" qq to mean quit-no-save
noremap qq :q!

" w to move between windows
noremap w 

" Ctrl-j and Ctrl-; to move left and right between words while
" in INSERT mode
:inoremap  b
:inoremap  w

" :inoremap C-x-C-o


"------------------------------------------------------------

Usually I will see something like this (“something” [ID]). If I accept one of the alternatives then it just adds the name of the function (e.g., “main”). Again, this is nothing like the animation. I note that Sublime will fill in all the syntax that goes with the function such as brackets and braces properly formatted. This is all telling me that YCM is finding the src folder and making some kind of sense of it, but falling well short of the mark for a reason I haven’t been able to discover. As it stands, I might as well just rote learn all the functions and type them in full.

I’ll shelve this for now and move on, since there’s work to do.

Today I’ve gone through once again the very long instructions for compiling not only YCM but its dependencies (Vim and Python). Rust source gives the same results as above, and C++ source just gives dismissive “RTFM” error messages. Hmm…

Actually, with syntax highlighting and autoformat, (which took ten minutes to install) and “cheat sheets”, and templates, and simple habit/muscle-memory, I have what I need.

EDIT: A valuable lesson was learning to compile the latest Vim from sources, with its many options. So that’s a keeper.