Skip to content

Commit 36599b1

Browse files
authored
Misc vim section fixes
1 parent 105ee3c commit 36599b1

File tree

1 file changed

+31
-12
lines changed

1 file changed

+31
-12
lines changed

linux-1/vim.md

+31-12
Original file line numberDiff line numberDiff line change
@@ -53,24 +53,26 @@ All commands must be run from Command Mode (unless otherwise specified).
5353
| `Ctrl + v` | Enter visual block mode for selecting columns of text. |
5454
| `:s/old/new/g` | Replace "old" text with "new" in the current line. |
5555
| `:%s/old/new/g` | Replace "old" text with "new" in the entire file. |
56-
| `gg` | Move cursor to the beginning of the file. |
57-
| `G` | Move cursor to the end of the file. |
58-
| `Ctrl + d` | Scroll down half a screen. |
59-
| `Ctrl + u` | Scroll up half a screen. |
56+
6057

6158
#### **Navigation & Cursor Movement**
59+
6260
| Command | Description |
6361
| ------- | ------------------------------------------------------------------ |
62+
| `gg` | Move cursor to the beginning of the file. |
63+
| `G` | Move cursor to the end of the file. |
6464
| `w` | Move cursor forward to the next word. |
6565
| `b` | Move cursor backward to the previous word. |
6666
| `e` | Move cursor to the end of the current word. |
6767
| `{` | Move cursor to the beginning of the previous paragraph. |
6868
| `}` | Move cursor to the beginning of the next paragraph. |
69-
| `Ctrl + o` | Jump to the previous cursor position. |
70-
| `Ctrl + i` | Jump to the next cursor position. |
7169
| `H` | Move cursor to the top of the screen. |
7270
| `M` | Move cursor to the middle of the screen. |
7371
| `L` | Move cursor to the bottom of the screen. |
72+
| `Ctrl + o` | Jump to the previous cursor position. |
73+
| `Ctrl + i` | Jump to the next cursor position. |
74+
| `Ctrl + d` | Scroll down half a screen. |
75+
| `Ctrl + u` | Scroll up half a screen. |
7476

7577
#### **Editing & Manipulating Text**
7678

@@ -110,8 +112,8 @@ All commands must be run from Command Mode (unless otherwise specified).
110112
| ------- | ----------------------------------------------- |
111113
| `:r filename` | Insert the contents of "filename" into the current buffer. |
112114
| `:w filename` | Save the current buffer to "filename". |
113-
| `"*y` | Yank (copy) text to the system clipboard. |
114-
| `"*p` | Paste text from the system clipboard. |
115+
| `"*y` | Yank (copy) text to the system clipboard (some versions of vim do not support this). |
116+
| `"*p` | Paste text from the system clipboard (some versions of vim do not support this). |
115117

116118
## The .vimrc file
117119

@@ -131,6 +133,7 @@ Here are some common `.vimrc` customizations to enhance your Vim experience:
131133
### **Basic Settings**
132134

133135
```vim
136+
set mouse+=a " turn on mouse in all modes
134137
set number " Show line numbers
135138
set relativenumber " Show relative line numbers
136139
set cursorline " Highlight the current line
@@ -140,12 +143,19 @@ set expandtab " Convert tabs to spaces
140143
set autoindent " Maintain indentation level
141144
set nowrap " Prevent line wrapping
142145
```
146+
147+
- **Mouse Usage**: `set mouse+=a` turns mouse usage on in all vim modes (normal, visual, insert, and command-line). This allows you to use the mouse for various actions like selecting text, resizing windows, and scrolling.
143148
- **Line Numbers:** `set number` displays absolute line numbers, while `set relativenumber` makes navigation easier by showing relative numbers.
144149
- **Cursor Highlighting:** `set cursorline` makes it easy to see where your cursor is.
145150
- **Indentation Control:** `tabstop`, `shiftwidth`, and `expandtab` ensure consistent spacing and indentation.
146151
- **Autoindent:** Helps maintain indentation consistency when writing code.
147152
- **Text Wrapping:** `set nowrap` prevents long lines from wrapping, keeping code readable.
148153

154+
155+
{% hint style="info" %}
156+
**Copy-Paste Issues**: Enabling mouse support might interfere with terminal copy-paste shortcuts. Use Shift or Ctrl keys as modifiers if needed (usually hold shift along with normal selection, then copy)
157+
{% endhint %}
158+
149159
### **Search & Navigation**
150160

151161
```vim
@@ -154,6 +164,7 @@ set smartcase " Override ignorecase if uppercase is used
154164
set incsearch " Highlight matches as you type
155165
set hlsearch " Highlight all search matches
156166
```
167+
157168
- **Case Handling:** `ignorecase` makes searches case-insensitive, while `smartcase` ensures uppercase queries remain case-sensitive.
158169
- **Incremental Search:** `incsearch` highlights matches as you type, providing instant feedback.
159170
- **Highlighting Matches:** `hlsearch` ensures all found results are highlighted for better visibility.
@@ -167,6 +178,7 @@ nnoremap <leader>x :x<CR> " Save and exit with <leader>x
167178
nnoremap <leader>n :bnext<CR> " Move to next buffer
168179
nnoremap <leader>p :bprevious<CR> " Move to previous buffer
169180
```
181+
170182
- **Leader Key Shortcuts:** These mappings allow quick execution of common tasks using a single key combination.
171183
- `<leader>w` saves the file.
172184
- `<leader>q` quits Vim.
@@ -178,23 +190,29 @@ nnoremap <leader>p :bprevious<CR> " Move to previous buffer
178190
In Vim, the **leader key** is a customizable key that serves as a prefix for user-defined shortcuts, making commands faster and more intuitive. By default, the leader key is set to `\` (backslash), but it can be changed to another key, such as the **comma** or **space**, to improve usability.
179191

180192
### **Why Use the Leader Key?**
193+
181194
- **Simplifies Commands:** Instead of typing long Vim commands, you can assign shortcuts to them.
182195
- **Improves Speed:** Reduces keystrokes for common actions.
183196
- **Personalized Workflow:** Tailor Vim to your habits and needs.
184197

185198
### **Setting a Custom Leader Key**
199+
186200
You can redefine the leader key in your `.vimrc` file:
201+
187202
```vim
188203
let mapleader="," " Set leader key to comma
189204
```
190205

191206
### **Using the Leader Key**
207+
192208
Once defined, the leader key can be used to create custom shortcuts:
209+
193210
```vim
194211
nnoremap <leader>w :w<CR> " Save file with ,w
195212
nnoremap <leader>q :q<CR> " Quit Vim with ,q
196213
nnoremap <leader>x :x<CR> " Save and exit with ,x
197214
```
215+
198216
This means pressing **`,` followed by `w`** will save the file instead of typing `:w<CR>` manually.
199217

200218
### **Plugins**
@@ -231,7 +249,7 @@ curl -fLo ~/.vim/autoload/plug.vim --create-dirs \
231249

232250
#### **Adding Plugins**
233251

234-
Edit your `.vimrc` file:
252+
Edit your `.vimrc` file to add the following lines:
235253

236254
```vim
237255
call plug#begin('~/.vim/plugged')
@@ -248,7 +266,7 @@ call plug#end()
248266
- **Vim-Surround:** Allows easy manipulation of surrounding characters.
249267
- **FZF:** Adds powerful fuzzy search capabilities.
250268

251-
Then, install plugins with:
269+
Then, install plugins in Vim with:
252270

253271
```vim
254272
:PlugInstall
@@ -269,7 +287,7 @@ Vim 8 introduced **native package management**:
269287
```sh
270288
git clone https://github.com/preservim/nerdtree ~/.vim/pack/plugins/start/nerdtree
271289
```
272-
3. Restart Vim—plugin loads automatically.
290+
3. Restart Vim; plugins load automatically.
273291

274292
Using a plugin manager is **easier** and **more scalable**, but native management works well for minimal setups.
275293

@@ -279,7 +297,8 @@ Using a plugin manager is **easier** and **more scalable**, but native managemen
279297
set laststatus=2
280298
set statusline=%f\ %y\ %m\ %r\ %=Line:%l/%L\ Col:%c
281299
```
282-
- **Status Line Customization:** Displays the file name, type, modification status, and cursor position efficiently.
300+
301+
- **Status Line Customization:** Displays the file name, type, modification status, and cursor position.
283302

284303
These configurations optimize Vim for usability, efficiency, and a better coding experience.
285304

0 commit comments

Comments
 (0)