vimrc - RicoJia/notes GitHub Wiki

  • source it: :so % #so means source, % means this file

    • or reload it by opening and reopening the file
  • help usr_05.txt #useful user manual for vimrc

  • settings

  • clipboard: if

    • set clipboard = unmmaped
    • If this doesn't work for u, download vim-gtk and vim-gnome
  • non-compatible: not the original vi settings

  • file type:

    • :filetype plugin indent on    #turn on file type detector, plugin (go detector, etc. )
      :filetype detect  #set to python
      set filetype?
  • syntax highlighting

    • leader key
        https://medium.com/usevim/vim-101-what-is-the-leader-key-f2f5c1fa610f
      
  • I/O

    • set VAR? to get the status of the variable.

Rationale

  • set ruler = :set ruler , this is called a setting

    • On and off:
      • :set SETTING
      • :set noSETTING
      • :set SETTING! THis is to toggle a setting
    • values
      • help SETTING: See choices of a setting:
      • set SETTING&: to set the default values
    • :set SETTING? to check the settings
      • :set will only display settings with non-default vals
      • :h option-list will display the options
  • color scheme

    • placed at ~/.vim/colors
  • mapping

     Enter: <CR>, <Enter>, <Return>
     Escape: <BS>
     <Up>, <Down>, <Left>, <Right>
     <Insert>, <Del>, 
     <Home> <End>
     <PageUp> <PageDown>
     <Tab>
     <Bar>	'|'
     <C-X>	
    
     - You can put in common patterns into vimrc as well!
     - ```let mapleader=","```
     - ```:map``` :see mappings
    
  • replacing

    • Once you replace a file with something new, You might not be able to see the change

      • :e is how you reload it.
      • mkvimrc allows you to overwrite .vimrc with the current settings.
    • key syntaxes whitespace, even if you just do , it still counts!!

    • Additional

      • Modeline: You may want a specific type of file to have specific settings. So at the top/end of the file, do /* vim: set ts=8 sw=4 tw=0 noet : */, notice that spacing and colons are important here.

Syntax (refer to this when necessary)

Basics

  • \$ means the last line, \. means the current line in : commands

mappings

  • nmap :NERDTreeToggle: so you can run C-f directly on vim.
  • <C-S-v> and <C-v> are really the same.
  • let is used to set variables
    • let VAR='<Enter>'
    • let VAR='<c-t>' #this is for mapping certain keys
  • means backslash
  • :verbose nmap ... this helps debug keybindings!!
  • determine the default position of cursor, from the end of line nnoremap <Leader>r :%s///g<Left><Left><Left>
  • map <S-k> <Nop> you can disable a mapping like this.
  • xnoremap j mode() ==# "v"? "c```jk" : "kj" //remappiong j in different modes.
    1. xmap is for visual mode only, vmap is for visual and select
    2. If you want to create something specifically for visual line mode, do this:
      xnoremap <expr> j  mode() ==# "v" ? "gj" : "j" 
    3. <expr> is to invoke a vim function. see help mode() for all modes

Functions

  • call a function on an event

    • autocmd QuitPre * exec 'FloatermKill!
      • exec means to call the plugin command
      • QuitPre is quite useful
    • autocmd QuitPre * call VIM_COMMAND
  • | is command separator

  • References

  • copy word under cursor to command:

     :vs <C-R><C-W><CR>
    

Low Level Details

  • CTRL - generates keycode of char - 64 (All ASCII)
    • So CTRL-I = TAB
    • < has ASCII code 60, so CTRL-< is impossible
  • is for <, > is fine

Plugins

  1. Vundle & vim-plug

     get vundle: plugin manager. Get that!  
    vim plugin: curl -fLo ~/.vim/autoload/plug.vim --create-dirs   https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
    • Use vim-plug:
      - add plug line, 
      - restart vim
      - PlugInstall
      - Remove the pluglin
      - restart vim
      - PlugClean
      - PlugUpdate    #update all plugins
      
    • vim has default .vimrc, even if it's deleted
  2. ag:

  3. File Explorers (generate a new buffer for u)

    • netrw
      • Stores in buffer as a hidden buffer file
      •   	:e .  #to see all files 
          d DIR_NAME  # make a new direcotry
    • I use nerdtree + ctrlp
      • ctrl+p is to search for a file, if there are so many of them.
      • ctrl+t is to open file in ctrl + p
    • nerdtree - Great references - repo - Nerd Tree List - - is enter nerd tree - I've set up auto start - m is to show list. You can create, delete files easily - I've remapped F2 as the quick way of opening/hiding nerd tree - I is to see the hidden directories - q is to close the nerd tree window - File Nav - o is to open and close - x is to close the current node. - Within a directory - P is root (current cwd, the top one in orange) - p is the the parent directory - K is to jump to the top of the current list - J is the last node - U, u is to move tree root up a dir. - C is to select the current dir
      - t is to open a file in new tab - R is to refresh. - F toggle whether files are used. (you need to hit F again to re-enable it) - Help - :help NERDTree-TOPIC - ? opens the key binding menu
      • if nerd tree says "1 file cannot be loaded", it's probably file permissions.
  4. Code Snippets

    • Fzf uses ultisnippets, really handy. You type the name of the snippets, in Fzf, then hit tab. Note, space not allowed.
    • UltiSnippets is the engine, vim-snippets provides all the rules. If you want to customize, go to ~/.vim/plugged/vim-snippets/UltiSnips to change
    • add another filetype to UltiSnips:
      1. set filetype? to see filetype in vim. If there's nothing, au BufRead,BufNewFile *.launch set filetype=xml
  5. ctags

    • install like here vim - follow this link
    • usage: generate a tags file in the root, ctags -R .
  • fzf
    • exclude searches that contains a word: !word
    • exlude searches that start with a word !^word
    • :History is to see most recent files.
  • coc
    • python: CocInstall coc-python coc-pyright coc-json
         pip3 install -U jedi-language-server
         sudo apt install python3-venv
      
    • cocconfig: add: "python.setInterpreter": "/usr/bin/python3", "python.linting.enabled": true
    • Basic operations:
      • gd for defintion, ctrl-o
⚠️ **GitHub.com Fallback** ⚠️