My NeoVim Config File

set nocompatible

filetype off

" Line numbers on:
set nu

" Use 256 colors:
set t_Co=256

" Use UTF-8 by default:
set encoding=utf-8

" Remap leader key to space bar:
let mapleader = "\<space>"

"""""""""""""""""""""""""""""""""
"""" Plugins """"""""""""""""""""
"""""""""""""""""""""""""""""""""
call plug#begin()

" Folding:
Plug 'tmhedberg/SimpylFold'
" See docstrings for folded code:
let g:SimplyFold_docstring_preview=1

" PEP8 indentation
Plug 'vim-scripts/indentpython.vim'

" Matching brackets, parens, ...:
Plug 'tpope/vim-surround'

" HTML Tags (for docs see https://docs.emmet.io/):
Plug 'mattn/emmet-vim'
" Use ctrl-a+comma to activate emmet-vim (default is ctrl-y+comma)
let g:user_emmet_expandabbr_key = '<C-a>,'

" Easymotion (see https://github.com/easymotion/vim-easymotion):
Plug 'easymotion/vim-easymotion'
" Type <leader><leader>[action] (e.g. <leader><leader>w) to invoke easymotion

" Completion:
Plug 'Valloric/YouCompleteMe'
" Ensure auto-completion window goes away when we're done with it:
let g:ycm_autoclose_preview_window_after_completion=1
" Define shortcut for goto definition:
" map <leader>g  :YcmCompleter GoToDefinitionElseDeclaration<CR>

" vim-jedi for "IDE" functions:
Plug 'davidhalter/jedi-vim'
" disable autocompletion, since we use YCM for that:
let g:jedi#completions_enabled = 0
" open the go-to function in split, not another buffer:
let g:jedi#use_splits_not_buffers = "right"
" vim-jedi shortcuts:
" <leader>d -> go to definition
" <leader>n -> show usage of a name in the current file
" <leader>r -> rename
" K -> show documentation


" Commenting:
Plug 'scrooloose/nerdcommenter'
" nerdcommentor options:
" Allow commenting and inverting empty lines (useful when commenting a region)
let g:NERDCommentEmptyLines = 1
" Enable trimming of trailing whitespace when uncommenting
let g:NERDTrimTrailingWhitespace = 1
" For more options, see https://github.com/scrooloose/nerdcommenter

" A couple of color scheme plugins:
Plug 'jnurmine/Zenburn'
Plug 'altercation/vim-colors-solarized'
colorscheme blue

" A file browser:
Plug 'scrooloose/nerdtree'
" Tell file browser to ignore clutter:
let NERDTreeIgnore=['\.pyc$', '\~$']
" Use F3 to toggle nerdtree:
nnoremap <silent> <F3> :NERDTreeToggle<CR>
" Search:
Plug 'kien/ctrlp.vim'

" Git integration:
Plug 'tpope/vim-fugitive'

" Status line (using Vim-Airline instead of Powerline):
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'

" PEP8 formatting:
Plug 'psf/black'

" All of your Plugins must be added before the following line
call plug#end()            " required
"""""""""""""""""""""""""""""""""
"""" End of Plugins """""""""""""
"""""""""""""""""""""""""""""""""

" Specify where splits should occur:
set splitbelow
set splitright

" split navigation:
nnoremap <C-J> <C-W><C-J>
nnoremap <C-K> <C-W><C-K>
nnoremap <C-L> <C-W><C-L>
nnoremap <C-H> <C-W><C-H>

" code folding:
set foldmethod=indent
set foldlevel=99

" For Python files:
"   four spaces for tab, line length <= 80, Unix line endings:
au BufNewFile,BufRead *.py
     \ | set tabstop=4
     \ | set softtabstop=4
     \ | set shiftwidth=4
     \ | set textwidth=79
     \ | set expandtab
     \ | set autoindent
     \ |set fileformat=unix 
" And for some other file types:
au BufNewFile,BufRead *.js, *.html, *.css
    \ set tabstop=2 \
    \ | set softtabstop=2 \
    \ | set shiftwidth=2

" If in virtual environment, tell
" nvim to use the system Python instead of the one in the venv:
" Figure out the system Python for Neovim.
" NOTE: pynvim must be installed (pip install pynvim) in each
" virtual environment where nvim will be used.
if exists("$VIRTUAL_ENV")
    let g:python3_host_prog=substitute(system("which -a python3 | head -n2 | tail -n1"), "\n", '', 'g')
else
    let g:python3_host_prog=substitute(system("which python3"), "\n", '', 'g')
endif

" In addition, check if we're in a virtual environment.
" If so, activate it. Among other things, this
" allows YCM to be aware of all packages installed
" in that environment.
py3 << EOF
import os
import sys
if 'VIRTUAL_ENV' in os.environ:
  project_base_dir = os.environ['VIRTUAL_ENV']
  activate_this = os.path.join(project_base_dir, 'bin/activate_this.py')
  exec(open(activate_this).read(), {'__file__': activate_this})
EOF

let python_highlight_all=1
syntax on

" If nvim is started with no file or directory named on the command line,
" or if a directory is named on the command line, start NerdTree:
autocmd StdinReadPre * let s:std_in=1
autocmd VimEnter * if argc() == 0 && !exists("s:std_in") | NERDTree | endif
autocmd VimEnter * if argc() == 1 && isdirectory(argv()[0]) && !exists("s:std_in") | exe 'NERDTree' argv()[0] | wincmd p | ene | exe 'cd '.argv()[0] | endif

How to Change the Leader Key in Vim

I have to look this up every time I need to do it, so I’m posting this for myself. (Of course, it would be better to keep track of my .vimrc so I wouldn’t have to do it from scratch!)

Add to your .vimrc:

let mapleader = <space> (or whatever key you want)

Installing YouCompleteMe Plugin for Vim in Ubuntu

Featured

The YouCompleteMe plugin (YCM) provides “Intellisense-like” features within Vim. Setting it up requires several steps:

  1. Install the plugin using any Vim plugin manager. For example, if you use Vundle, you would add to your .vimrc:
    • Plugin ‘Valloric/YouCompleteMe’
  2. Install development tools:
    • sudo apt install build-essential cmake python3-dev
  3. Install Ubuntu packages on which YCM depends for the programming languages you plan on using:
    1. For C and C++ support: sudo apt install clang-8 libclang1-8 clang-tools-8
    2. For C# support: sudo apt install mono-complete
    3. For JavaScript and TypeScript: sudo apt install nodejs npm
    4. For others, see the YCM documentation at https://github.com/ycm-core/YouCompleteMe
  4. Run the YCM install.py script with flags appropriate to the above languages:
    • For C and C++: --clang-completer
    • For C#: –cs-completer
    • –ts-completer
    • For example, if you want support for all three of the above language groups, you would do:
      • cd ~/.vim/bundle/YouCompleteMe
      • python3 ./install.py –clang-completer –cs-completer –ts-completer

Schematic for creating 3-tier JSF/JPA application in Eclipse

JPA Layer:
1. Make project

2. Make DB connection

3. Convert project to JPA project — use connection from step 2

4. Make JPA entities – give them properties
4a List them as “managed” in persistence.xml

5. Make tables

EJB (business logic) Layer:
1. Make EJB classes that manipulate JPA entities in JPA layer.

2. Annotate EJB classes as:
@Stateless
@LocalBean
and:
@PersistenceContext
EntityManager em;

3. Give the EJB classes methods to be called from the View layer

View Layer (Web, specifically)
0. If faces-config.xml doesn’t exist, do Project Properties->JPA
->Project Facets

1. In faces-config.xml, make new Managed Bean classes. Give them
Session scope.

2. Annotate them with:
@EJB
BookEJB bookEJB; // for example

3. Put properties in the managed bean classes that will be
bound to the fields in the web pages.

4. Make methods in the managed bean classes that will be bound to
the buttons/links etc. in the web pages. The methods should return
strings that tell the JSF engine which page to load next.

5. Make xhtml file(s). Be sure to put the following before the
header:
xmlns:ui=”http://java.sun.com/jsf/facelets”
xmlns:h=”http://java.sun.com/jsf/html”
xmlns:f=”http://java.sun.com/jsf/core”
Order matters.

6. Make a form. Put components in the form that are bound to the
managed bean class properties.

Installing Oracle Java on Ubuntu – summary

Each time I do this, I have to search the Web to remember where the PPA is and what packages to install, so this time I’m summarizing the steps here:

  1. Add the WebUpd8Team Java PPA:
    sudo add-apt-repository ppa:webupd8team/java
  2. Install the installer package (downloads the Oracle installer from Oracle’s repository):
    sudo apt-get update
    sudo apt-get install oracle-java7-installer
  3. To set up required environment variables:
    sudo apt-get install oracle-java7-set-default

For details and troubleshooting tips, see: https://coderwall.com/p/xii-fq

 

 

Fixing “Failed to Create the SD Card” using Android Tools

I use Eclipse and run the ADT stuff within it. I tried to create a new Android virtual machine and kept getting the error mentioned in the title. I verified all permissions in all applicable directories, and still had no luck.

It turned out the problem was that I was running the ADT on 64-bit Linux (Mint 17, to be specific), and I needed to install a couple of 32-bit libraries. Here is the list:
libstdc++6:i386 libgcc1:i386 zlib1g:i386 libncurses5:i386

Thanks to Pavel Kazlou for providing the list here:

http://stackoverflow.com/questions/3878445/ubuntu-error-failed-to-create-the-sd-card

 

Speeding up Android Emulator

This is a reminder of the steps required to use kvm/hardware acceleration in the Android Emulator, in case I need to re-do them.

They’re taken from here: https://software.intel.com/en-us/android/articles/speeding-up-the-android-emulator-on-intel-architecture#_Toc358213272

(The link also has instructions for Windows and Mac, in case any of you haven’t switched to Linux yet.)

In brief, the steps are:

  1. Verify hardware support by typing
    egrep –c ‘(vmx|svm)’ /proc/cpuinfo

    (result should not be 0).
  2. Install required packages:
    sudo apt-get install qemu-kvm libvirt-bin ubuntu-vm-builder bridge-utils
  3. Add yourself to the kvm and libvirtd groups; log out and log in again.
  4. Install “Intel x86 Atom System Image” in Android SDK Manager
  5. (If using Eclipse, shut it down and restart it.)
  6. Create a new device in the Android Virtual Device Manager, selecting the new system image for the “CPU/ABI” option.