15 KiB
title, description, published, date, tags, editor, dateCreated
title | description | published | date | tags | editor | dateCreated |
---|---|---|---|---|---|---|
04 Programming | true | 2024-11-24T11:52:36.975Z | markdown | 2023-04-28T08:02:02.339Z |
Programming
Even if you are not into programming and have no interest in learning it, some of these programs might be useful, in the case of Neovim it is a lot easier to read configuration files for example, If you want to get into programming these programs are an absolute must.
Installing Neovim
We are using Neovim over Vim because Neovim has LSP support
install it using pacman
sudo pacman -S neovim
We will configure it later, we will start with ZSH
Neovim Options and Keybinds
We already installed Neovim in the first step, but we still need to configure it the way we want to. First we need create config files
touch ~/Config/init.vim ~/Config/sysinit.vim
Now we are going to create a symlink for the user config file
ln -sf ~/Config/init.vim ~/.config/nvim/init.vim
Do the same for the global config file
sudo ln -sf ~/Config/sysinit.vim /etc/xdg/nvim/sysinit.vim
We can now set some options, I recommend putting them in the system file this way you have the same configuration with the root user
sv ~/Config/init.vim
Add in the following options, Going over them all is beyond the scope of this guide, But you can look them all up to see what they do exactly.
"Options for Neovim"
:setlocal list
set listchars=eol:↓,tab:··▸,trail:●,extends:…,precedes:…,space:·
set updatetime=300
set shortmess+=c
syntax on
set number
set nu rnu
set tabstop=4
set cursorline
set showcmd
filetype indent on
set wildmenu
set showmatch
set incsearch
set hlsearch
set nospell
set spelllang=en_us
set autoindent
set ruler
set confirm
set cmdheight=2
set shiftwidth=4
set noexpandtab
set hidden
set nowrap
set encoding=utf-8
set pumheight=10
set mouse=a
set splitbelow
set splitright
set t_Co=256
set conceallevel=0
set smarttab
set smartindent
set background=dark
set showtabline=0
set noshowmode
set nobackup
set nowritebackup
set clipboard=unnamedplus
set dir=~/tmp,/tmp
set scrolloff=3
set sidescrolloff=7
set sidescroll=1
set ignorecase smartcase
set undofile
set undodir=~/.nvim/undo
set inccommand=nosplit
set signcolumn=number
set backspace=indent,eol,start
set complete-=i
Now add some keyboard remaps
"Keyboard Remaps"
nmap <C-d> :windo bd<CR>
nmap <A-o> :tabnew<CR>
nmap <A-e> :tabp<CR>
nmap <A-w> :tabn<CR>
nmap <C-o> :ene<CR>
nmap <C-w> :bp<CR>
nmap <C-e> :bn<CR>
nmap <C-n> :vs<CR>
nmap <C-b> :split<CR>
nmap <C-q> :q<CR>
nmap <C-s> :w<CR>
nmap <C-p> :set nu! rnu!<CR>
nmap <A-c> :set list!<CR>
nmap <S-up> :resize +3<CR>
nmap <S-down> :resize -3<CR>
nmap <S-left> :vertical resize +3<CR>
nmap <S-right> :vertical resize -3<CR>
nmap <S-k> :resize +3<CR>
nmap <S-j> :resize -3<CR>
nmap <S-h> :vertical resize +3<CR>
nmap <S-l> :vertical resize -3<CR>
nmap <c-k> :wincmd k<CR>
nmap <c-j> :wincmd j<CR>
nmap <c-h> :wincmd h<CR>
nmap <c-l> :wincmd l<CR>
nmap <c-up> :wincmd k<CR>
nmap <c-down> :wincmd j<CR>
nmap <c-left> :wincmd h<CR>
nmap <c-right> :wincmd l<CR>
nmap <A-j> :m .+1<CR>==
nmap <A-k> :m .-2<CR>==
imap <A-j> <Esc>:m .+1<CR>==gi
imap <A-k> <Esc>:m .-2<CR>==gi
vmap <A-j> :m '>+1<CR>gv=gv
vmap <A-k> :m '<-2<CR>gv=gv
nmap <A-down> :m .+1<CR>==
nmap <A-up> :m .-2<CR>==
imap <A-down> <Esc>:m .+1<CR>==gi
imap <A-up> <Esc>:m .-2<CR>==gi
vmap <A-down> :m '>+1<CR>gv=gv
vmap <A-up> :m '<-2<CR>gv=gv
nmap <A-h> <<
nmap <A-l> >>
imap <A-h> <Esc> <<
imap <A-l> <Esc> >>
vmap <A-h> <
vmap <A-l> >
nmap <A-left> <<
nmap <A-right> >>
imap <A-left> <Esc> <<
imap <A-right> <Esc> >>
vmap <A-left> <
vmap <A-right> >
Neovim Plugins
Vim Plug will be our plugin manager, It will handle most of the work
We will install it system wide
sudo mkdir /etc/xdg/nvim/autoload
sudo curl -o /etc/xdg/nvim/autoload/plug.vim https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
Plugins get installed locally so we have to install plugins for every user seperately, We can make it universal, but this will prevent users from adding their own plugins. With our configuration we can set global plugins for everyone and any extra plugins the user may want using their own init.vim file.
We can add plugins to either init.vim or sysinit.vim If you want to Install for yourself or everyone respectively, they do have to be inside a special block like this.
call plug#begin()
Plug '<link plugin 1>'
Plug '<link plugin 2>''
call plug#end()
You can use PlugUpdate to update and install all selected plugins, PlugClean te remove unselected plugins and, PlugUpgrade to update vim plug itself.
Just add whichever plugin you think will improve your workflow, these are the ones I use.
This plugin will add a ton of icons to Neovim, many of the following plugins will use them, but they are optional.
Plug 'kyazdani42/nvim-web-devicons'
vim-airline is a very cool plugin that gives some color to Neovim, it gives you a powerline with a ton of information, clear visual cues in which mode you are, where you are in the document, how big it is, what type it is, etc.
Plug 'vim-airline/vim-airline'
Barbar is a very nice Tab bar for Neovim, It will help you navigate your open tabs visually instead of just guessing the next or previous tab.
Plug 'romgrk/barbar.nvim'
Nvim-Tree is a directory browser, It is very handy if you want to have an overview of the files in the directory, browse and open them for editing.
Plug 'kyazdani42/nvim-tree.lua'
Be sure to add the Ctrl + T keybind
nmap <C-t> :NvimTreeToggle<CR>
Also add the following to your vim.init somewhere after loading the plugins
lua require("nvim-tree").setup()
Floaterm is a simple terminal which is handy for obvious reasons.
Plug 'voldikss/vim-floaterm'
Be sure to add the Ctrl + Y keybind
nmap <C-y> :FloatermNew --autoclose=2 --wintype=split --height=0.3<CR>
Ctrl P is a great plugin that allows you to open files directly with a hotkey typing (part of) the filename you want to open and press enter to edit it directly.
Plug 'ctrlpvim/ctrlp.vim'
Be sure to add the Ctrl + F Keybind
nmap <C-f> :CtrlP<CR>
Also add the following between the plugin options somewhere after the plug block
let g:ctrlp_map = '<c-/>'
Undotree is a great plugin that allows you to look into your undo history see the acctual changes you made and revert to any of the previous stages of your document, You can also go forward after you went back ofcourse.
Plug 'mbbill/undotree'
Be sure to add the Ctrl + U keymap
nmap <C-u> :UndotreeToggle<CR>
GitGutter is a great plugin that can show you git diffs and much much more git functionality
Plug 'airblade/vim-gitgutter'
Be sure to add the CTRL + G toggle as a keymap to your init.vim
nmap <C-g> :GitGutterToggle<CR>
Nerdcommenter is a handy plugin to comment out lines or a bunch of lines with a single key.
Plug 'preservim/nerdcommenter'
Be sure to add the keymaps for Ctrl + C in normal and visual mode
nmap <C-c> <Plug>NERDCommenterInvert
vmap <C-c> <Plug>NERDCommenterInvert
Autopairs is a simple plugin to handle quotes, brackets and other pairs of characters for you.
Plug 'jiangmiao/auto-pairs'
42Header is something we need to use for school, But I made some little changes to it so it supports changing the ascii art to something like a little Tux :)
Plug 'pbondoer/vim-42header'
Neovim LSP Config
Language Server Protocol is used for live code checking using external Language Servers
For the scope of this guide we will set up a few languages but first we need to install the nvim-lspconfig plugin to make it all a bit easier
Add the following line in your init.vim on a empty line inside the plug block
Plug 'neovim/nvim-lspconfig'
Run the following command to install it
nvim +PlugUpdate +qall
Now we can simply install language servers using pacman and add them to the init.vim file accordingly
Lets start with Bash, simply install the language server using pacman
sudo pacman -S bash-language-server
Now add the language server to your init.vim file of choice
lua require'lspconfig'.bashls.setup{}
Next up is C, Install the language server with pacman
sudo pacman -S ccls
And add the language server to your init.vim file of choice
lua require'lspconfig'.ccls.setup{}
Next up is CSS, Install the language server with pacman
sudo pacman -S vscode-css-languageserver
And add the language server to your init.vim file of choice
lua require'lspconfig'.cssls.setup{}
Next up is HTML, Install the language server with pacman
sudo pacman -S vscode-html-languageserver
And add the language server to your init.vim file of choice
lua require'lspconfig'.html.setup{}
Next up is JS, Install the language server with pacman
sudo pacman -S deno
And add the language server to your init.vim file of choice
lua require'lspconfig'.denols.setup{}
Next up is json, Install the language server with pacman
sudo pacman -S vscode-json-languageserver
And add the language server to your init.vim file of choice
lua require'lspconfig'.jsonls.setup{}
Next up is Lua, Install the language server with pacman
sudo pacman -S lua-language-server
And add the language server to your init.vim file of choice
lua require'lspconfig'.sumneko_lua.setup{}
Next up is Python, Install the language server with pacman
sudo pacman -S pyright
And add the language server to your init.vim file of choice
lua require'lspconfig'.pyright.setup{}
Next up is Rust, Install the language server with pacman
sudo pacman -S rust-analyzer
And add the language server to your init.vim file of choice
lua require'lspconfig'.rust_analyzer.setup{}
Next up is YAML, Install the language server with pacman
sudo pacman -S yaml-language-server
And add the language server to your init.vim file of choice
lua require'lspconfig'.yamlls.setup{}
You can add many many more, just look for nvim plugins online
Hotkeys
Just a simple overview of all the hotkeys you can use
a = Append, Enter Insert mode 1 character after the cursor
b = Move 1 word backwards, Works with numbers
c = Nothing
d = Delete, Deletes a character, double press it to delete the line, also works with numbers and move commands
e = Nothing
f = Find, Finds a character and jumps to that position
g = Goto, enter a line press g twice and you will jump to the line, double press it to go to the first line
h = Left, Same function as the left arrow, but closer to your hand.
i = Insert, Enter Insert mode on the cursor
j = Down, Same function as the down arrow, but closer to your hand.
k = Up, Same function as the up arrow, but closer to your hand.
l = Right, Same function as the right arrow, but closer to your hand.
m = Bookmark position, press m, then press another character to bind it to, use ' to go to the section
n = Nothing
o = Enter insert mode on a new line below the current line.
p = Paste, Pastes the buffer after the current cursor position
q = Record, Press a key after hitting q to start recording, do some stuff and press q again in normal mode to save the recording, then type @key to repeat the action, type 20@key to do it 20 times.
r = Nothing
s = Nothing
t = Nothing
u = Undo your previous action.
v = Visual mode, Switch to Visual mode to select stuff character for character.
w = Move 1 word forward, works with numbers
x = Delete character under the cursor
y = Yank, Or Copy in recent terms, press it once to copy the selection, press it twice to copy the entire line and include a number to copy that amount of line.
z = Nothing
Shift + Arrows = Resize Splits
A = Append, Enter insert mode at the end of the line.
B = Move 1 whitespace backwards
C = Nothing
D = Delete everything on line after the cursor
E = Nothing
F = Find, Finds a character going backwards and jumps to that position
G = Move to the end of the file
H = Make split smaller horizontally
I = Nothing
J = Make split smaller vertically
K = Make split bigger vertically
L = Make split bigger horizontally
M = Nothing
N = Nothing
O = Nothing
P = Paste before cursor
Q = Enter insert mode on a new line above the current line
R = Replace Characters instead of Inserting them
S = Nothing
T = Nothing
U = Nothing
V = Visual Line mode, Select lines to edit, yank, or manipulate
W = Move 1 whitespace forward
X = Nothing
Y = Nothing
Z = Double press it to save and exit
0 = Go to beginning of line
~ = Change case of current character
!
@ = enter @ and then type the letter of the recording made with q to play in
# = Highlight the word you are standing on in the rest of the document
$ = Go to end of line
%
^ = Go to the first character on the line
&
*
( = Jump to previous sentence
) = Jump to next sentence
=
-
[
]
{ = Navigate up a codeblock
} = Navigate down a codeblock
' = Go to bookmark saved earlier with m
"
;
:
<
>
,
.
/ search, type, press enter and press n/N to go to the next/previous result
?
Ctrl + Arrows = Change active split
Ctrl + A = increments ints
Ctrl + B = Split window below
Ctrl + C = Comment out line or selection
Ctrl + D = Delete current buffer
Ctrl + E = Next Buffer
Ctrl + F = Find file and open it quickly
Ctrl + G = Toggle Git
Ctrl + H = Navigate around splits to the left
Ctrl + I = Nothing
Ctrl + J = Navigate around splits to below
Ctrl + K = Navigate around splits to up
Ctrl + L = Navigate around splits to the right
Ctrl + M = Toggle invisible characters
Ctrl + N = Split window next
Ctrl + O = Open new Buffer
Ctrl + P = Toggle Numberline
Ctrl + Q = Quit
Ctrl + R = Redo your previous action
Ctrl + S = Save current buffer
Ctrl + T = Toggle directory tree
Ctrl + U = Open undo history
Ctrl + V = Visual Block Mode, Select a custom block of text to manipulate
Ctrl + W = Previous Buffer
Ctrl + X = Decrements ints
Ctrl + Y = Show Terminal
Ctrl + Z = Places the application in the background
Alt + Arrows = move line or selection
Alt + A = Nothing
Alt + B = Nothing
Alt + C = Toggle Invisible Characters
Alt + D = Nothing
Alt + E = Next Tab
Alt + F = Nothing
Alt + G = Nothing
Alt + H = Remove indent for line or selection
Alt + H = Nothing
Alt + I = Move Tab to the Right
Alt + J = Nothing
Alt + J = Move line or selection to the line below
Alt + K = Move line or selection to the line above
Alt + L = Add indent for line or selection
Alt + M = Nothing
Alt + N = Nothing
Alt + O = Open New Tab
Alt + P = Toggle Autopairs
Alt + Q = Nothing
Alt + R = Nothing
Alt + S = Nothing
Alt + T = Nothing
Alt + U = Move Tab to the Left
Alt + V = Nothing
Alt + W = Previous Tab
Alt + X = Nothing
Alt + Y = Nothing
Alt + Z = Nothing
Pacman Hooks for Updating Plugins
It is important that we update our plugins regularly, I will add more later WIP!
GDB
GDB is the GNU Debugger, It is extremely powerfull, I will add this one later WIP!
Valgrind
Valgrind is the best memory checker I have used, I will add this one later WIP!