⬅️ **[[$-Tools|Tools]]** *** # Vim > [!important] Standard-Editor unter [[$-Linux|Linux]] Command Line. ## Vim Basic Commands | Command | Description | | ---- | ---- | | **Basic Commands:** | | | h j k l | Curosor Navi | | ESC | Normalmodus | | q | Beenden | | x | Zeichen löschen **Entf** | | dd | Zeile löschen | | p | Diese Zeile unterhalb des Cursors wieder einfügen | | STRG + WW | wischen “Fensters” switchen | | S | Zeile löschen + Insert Mode am Anfang der Zeile | | tabnew | Tabs in VIM | | Tabnext | nächster Tab | | STRG + Z | auf Konsole | | fg ENTER | wieder zu Vim zurück von Konsole | | **VIM Modes:** | - Normal<br>-Insert<br>-Visual<br>-Command | | **Navigation:** | `hjkl wWbBeEggG 0` | | w | Anfang von Wort | | W | Anfang von WORT (einem durch Leerzeichen getrenntes Wort) “12,4123 asdas-dasdas,asd asdas” | | b / B | wie w / W nur umgekehrt | | e / E | Ende von wort / WORT | | gg / G | Dateianfang / Dateiende | | 0 | first Char in line | | $ | last Char in line | | ^ | first non-blank Char of line | | **Insert Mode:** | `iIsScCoO` | | i | Insert bei Cursor | | I | Insert am Anfang des Blocks (nicht unbedingt der Linie) | | s | löscht Char unter Cursor + Insert Mode | | S | löscht ganze Zeile + Insert Mode | | o | fügt eine neue Zeile drunter ein + Insert Mode | | O | fügt eine neue Zeile drüber ein + Insert Mode | | c | | | C | löscht ab Cursor bis EOL + Insert Mode | | **Suchen:** | | | / | Forward | | ? | Backward | | n / N | next / prev result | | :%s/pull/status | search and replaces "pull" with "status" | | **Copy / Paste:** | | | y | Yank -> kopiere in Buffer | | yw | Yank Word -> Wort von Cursor bis Ende des Wortes kopieren / in Buffer | | p / P | paste buffer after / before Cursor | | v | paste buffer after / before Cursor | | **Undo / Redo Stuff:** | | | u | undo | | STRG + R | Redo | | **Markieren:** | | | v --> y --> p | v (Visual Mode) --> y (Yank) --> p (paste) | | ggVG | gesamtes Dokument markieren | | V -> mark -> = | korrekt Einrücken / indent | ## Basic Config ```sh "## Syntax Highlighting an syntax on "## Zeilennummern an set number "## Suche Highlighten set hlsearch "## Color Scheme: set background=dark set t_Co=256 " enable 256 Color Mode "## :set paste --> damit 1:1 Inhalt gepastet wird "## an / aus --> im Insert-Mode :set pastetoggle=<f5> set mouse=v "Disable vim automatic visual mode on mouse select :set mouse-=a ``` ## Key Maps ```bash " KEY MAPS "let mapleader = "ctrl" "nmap ctrl + n :NERDTree<cr> nnoremap <C-e> :NERDTreeToggle<CR> :map <F2> :echo 'Current time is ' . strftime('%c')<CR> ``` ## Vim with Vundle Package manager - Insert the following in before the basic Vim settings from above. ```sh " vundle " git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim set nocompatible filetype off " needed for vim-gtk set encoding=utf-8 " Speed up start of vim after vim-gtk (Python 3.6 issue with YCM) " When vim -X helps, this is the same " https://stackoverflow.com/questions/14635295/vim-takes-a-very-long-time-to-start-up set clipboard=exclude:.* set rtp+=~/.vim/bundle/Vundle.vim call vundle#begin() Plugin 'VundleVim/Vundle.vim' " Add your plugins below this line Plugin 'preservim/nerdtree' Plugin 'scrooloose/syntastic' Plugin 'valloric/youcompleteme' Plugin 'vim-airline/vim-airline' " All of your Plugins must be added before the following line call vundle#end() filetype plugin indent on ``` ## Vim Config - fix issues ```sh " needed for vim-gtk set encoding=utf-8 " Speed up start of vim after vim-gtk (Python 3.6 issue with YCM) " When vim -X helps, this is the same " https://stackoverflow.com/questions/14635295/vim-takes-a-very-long-time-to-start-up set clipboard=exclude:.* ``` ## Pakete - verschiedene Vim Packete: [VIM Packages](http://askubuntu.com/questions/281886/what-is-the-difference-between-the-different-vim-packages-available-in-ubuntu) __Installation__ sudo apt-get install vim vim-nox vimhelp-de sudo apt-get install pandoc ## Vim Basic Concept - Filetype handling - `~/.vim/ftplugin/<filetype>.vim` - dort für den Filetype die Config hinterlegen - `set tabstop=2` - `set shiftwidth=2` ## Suchen in Dateien mit vimgrep * sucht in angebenen Verzeichnis nach Suchwort * .vimrc Command hinzufügen ``` command! -nargs=1 Ngrep vimgrep "<args>" ~/myfiles/1-notes/**/*.md nnoremap <leader>[ :Ngrep ``` * Verwendung: `:Ngrep <suchwort>` * Suchergebnisse - copen / cclose | Liste der Ergebnisse - cnext / cprevious | Springen zu ... * cnext + cprevious Shortcuts in .vimrc `no <C-n> :cnext <CR>` `no <C-p> :cprevious <CR>` ## Vim Customizing - Vim Ordner unter - `/usr/share/vim/vim74/` - `~/.vim/` - Folder `syntax` - Syntax Erkennung für verschiedene Sprachen - was unter `./vim/syntax` verändert wird, überschreibt die default Konfigs aus `/usr/share/vim/vim74/syntax` - Folder `plugins` ### Mappings - `no`= noremap - `ino` = inoremap - `vno` = vnoremap - `nmap, imap, vmap` = mapping in Normal, Insert und Visual Mode - Syntax = `<map> <key zum Auslösen> <Command das ausgeführt wird>` - ## Vim Settings Der Vim wird unter ` ~/.vimrc ` konfiguriert: Zeilennummern = set number Pathagon Plugin Mgr. = execute pathogen#infect() Notes Directory = :let g:notes_directories = [’~/Dokumente/ImportantFiles/Bibliothek_Notes’] Plugin Ordner = ~/.vim/bundle ### Vim in Cygwin Erstellen oder Kopieren von anderem Rechner von .vimrc & .vim/ in Cygwin-User-Ordner → alle Plugins usw. sind da ## Vim Plugins Link: http://vimawesome.com/ - Pathagon: Plugin-Mgr. - Installieren in `~/.vim/autoload/pathagon.vim` - NERDTree: Dateibrowser - Befehl: NERDTree - zw. Fenster switchen: *STRG + W* 2 Mal - vim-notes: **Notizen** - vim-outliner:_Notizen_, Markdown Lister von Vim Plugins: | Name | Link | Verwendung für? | aktiv? | | ------ | ------------------------------------------------- | --------------- | ------ | | Indent Guides | <http://vimawesome.com/plugin/indent-guides> | | | | VimOutliner | <https://github.com/vimoutliner/vimoutliner> | | | | Vim-Sensible | <https://github.com/tpope/vim-sensible> | | | | Vim-Pandoc | <https://github.com/vim-pandoc/vim-pandoc> | | | | Vim-Pandoc-Syntax | <https://github.com/vim-pandoc/vim-pandoc-syntax> | | | | Vim-Markdown | <https://github.com/plasticboy/vim-markdown> | | | | NERDTree | <http://vimawesome.com/plugin/the-nerd-tree> | | | | Vim-Notes | <http://vimawesome.com/plugin/notes-vim> | | | | YouCompleteMe | <http://vimawesome.com/plugin/youcompleteme> | | | | autoformat | <http://vimawesome.com/plugin/vim-autoformat> | | | | tabular | <http://vimawesome.com/plugin/vim-autoformat> | | | | vim-airline | <http://vimawesome.com/plugin/vim-airline-sad-beautiful-tragic> | | | | vim-colorschemes | <http://vimawesome.com/plugin/vim-colorschemes-sweeter-than-fiction> | | | V ### NERDTree - Dateibrowser - Befehl: NERDTree - zw. Fenster switchen: STRG + W 2 Mal ### NERDTreeTabs - ### Vim Notes Link: https://github.com/xolox/vim-notes - Headings: `# <text>` - Bold: `*<text>*` - Italic: `_<text>_` ### Notes Markdown PDF 1. Note 2. :NoteToMarkdown 3. Markdown 4. abspeichern 5. pandoc —latex-engine=pdflatex test.txt -o test.pdf 6. PDF ### Vim Outliner (nicht verwendet) ### YouCompleteMe (Linux Only) **<http://vimawesome.com/plugin/youcompleteme>** - Intelligente Code Autovervollständigung - Muss kompiliert werden -> daher nicht einfach kopierbar - Instant Vervollständigung und Vorschläge beim Tippen --> kein TAB oder so drücken Remember: YCM is a plugin with a compiled component. If you update YCM using Vundle and the ycm_support_libs library APIs have changed (happens rarely), YCM will notify you to recompile it. You should then rerun the install process. Install development tools and CMake: `sudo apt-get install build-essential cmake` Make sure you have Python headers installed: `sudo apt-get install python-dev.` Compiling YCM with semantic support for C-family languages: cd ~/.vim/bundle/YouCompleteMe ./install.sh --clang-completer Compiling YCM without semantic support for C-family languages: cd ~/.vim/bundle/YouCompleteMe ./install.sh - YCM: - 'sudo apt-get install build-essential cmake' - Python Headers: 'sudo apt-get install python-dev.' - git submodule update --init --recursive - ./install.sh ### Autoformat (Linux Only evtl.) - Autoformatierung von Code - Defaultformatter werden benötigt - im OS durch Paketmanager installiert - `sudo apt-get install python-autopep8` - durch vim-Pakete - vim-jsbeautify - in `.vimrc` Taste definieren --> **F3** - npm install -g js-beautify (js, json, html, css - pip install --upgrade autopep8 - sudo apt-get install tidy (für HTML, funktioniert aber nicht) ### tabular - schnelle Formatierung von z.B. Tabellen oder aufzählungen - Aufzählungen z.B. durch "=" oder "-" getrennt: `:tabularize /=` oder `:tabularize /-` - Tabellenspalten durch "|" getrennt: `:tabularize /|` ### tagbar (für Programmierung) - Übersicht zu Code (Klassen, Attribute usw.) - in `vimrc` Eintrag für Togglebutton festlegen --> **F4** ### vim-airline - Statuszeile für Vim - Customizable --> mal anschauen! ### vim-colorschemes - verschiedene Color Schemas - gute Schemas - inkpot ### vim-indent-guides - Veranschaulichung der Einrückungen im Text - z.B. wichtig in Python zur Übersicht - in `.vimrc` Breite, Farben usw. einstellen ### vim-markdown - Markdown in Vim darstellen # *** Related: - [[$-Note-Making|Note-Making]]