Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to turn Vim 8.2 into Python IDE under Ubuntu

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

Editor to share with you how to build Vim 8.2 into Python IDE under Ubuntu, I believe most people do not know much about it, so share this article for your reference. I hope you will learn a lot after reading this article. Let's learn about it together.

1. Install Python

Install Python 3.9 under Ubuntu 20.04 LTS. Reference link: https://www.linuxmi.com/ubuntu-20-04-python-3-9.html

2. Install Vim

Ubuntu 20.04 LTS Desktop initial installation comes with vi, no vim needs to be installed, and has been skipped.

Ubuntu and its derivative version

Linuxmi@linuxmi:~/www.linuxmi.com$ sudo add-apt-repository ppa:jonathonf/vim linuxmi@linuxmi:~/www.linuxmi.com$ sudo apt-get update linuxmi@linuxmi:~/www.linuxmi.com$ sudo apt install vim

Arch Linux and its derivative version

Linuxmi@linuxmi:~/www.linuxmi.com$ sudo pacman-S vim linuxmi@linuxmi:~/www.linuxmi.com$ flatpak install flathub org.vim.Vim

3. Plug-in installation

Tag navigation (tagbar and ctags), syntax detection (syntastic), file search (ctrlp), directory tree navigation (nerdtree), status bar beautification (vim-powerline), topic style (solarized), python related (jedi-vim and python-mode), parenthesis matching highlighting (rainbow_parentheses), visual indentation (vim-indent-guides). It's got everything.

One of the most important is the plug-in management tool vundle.

Install vundle

Git clone https://github.com/gmarik/vundle.git ~ / .vim/bundle/vundle

Once vundle is installed, you need to add vundle support to the ~ / .vimrc configuration file. Configure vim

The configuration of vim is done in the ~ /. Vimrc file in the user's home directory. If not, you need to create it yourself.

Edit the ~ / .vimrc file and write the following:

Filetype off set rtp+=~/.vim/bundle/vundle/ call vundle#rc () if filereadable (expand ("~ / .vimrc.bundles") source ~ / .vimrc.bundles endif

To prevent the configuration file from being too cluttered, we can manage our installed plug-ins through ~ / .vimrc.bundles.

.vimrc.bundles configuration file

First create the file ~ / .vimrc.bundles, and then add the following code:

If & compatible set nocompatible end filetype off set rtp+=~/.vim/bundle/vundle/ call vundle#rc () "Let Vundle manage Vundle Bundle 'gmarik/vundle'" Define bundles via Github repos "tag navigation Bundle' majutsushi/tagbar' Bundle 'vim-scripts/ctags.vim'" static code analysis Bundle' scrooloose/syntastic' "file search Bundle 'kien/ctrlp.vim'" directory tree navigation Bundle "scrooloose/nerdtree" Beautify the status bar Bundle "Lokaltog/vim-powerline", theme style Bundle "altercation/vim-colors-solarized", python automatic completion Bundle 'davidhalter/jedi-vim' Bundle "klen/python-mode", parenthesis matching highlight Bundle' kien/rainbow_parentheses.vim' "visual indentation Bundle 'nathanaelkane/vim-indent-guides' if filereadable (expand (" ~ / .vimrc.bundles.local ") source ~ / .local)

As shown in the above code, we specify the address of each plug-in in Github through Bundle, and the filling rule is "user name / warehouse name". There are three kinds of writing rules, the most common one is used here, and the other writing methods will not be mentioned here.

Install the plug-in

We have specified the path of each plug-in, and the next step is to install each plug-in. Enter vim in shell and enter BundleInstall in command line mode.

Run this command and start installing the plug-ins we specified earlier. This process requires networking. After downloading and installing each plug-in, you will be prompted to Done!

Note: since tagbar depends on ctags, we also need to install ctags with instructions:

Sudo apt-get install ctags

Plug-in configuration

1. Basic configuration

Each plug-in has been installed, can you use it directly next? The answer is no, and we need to continue to configure our own installed plug-ins. The configuration is also very simple here. Write the ~ / .vimrc configuration below:

Filetype off set rtp+=~/.vim/bundle/vundle/ call vundle#rc () if filereadable (expand ("~ / .vimrc.bundles") source ~ / .vimrc.bundles endif "tagbar tag navigation nmap tb: TagbarToggle let GGRO tagbartagstagsbindings binding let g:tagbar_width=30 autocmd BufReadPost *. Cpp,*.c,*.h,*.hpp,*.cc * .cxx call tagbar#autoopen () let g:jedi#auto_initialization = 1 "theme solarized let g:solarized_termtrans=1 let glug solarizedvisibility=" normal "" color scheme set background=dark set t_Co=256 colorscheme solarized "directory file navigation NERD-Tree"\ nt opens the nerdree window. In the left column, display nmap nt: NERDTree let NERDTreeHighlightCursorline=1 let NERDTreeIgnore= ['\ .pyc $','\ .pyo $','\ .obj $','\ .o $','\ .so $','\ .egg $','^\ .git $','^\ .SVN $' '^\ .hg $'] let GRV netrwned homeowners started searching for ctrlp'"close vim if the only window left open is a NERDTree autocmd bufenter * if (winnr (" $") = = 1 & & exists (" b:NERDTreeType ") & & b:NERDTreeType = =" primary ") | Q | end" ctrlp file search "Open ctrlp search let g:ctrlp_map = 'ff' let g:ctrlp_cmd =' CtrlP'" is equivalent to mru function Show recently opened files map fp: CtrlPMRU "set wildignore+=*/tmp/*,*.so,*.swp,*.zip" MacOSX/Linux "let g:ctrlp_custom_ignore = {\ 'dir':'\ v [\ /]\. (git | hg | svn | rvm) $',\ 'file':'\ v\. (exe | so | dll | zip | tar.gz) $',\}"\ 'link':' SOME_BAD_SYMBOLIC_LINKS' Let g:ctrlp_working_path_mode=0 let g:ctrlp_match_window_bottom=1 let g:ctrlp_max_height=15 let g:ctrlp_match_window_reversed=0 let g:ctrlp_mruf_max=500 let g:ctrlp_follow_symlinks=1 "vim-powerline beautification status" let g:Powerline_symbols = 'fancy' let g:Powerline_symbols =' unicode' 'parentheses match highlight let g:rbpt_colorpairs = [\ [' brown', 'RoyalBlue3'] \ ['Darkblue',' SeaGreen3'],\ ['darkgray',' DarkOrchid3'],\ ['darkgreen',' firebrick3'],\ ['darkcyan',' RoyalBlue3'],\ ['darkred',' SeaGreen3'],\ ['darkmagenta',' DarkOrchid3'],\ ['brown',' firebrick3'],\ ['gray'] 'RoyalBlue3'],\ [' black', 'SeaGreen3'],\ [' darkmagenta', 'DarkOrchid3'],\ [' Darkblue', 'firebrick3'],\ [' darkgreen', 'RoyalBlue3'],\ [' darkcyan', 'SeaGreen3'],\ [' darkred', 'DarkOrchid3'],\ [' red'' 'firebrick3'],\] let g:rbpt_max = 40 let g:rbpt_loadcmd_toggle = 0 "Visual indent let g:indent_guides_enable_on_vim_startup = 0" default off let g:indent_guides_guide_size = 1 "specify alignment line size let g:indent_guides_start_level = 2" Visual indent from the second layer

You can set the shortcut key according to your preference, press the key\, according to my configuration. In the normal mode of Vim:

Press the key\ tb in turn, and the label navigation will be called up.

Press the key\ ff in turn, and the file search will be called up.

Press the key\ nt in turn, and the directory navigation will be called up.

2. Running configuration

These basic configurations have been completed, but I want to press a key to run the currently edited Python file and view the results in Vim as in IDE. Can this be done?

If the vim plug-in reports an error Error detected while processing / root/.vim/bundle/python-mode/autoload/pymode/lint.vim

That's because the pylama module is missing, so you can install it as shown below.

No problem!

The pursuit code on the last line of ~ / .vimrc is as follows:

"run the file map: WRV rpm python 3%

The above code means that in the normal mode of Vim, pressing F5 will save the file and run the current file using Python3, and output the results to the current interface.

Note that:! python3 means to run the system command Python3, if you do not install the coexistence of Python2 and Python3, just write python here.

In this way, we can view the running results while editing, as shown in the screenshot at the top of this article.

After running, you can still press u in the normal mode of Vim to withdraw the output operation, so that the output is withdrawn, and we can continue to write our own code.

These are all the contents of the article "how to make Vim 8.2 into Python IDE under Ubuntu". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report