Vim

From The World according to Vissie
Jump to navigation Jump to search

Install vim

For neocomplete, I used vim nox

sudo apt-get install vim-nox

Install neovim

From now on, because of ncm2, I will be using neovim

https://github.com/neovim/neovim/releases

The folder locations got me a little bit when I started to look at and working with neovim. This is very useful:

:help runtimepath


Plug in manager

Download vim-plug

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

Place that in your ~/.vim/autoload folder. Then add this:

vim: ~/.vimrc
call plug#begin()
" Make sure you use single quotes
Plug  'Shougo/neocomplete.vim'
" Add plugins to &runtimepath
call plug#end()
:PlugInstall

If your mouse goes not want to copy/past

:set mouse=r

Virtual block mode

I keep on forgetting! To select text vertically, any old way actually, do the following:

ctl-q (windows), ctl-v (linux)

Do you select

shift I

Then add your text.

To delete, it is similair, but easier.

ctl-q (windows), ctl-v (linux)

Select, hit Del. Done

And yet another way:

Move to the beginning of a line
enter Visual Block mode (CTRL-v)
select the lines you want (moving up/down with j/k, or jumping to a line with [line]G)
press I (that's capital i)
type the comment character(s)
press ESC

Another way that might be easier for newcomers:

Place the cursor on the first line, e.g. by

and type the following to get into insert mode and add your text:

I / / Space

// █some
code
here

Press Esc to get back to command mode and use the digraph:

j . j .

// some
// code
//█here

j is a motion command to go down one line and . repeats the last editing command you made.


Search

If you copy paste text from external sources into Vim, you might end up with non-ASCII characters.

To find the non-ASCII characters in the file open in Vim, try this search:

/[^\x00-\x7F]

This tries to highlight all the characters that lie outside the given range, that is the ASCII range.

Convert all text to lowercase

ggguG

gg - Goto the first line 
g  - start to converting from current line    
u  - Convert into lower case for all characters
G  - To end of the file.

Add a character at the end of each line

:%norm A,

Vim with auto-complete

Firstly, to understand some basics of how VIM works, read this page. Make sure you understand (in a very rough way) what each directory we've talked about does. And I'm not kidding.

http://learnvimscriptthehardway.stevelosh.com/chapters/42.html

I have tried this:

https://github.com/Shougo/neocomplete.vim

Works well on Windows. I will test on Linux later (at home)

And, to change the colors, edit your color file, I use vibrantink. Add to your GUI(Windows) section:

   highlight Pmenu       guibg=#333333
   highlight PmenuSel    guifg=#29a329 guibg=Black
   highlight PmenuSbar   guibg=#d6d6d6
   highlight PmenuThumb  guifg=#3cac3c

For a custom dictionary file use:

let  g:neocomplete#sources#dictionary#dictionaries = {
     \ '_' : 'C:\Data\Vim\vissie.txt'
     \ } 

Note the "_", that will load this file always.

Syntax file for OpenSCAD:

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

You need a "File Type Detect" (ftdetect) file to set the file extension type.

Color schemes

Make sure that your terminal used 256 colors in ~/.bashrc or /etc/bash.bashrc

if [ "$COLORTERM" == "gnome-terminal" ]; then 
    export TERM=xterm-256color 
fi 

If you plan to use screen multiplexer, you'll also have to assure, that your ~/.screenrc contains the following stuff:

term screen-256color 
attrcolor b ".I" 
# Tell screen how to set colors. AB = background, AF=foreground 
termcapinfo xterm 'Co#256:AB=\E[48;5;%dm:AF=\E[38;5;%dm' 
# Erase background with current bg color.  Not needed if TERM=screen-256color 
defbce "on" 
vim: ~/.vim/ftdetect/openscad.vim
au BufRead,BufNewFile *.scad    set filetype=openscad

Setup fonts

The easiest way of setting the 'guifont' is simply not bothering with the exact font string at all.

Use a friendly dialog to set it instead:

:set guifont=*

This pops up a dialog where you can select your preferred font.

Once you have set it, you can query the setting again with

:set guifont?

and put that string in your vimrc. On my machine this returns Monaco:h12 for Monaco at 12pt. Make the change at the appropriate place in your block, or, if you have no idea what you're doing, simply replace the whole block with

if has("gui_running")
  set guifont=Monaco:h12
endif