Personal blog written from scratch using Node.js, Bootstrap, and MySQL. https://jrtechs.net
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

177 lines
5.6 KiB

  1. # Vim Configuration
  2. Stock Vim is pretty boring. The good news is that Vim has a very
  3. comprehensive configuration file which allows you to tweak it to your
  4. heart's content. To make changes to Vim you simply modify the ~/.vimrc
  5. file in your home directory. By adding simple commands this file you
  6. can easily change the way your text editor looks. Neat.
  7. I attempted to create the smallest Vim configuration file which makes
  8. Vim usable enough for me to use as my daily text editor. I believe
  9. that it is important for everyone to know what their Vim configuration
  10. does. This knowledge will help ensure that you are only adding the
  11. things you want and that you can later customize it for your workflow.
  12. Although it may be tempting to download somebody else's massive Vim
  13. configuration, I argue that this can lead to problems down the road.
  14. I want to mention that I don't use Vim as my primary IDE; I only use
  15. Vim as a text editor. I tend to use JetBrains tools on larger projects
  16. since they have amazing auto complete functionality, build tools, and
  17. comprehensive error detection. There are great Vim configurations out
  18. there on the internet; however, most tend to be a bit overkill for
  19. what most people want to do.
  20. Alright, lets dive into my vim configuration!
  21. # Spell Check
  22. ```vim
  23. autocmd BufRead,BufNewFile *.md setlocal spell spelllang=en_us
  24. autocmd BufRead,BufNewFile *.txt setlocal spell spelllang=en_us
  25. ```
  26. Since I am often an atrocious speller, having basic spell check
  27. abilities in Vim is a lifesaver. It does not make sense to have spell
  28. check enabled for most files since it would light up most programming
  29. files like a Christmas tree. I have my Vim configuration set to
  30. automatically enable spell check for markdown files and basic text
  31. files. If you need spell check in other files, you can enter the
  32. command ":set spell" to enable spell check for that file. To see the
  33. spelling recommendations, type "z=" when you are over a highlighted
  34. word.
  35. # Appearance
  36. Adding colors to Vim is fun. The "syntax enable" command tells vim to
  37. highlight keywords in programming files and other structured files.
  38. ```vim
  39. syntax enable
  40. ```
  41. I would encourage everyone to look at the different color schemes
  42. available for Vim. I threw the color scheme command in a try-catch
  43. block to ensure that it does not crash Vim if you don't have the color
  44. scheme installed. By default the desert color scheme is installed;
  45. however, that is not always the case for [community
  46. created](http://vimcolors.com/) Vim color schemes.
  47. ```vim
  48. try
  49. colorscheme desert
  50. catch
  51. endtry
  52. set background=dark ```
  53. # Indentation and Tabs
  54. Having your indentation settings squared away will save you a ton of
  55. time if you are doing any programming in Vim.
  56. ```vim
  57. "copy indentation from current line when making a new line
  58. set autoindent
  59. " Smart indentation when programming: indent after {
  60. set smartindent
  61. set tabstop=4 " number of spaces per tab set expandtab "
  62. convert tabs to spaces set shiftwidth=4 " set a tab press equal to 4
  63. spaces ```
  64. # Useful UI Tweaks
  65. These are three UI tweaks that I find really useful to have, some
  66. people may have different opinions on these. Seeing line numbers is
  67. useful since programming errors typically just tells you what line
  68. your program went up in flames. The cursor line is useful since it
  69. allows you to easily to find your place in the file -- this may be a
  70. bit too much for some people.
  71. I like to keep every line under 80 characters long for technical
  72. files, having a visual queue for this is helpful. Some people prefer
  73. to just use the auto word wrap and keep their lines as long as they
  74. like. I like to keep to the 80 character limit and explicitly choose
  75. where I cut each line. Some of my university classes mandate the 80
  76. character limit and take points off if you don't follow it.
  77. ```vim
  78. " Set Line Numbers to show "
  79. set number
  80. " Highlights the entire current line with a underscor "
  81. set cursorline
  82. " Displays a red bar at 80 characters "
  83. set colorcolumn=80
  84. ```
  85. # Searching and Auto Complete
  86. This these configurations make searching in Vim less painful.
  87. ```vim
  88. " search as characters are entered "
  89. set incsearch
  90. " highlight matched characters "
  91. set hlsearch
  92. " Ignore case when searching "
  93. set ignorecase
  94. ```
  95. These configurations will make command completion easier by showing
  96. an auto-complete menu when you press tab.
  97. ```vim
  98. " Shows a auto complete menu when you are typing a command "
  99. set wildmenu
  100. set wildignorecase " ignore case for auto complete
  101. ```
  102. ![Vim auto complete](media/vim/commandCompletion.png)
  103. # Useful Things to Have
  104. There is nothing too earth shattering in this section, just things
  105. that might save you some time. Enabling mouse support is a really
  106. interesting configuration. When enabled, this allows you to select
  107. text and jump between different locations with your mouse.
  108. ```vim
  109. " Enables mouse support "
  110. set mouse=a
  111. "Disable ding sound on error, flashes cursor instead "
  112. set visualbell
  113. " Display ruler on bottom right -- should be there by default "
  114. set ruler
  115. " Auto updates file if an external source edits the file "
  116. set autoread
  117. " Improves performance by only redrawing screen when needed "
  118. set lazyredraw
  119. ```
  120. Setting your file format is always a good idea for compatibility.
  121. ```vim
  122. " Set utf8 as standard encoding and en_US as the standard language "
  123. set encoding=utf8
  124. " Use Unix as the standard file type "
  125. set ffs=unix,dos,mac
  126. ```
  127. # Wrapping it up
  128. I hope that this quick blog post inspired you to maintain your own Vim
  129. configuration file. You can find my current configuration files in my
  130. [random scripts
  131. repository](https://github.com/jrtechs/RandomScripts/tree/master/config).