Difference between revisions of "Neovim Setting up the basics"
From EdWiki
(Created page with "__NOTOC__ === General Setings === To include some basics in your config first create a directory called ''general'' and a file called ''settings.vim'' mkdir ~/.config/nvim/ge...") |
m (→General Setings) |
||
Line 8: | Line 8: | ||
Add the following to ''settings.vim'' | Add the following to ''settings.vim'' | ||
+ | <pre> | ||
" set leader key | " set leader key | ||
let g:mapleader = "\<Space>" | let g:mapleader = "\<Space>" | ||
Line 17: | Line 18: | ||
set pumheight=10 " Makes popup menu smaller | set pumheight=10 " Makes popup menu smaller | ||
set fileencoding=utf-8 " The encoding written to file | set fileencoding=utf-8 " The encoding written to file | ||
− | set ruler | + | set ruler " Show the cursor position all the time |
set cmdheight=2 " More space for displaying messages | set cmdheight=2 " More space for displaying messages | ||
set iskeyword+=- " treat dash separated words as a word text object" | set iskeyword+=- " treat dash separated words as a word text object" | ||
Line 42: | Line 43: | ||
set timeoutlen=500 " By default timeoutlen is 1000 ms | set timeoutlen=500 " By default timeoutlen is 1000 ms | ||
set formatoptions-=cro " Stop newline continution of comments | set formatoptions-=cro " Stop newline continution of comments | ||
− | set clipboard=unnamedplus | + | set clipboard=unnamedplus " Copy paste between vim and everything else |
"set autochdir " Your working directory will always be the same as your working directory | "set autochdir " Your working directory will always be the same as your working directory | ||
Line 49: | Line 50: | ||
" You can't stop me | " You can't stop me | ||
cmap w!! w !sudo tee % | cmap w!! w !sudo tee % | ||
+ | </pre> | ||
Source in init.vim | Source in init.vim |
Revision as of 08:11, 21 February 2021
General Setings
To include some basics in your config first create a directory called general and a file called settings.vim
mkdir ~/.config/nvim/general touch ~/.config/nvim/general/settings.vim
Here is every general setting I use with a brief explanation:
Add the following to settings.vim
" set leader key let g:mapleader = "\<Space>" syntax enable " Enables syntax highlighing set hidden " Required to keep multiple buffers open multiple buffers set nowrap " Display long lines as just one line set encoding=utf-8 " The encoding displayed set pumheight=10 " Makes popup menu smaller set fileencoding=utf-8 " The encoding written to file set ruler " Show the cursor position all the time set cmdheight=2 " More space for displaying messages set iskeyword+=- " treat dash separated words as a word text object" set mouse=a " Enable your mouse set splitbelow " Horizontal splits will automatically be below set splitright " Vertical splits will automatically be to the right set t_Co=256 " Support 256 colors set conceallevel=0 " So that I can see `` in markdown files set tabstop=2 " Insert 2 spaces for a tab set shiftwidth=2 " Change the number of space characters inserted for indentation set smarttab " Makes tabbing smarter will realize you have 2 vs 4 set expandtab " Converts tabs to spaces set smartindent " Makes indenting smart set autoindent " Good auto indent set laststatus=0 " Always display the status line set number " Line numbers set cursorline " Enable highlighting of the current line set background=dark " tell vim what the background color looks like set showtabline=2 " Always show tabs set noshowmode " We don't need to see things like -- INSERT -- anymore set nobackup " This is recommended by coc set nowritebackup " This is recommended by coc set updatetime=300 " Faster completion set timeoutlen=500 " By default timeoutlen is 1000 ms set formatoptions-=cro " Stop newline continution of comments set clipboard=unnamedplus " Copy paste between vim and everything else "set autochdir " Your working directory will always be the same as your working directory au! BufWritePost $MYVIMRC source % " auto source when writing to init.vm alternatively you can run :source $MYVIMRC " You can't stop me cmap w!! w !sudo tee %
Source in init.vim
source $HOME/.config/nvim/general/settings.vim
Mapping new keys
Again we'll create a directory called keys and and a file called mappings.vim
mkdir ~/.config/nvim/keys touch ~/.config/nvim/keys/mappings.vim
Add the following to mappings.vim:
" Better nav for omnicomplete inoremap <expr> <c-j> ("\<C-n>") inoremap <expr> <c-k> ("\<C-p>") " Use alt + hjkl to resize windows nnoremap <M-j> :resize -2<CR> nnoremap <M-k> :resize +2<CR> nnoremap <M-h> :vertical resize -2<CR> nnoremap <M-l> :vertical resize +2<CR>
" I hate escape more than anything else inoremap jk <Esc> inoremap kj <Esc>
" Easy CAPS inoremap <c-u> <ESC>viwUi nnoremap <c-u> viwU<Esc> " TAB in general mode will move to text buffer nnoremap <TAB> :bnext<CR>
" SHIFT-TAB will go back nnoremap <S-TAB> :bprevious<CR>
" Alternate way to save nnoremap <C-s> :w<CR>
" Alternate way to quit nnoremap <C-Q> :wq!<CR> " Use control-c instead of escape nnoremap <C-c> <Esc>
" <TAB>: completion. inoremap <expr><TAB> pumvisible() ? "\<C-n>" : "\<TAB>" " Better tabbing vnoremap < <gv vnoremap > >gv
" Better window navigation nnoremap <C-h> <C-w>h
nnoremap <C-j> <C-w>j nnoremap <C-k> <C-w>k nnoremap <C-l> <C-w>l nnoremap <Leader>o o<Esc>^Da nnoremap <Leader>O O<Esc>^Da
Source in init.vim
source $HOME/.config/nvim/keys/mappings.vim
Get healthy
Open nvim and enter the following:
- checkhealth
You'll probably notice you don't have support for copy/paste also that python and node haven't been setup
So let's fix that
First we'll fix copy/paste
On mac pbcopy should be builtin On Ubuntu
sudo apt install xsel On Arch Linux
sudo pacman -S xsel Next we need to install python support (node is optional)
Neovim python support
pip install pynvim Neovim node support
npm i -g neovim
Note
If you use virtual environments I highly suggest putting these varibles in your config
I recommend putting this in paths.vim in the general directory
let g:python3_host_prog = expand("<path to python with pynvim installed>") let g:python3_host_prog = expand("~/.miniconda/envs/neovim/bin/python3.8") " <- example let g:node_host_prog = expand("<path to node with neovim installed>") let g:node_host_prog = expand("~/.nvm/versions/node/v12.16.1/bin/node") " <- example
Run checkhealth again and you should now see the requirements are met