Linux vim editor command

1. Vim Commands¶

To run the ‘ctrl-]’ and ‘ctrl-T’ command, we need to create the tags first. In the below command, the ‘tags’ will be created for all the python files in the directory, which will be stored in a file ‘tags’,

(run the following command in shell) ctags -R *.py
Commands Descriptions
h left
j down
k up
l down
w forward to the beginning of next word
3w forward 3 words
W forward to the beginning of next word (only spaces are the end of word)
b backward to the beginning of next word
B backward to the beginning of next word (only spaces are the end of word)
e forward to end of next word
E forward to end of next word (only spaces are the end of the word)
gg go to first line of page
G go to end line of page
10G go to 10th line
10gg go to 10th line
0 go to first character of line
$ go to end character of line
^ go to first non-black character of line
M go to middle of the screen
fa go to next a in current line
Fa go to previous a in current line
ta go to end of next a in current line
Ta to to end of previous a in current line
ctrl-o go to previous location e.g. we went to line 10 from line 18, ctrl-o will go to line 18 again
ctrl-i or Tab go to next location i.e. go to line 10 again from line 18.
gd go to the local declaration of the word under cursor
gD go to the global declaration of the word under cursor
g* search for the word under the cursor
g# same as g* but in backward direction.
gf go to the filename under the cursor, use ctrl-o to go back
ctrl-] go to tag definition (a tag can be a function or variable name etc.); use ctrl-o to go back
ctrl-T go back to previous loation from where ctrl-] was exectued

1.12. Screen movements¶

Commands Descriptions
ctrl-d move half screen down
ctrl-f page down
ctrl-e move one line down
ctrl-u move half screen up
ctrl-b page up
ctrl-y move one line up
z

move current line to the top of screen (with cursor at the beginning)
zt move current line to the top with without changing the location of cursor
move current line to the center of screen (with cursor at the beginning)
zz move current line to the center of screen (without moving cursor)
z- move current line to the center of screen (with cursor at the beginning)
zb move current line to the center of screen (without moving cursor)

1.13. Unix Shell¶

1.14. Registers¶

Commands Descriptions
“ayy copy line in register ‘a’
“ap paste content of register ‘a’
Capital letters append the new value to previously stored values
“Ayy copy line and append to previous value in register “a” Then use “a to paste the value in register ‘a’
“=3*2p paste the result i.e. 6 at the current cursor location
:registers display the values in all the registers
:registers abc display the values of registers a, b and c

1.15. Multiple Files¶

Commands Descriptions
:arg grep -l ‘import’ *.py open all files in current folder which contains word ‘import’

1.16. Mark¶

Commands Descriptions
ma mark the line with name ‘a’ (use a-z or 0-9)
Next go to some other line and excute following command
d’a delete till line which is marked as ‘a’
:marks show the list of marks
‘a go to mark a

1.17. Sorting¶

Commands Descriptions
!10G (press enter) sort (press enter) it will sort first ten lines according to name
!G (press enter) sort (press enter) it will sort all the lines according to names
!!ls go to terminal, run ls command and print the output on the file (i.e. print list of file in current directory)
!!dates go to terminal, run date command and print the output on the file

1.18. Printing the code¶

Commands Descriptions
:hardcopy open the printing-instructions-window
:TOhtml and then save the file Save in html format, use :colorscheme default for white background

1.19. Mapping¶

  • Please read the comments in .vimrc file for more commands and details
  • comment/uncomment the command using double quote as per requirement.

1.19.1. Copy/paste from clip board¶

Use and then normal copy/paste command from clipboard.

Copy/paste to clip board
is remapped nnoremap “+
is remapped nnoremap “+]p (paste with indentation)
yiw or yy etc. copy the word or line etc. in clipboard
p paste the data from clipboard

1.19.2. Disable arraow keys¶

Below code can be used in .vimrc file

1.19.3. Code execution¶

“python commands
” Execute : F9 (Below code is used in .vimrc file)
:autocmd FileType python :nmap :! clear :! python %
“C/C++ commands
“Compile : F9 (Below code is used in .vimrc file)
:autocmd FileType c,cpp :nmap :! rm -r out :! clear :! g++ % -o out
“Run : Ctrl+F9 (Below code is used in .vimrc file)
:autocmd FileType c,cpp :nmap :! clear :! ./out

1.20. Buffer¶

Commands Descriptions
:bn go to next buffer i.e. file
:b go to buffer with
:bd close current file without exiting vim
:bd! close current file without exiting vim and ‘no modification’

1.21. Split windows¶

Commands Descriptions
:split split window in two part and display current file in both window
:split open in split window
:5 split open in new split window with width of 5 line
:new split window in two part with second window as blank
crtl-w j go to below split window
crtl-w k go to above split window
crtl-ww, crtl-w w go to next split window
crtl-w + increase the width of split window by one line
5 crtl-w — decrease the width of split window by 5 line
crtl-w = make all split window of equal size
crtl-w _ maximize the current split window

1.22. Auto completion¶

Commands Descriptions
ctrl-p,ctrl-n auto complete by looking previous/next words (use ctrl-p or ctrl-n to change the words from list)

1.23. Text files¶

Commands Descriptions
:set textwidth=50 change the line after 50 character
:1,5 center 50 textwidth = 50 and center the lines 1 to 5
:1,5 right 50 textwidth = 50 and right justify the text on lines 1 to 5
:1,5 left 4 left margin = 4 for lines 1 to 5
Use $ for end of the line as shown below,
:1,$ center 50 textwidth=50 and cneter all the line
or use % sign for the file (results is same as above,
:% center 50
:set wrap turn the wrap words on
:set nowrap turn off the wrap words

1.24. Macros¶

Commands Descriptions
qa start recording and store in reg ‘a’. Then perform certain operations. press ‘q’ again to stop recording.
@a execute macro
3@a repeat macro 3 times

1.25. More commands¶

Commands Descriptions
ctrl + g name of current file
ctrl + u move half screen up
ctrl + d move half screen down
J join line below with current line
3J join below two line with this line (not 3)
z= spell suggestion
~ change case of letter
:digraphs to see the list of symbols e.g. copyright etc.

1.26. Block Visual Mode¶

Add same items in the beginning/end/middle of all the lines

Commands Descriptions
crtl-v select the block with cursor movement
press I (insert before) or A (insert after) or c (replace) type the text -> press Esc -> block will be replaces by text

1.27. Zoom Screen¶

1.28. Save session¶

Commands Descriptions
:mksession name.vim save session
:mksession! name.vim override session
:source name.vim load session

1.29. Folding¶

Use space (remapped in .vimrc) at the line below the function definition for folding/unfolding the code.

1.30. Plugins¶

First install ‘vundle’ using following command. Use ‘git-shell’ to run this command in Windows.

  • git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
  • After that copy and paste the .vimrc file in the home directory (in Windows paste in the director C:/Users//)
  • Use double quote to comment/uncomment” the packages in .vimrc file e.g. ” Plugin ‘mattn/emmet-vim’ will not install the package “emmet-vim”. Or add some more packages in .vimrc file as required.
  • After selecting the packages, open vim and run the command -> :PluginInstall and it will install the all the plugins.
  • Use :help to see the list of operations.

1.30.1. NERDTree¶

Commands Descriptions
NERDTree turn on the directory structure
NERDTree! disable the directory structure
m then use various operations for delete, and create files.
e.g
m-a meher create a file with name meher
m-a meher/ create a folder with name meher

1.30.2. Surround¶

Commands Descriptions Results
ysiw” add “” to the word Meher -> “Meher”
ds” delete surround quotes “Meher” -> Meher
cs[( or cs]) change surround [] by () [2+3]/2 -> (2+3)/2
cst change

tag to

Meher Krishna

->

Meher Krishna

1.30.3. NerdCommenter¶

1.30.4. vim-table-mode¶

Follow the below steps to create the ‘rst-table’ in Vim,

  • Enable/Disable table mode using ‘:TableModeEnable/TableModeDisable’ or using ‘:TableModeToggle’,
  • Type column-names e.g. |Col1 | Col2| and press enter
  • Then press | twice to create the table. Do the same to add more lines in the table.
  • Also, go above the |Col1 | Col2| and press | twice (required for correct rst-table-format)

1.30.5. vim-extline¶

This is used to underline the text, which is required for making Headings in .rst document.

  • Type the symbols (in insert mode) e.g. = and then press ctrl-l ctrl-l to complete it.
  • Or press ctrl-l and then press the symbol,
  • Or press ctrl-l and then press a number e.g. 1, 2 etc. This is autocomplete the underline base on heading levels.
  • Some more commands are listed below,

1.30.6. ConqureShell¶

Use :ConqueTermSplit to start the terminal in the Vim.

1.30.7. Airline¶

Airline theme plugin for better view e.g. display name of file, line number, column number etc.

© Copyright 2017, Meher Krishna Patel. Revision 15854b56 .

Versions latest Downloads pdf htmlzip epub On Read the Docs Project Home Builds Free document hosting provided by Read the Docs.

Источник

Читайте также:  Intel gma hd linux driver
Оцените статью
Adblock
detector